Add SliverGrid.list convenience constructor#173925
Add SliverGrid.list convenience constructor#173925auto-submit[bot] merged 13 commits intoflutter:masterfrom
Conversation
Add SliverGrid.list constructor that accepts List<Widget> children for cleaner API when working with predefined widget lists. Fixes: flutter#173018
Add test coverage for SliverGrid.list including basic functionality and empty children edge case.
There was a problem hiding this comment.
Code Review
This pull request introduces a SliverGrid.list convenience constructor, which simplifies creating a SliverGrid from a list of widgets. The implementation is clean and follows existing patterns in the framework. The accompanying tests cover the basic functionality and edge cases well.
My main feedback is to enhance the documentation for the new constructor to fully align with the Flutter Style Guide by adding a code example and documenting all parameters. This will improve its usability for other developers.
|
FYI @loic-sharma since you opened the issue asking for this (#173018). |
loic-sharma
left a comment
There was a problem hiding this comment.
This looks good to me - thanks for the wonderful contribution!
Thank you! Excited to keep contributing 🙌 |
| /// | ||
| /// |
There was a problem hiding this comment.
Are these two newlines intentional?
There was a problem hiding this comment.
Thanks, that was unintentional. I’ve fixed it 👍
|
@ahmeddhus Looks like there are some formatting issues, can you run |
Fixed 👍🏾 |
victorsanni
left a comment
There was a problem hiding this comment.
LGTM. Thanks for the PR
|
autosubmit label was removed for flutter/flutter/173925, because - The status or check suite Google testing has failed. Please fix the issues identified (or deflake) before re-applying this label. |
This PR adds a new `SliverGrid.list` convenience constructor that accepts a `List<Widget> children` parameter, providing a cleaner API compared to manually creating `SliverChildListDelegate`. ## What was added The constructor uses `SliverChildListDelegate` internally and follows the same pattern as existing convenience constructors like `SliverGrid.count` and `SliverGrid.extent`. This addresses the use case where developers want to create sliver grids with predefined widget lists without the verbosity of manually constructing the delegate. ## Before/After comparison **Before:** ```dart SliverGrid( gridDelegate: gridDelegate, delegate: SliverChildListDelegate([widget1, widget2, widget3]), ) ``` **After:** ```dart SliverGrid.list( gridDelegate: gridDelegate, children: [widget1, widget2, widget3], ) ``` ## Implementation details - Added `SliverGrid.list` constructor in `packages/flutter/lib/src/widgets/sliver.dart` - Constructor accepts `List<Widget> children` and all necessary delegate configuration parameters - Uses `SliverChildListDelegate` internally for consistent behavior - Added comprehensive test coverage in `packages/flutter/test/widgets/slivers_test.dart` ## Issue addressed Fixes: flutter#173018 ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing. --------- Co-authored-by: Loïc Sharma <737941+loic-sharma@users.noreply.github.com>
This PR adds a new `SliverGrid.list` convenience constructor that accepts a `List<Widget> children` parameter, providing a cleaner API compared to manually creating `SliverChildListDelegate`. ## What was added The constructor uses `SliverChildListDelegate` internally and follows the same pattern as existing convenience constructors like `SliverGrid.count` and `SliverGrid.extent`. This addresses the use case where developers want to create sliver grids with predefined widget lists without the verbosity of manually constructing the delegate. ## Before/After comparison **Before:** ```dart SliverGrid( gridDelegate: gridDelegate, delegate: SliverChildListDelegate([widget1, widget2, widget3]), ) ``` **After:** ```dart SliverGrid.list( gridDelegate: gridDelegate, children: [widget1, widget2, widget3], ) ``` ## Implementation details - Added `SliverGrid.list` constructor in `packages/flutter/lib/src/widgets/sliver.dart` - Constructor accepts `List<Widget> children` and all necessary delegate configuration parameters - Uses `SliverChildListDelegate` internally for consistent behavior - Added comprehensive test coverage in `packages/flutter/test/widgets/slivers_test.dart` ## Issue addressed Fixes: flutter#173018 ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing. --------- Co-authored-by: Loïc Sharma <737941+loic-sharma@users.noreply.github.com>
This PR adds a new `SliverGrid.list` convenience constructor that accepts a `List<Widget> children` parameter, providing a cleaner API compared to manually creating `SliverChildListDelegate`. ## What was added The constructor uses `SliverChildListDelegate` internally and follows the same pattern as existing convenience constructors like `SliverGrid.count` and `SliverGrid.extent`. This addresses the use case where developers want to create sliver grids with predefined widget lists without the verbosity of manually constructing the delegate. ## Before/After comparison **Before:** ```dart SliverGrid( gridDelegate: gridDelegate, delegate: SliverChildListDelegate([widget1, widget2, widget3]), ) ``` **After:** ```dart SliverGrid.list( gridDelegate: gridDelegate, children: [widget1, widget2, widget3], ) ``` ## Implementation details - Added `SliverGrid.list` constructor in `packages/flutter/lib/src/widgets/sliver.dart` - Constructor accepts `List<Widget> children` and all necessary delegate configuration parameters - Uses `SliverChildListDelegate` internally for consistent behavior - Added comprehensive test coverage in `packages/flutter/test/widgets/slivers_test.dart` ## Issue addressed Fixes: flutter#173018 ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing. --------- Co-authored-by: Loïc Sharma <737941+loic-sharma@users.noreply.github.com>
This PR adds a new `SliverGrid.list` convenience constructor that accepts a `List<Widget> children` parameter, providing a cleaner API compared to manually creating `SliverChildListDelegate`. ## What was added The constructor uses `SliverChildListDelegate` internally and follows the same pattern as existing convenience constructors like `SliverGrid.count` and `SliverGrid.extent`. This addresses the use case where developers want to create sliver grids with predefined widget lists without the verbosity of manually constructing the delegate. ## Before/After comparison **Before:** ```dart SliverGrid( gridDelegate: gridDelegate, delegate: SliverChildListDelegate([widget1, widget2, widget3]), ) ``` **After:** ```dart SliverGrid.list( gridDelegate: gridDelegate, children: [widget1, widget2, widget3], ) ``` ## Implementation details - Added `SliverGrid.list` constructor in `packages/flutter/lib/src/widgets/sliver.dart` - Constructor accepts `List<Widget> children` and all necessary delegate configuration parameters - Uses `SliverChildListDelegate` internally for consistent behavior - Added comprehensive test coverage in `packages/flutter/test/widgets/slivers_test.dart` ## Issue addressed Fixes: flutter#173018 ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing. --------- Co-authored-by: Loïc Sharma <737941+loic-sharma@users.noreply.github.com>
This PR adds a new
SliverGrid.listconvenience constructor that accepts aList<Widget> childrenparameter, providing a cleaner API compared to manually creatingSliverChildListDelegate.What was added
The constructor uses
SliverChildListDelegateinternally and follows the same pattern as existing convenience constructors likeSliverGrid.countandSliverGrid.extent. This addresses the use case where developers want to create sliver grids with predefined widget lists without the verbosity of manually constructing the delegate.Before/After comparison
Before:
After:
Implementation details
SliverGrid.listconstructor inpackages/flutter/lib/src/widgets/sliver.dartList<Widget> childrenand all necessary delegate configuration parametersSliverChildListDelegateinternally for consistent behaviorpackages/flutter/test/widgets/slivers_test.dartIssue addressed
Fixes: #173018
Pre-launch Checklist
///).