Skip to content

Conversation

ahmeddhus
Copy link
Contributor

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:

SliverGrid(
  gridDelegate: gridDelegate,
  delegate: SliverChildListDelegate([widget1, widget2, widget3]),
)

After:

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: #173018

Pre-launch Checklist

  • I read the [Contributor Guide] and followed the process outlined there for submitting PRs.
  • I read the [Tree Hygiene] wiki page, which explains my responsibilities.
  • I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement].
  • I signed the [CLA].
  • I listed at least one issue that this PR fixes in the description above.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or this PR is [test-exempt].
  • I followed the [breaking change policy] and added [Data Driven Fixes] where supported.
  • All existing and new tests are passing.

ahmeddhus and others added 3 commits August 17, 2025 13:49
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.
@github-actions github-actions bot added framework flutter/packages/flutter repository. See also f: labels. f: scrolling Viewports, list views, slivers, etc. labels Aug 17, 2025
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@justinmc
Copy link
Contributor

FYI @loic-sharma since you opened the issue asking for this (#173018).

@justinmc justinmc requested a review from loic-sharma August 19, 2025 22:05
Copy link
Member

@loic-sharma loic-sharma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me - thanks for the wonderful contribution!

@ahmeddhus
Copy link
Contributor Author

This looks good to me - thanks for the wonderful contribution!

Thank you! Excited to keep contributing 🙌

Comment on lines 812 to 813
///
///
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these two newlines intentional?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, that was unintentional. I’ve fixed it 👍

@loic-sharma
Copy link
Member

@ahmeddhus Looks like there are some formatting issues, can you run dart format?

See: https://logs.chromium.org/logs/flutter/buildbucket/cr-buildbucket/8705948798842944625/+/u/run_test.dart_for_analyze_shard_and_subshard_None/stdout

@ahmeddhus
Copy link
Contributor Author

@ahmeddhus Looks like there are some formatting issues, can you run dart format?

See: https://logs.chromium.org/logs/flutter/buildbucket/cr-buildbucket/8705948798842944625/+/u/run_test.dart_for_analyze_shard_and_subshard_None/stdout

Fixed 👍🏾

@justinmc justinmc requested a review from victorsanni August 26, 2025 22:04
Copy link
Contributor

@victorsanni victorsanni left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks for the PR

@victorsanni victorsanni added the autosubmit Merge PR when tree becomes green via auto submit App label Aug 28, 2025
@auto-submit auto-submit bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Aug 28, 2025
Copy link
Contributor

auto-submit bot commented Aug 28, 2025

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.

engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 31, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Sep 1, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Sep 1, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Sep 1, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Sep 2, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Sep 2, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Sep 2, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Sep 2, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Sep 2, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Sep 2, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Sep 2, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Sep 3, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Sep 3, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Sep 3, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Sep 4, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Sep 4, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Sep 4, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Sep 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
f: scrolling Viewports, list views, slivers, etc. framework flutter/packages/flutter repository. See also f: labels.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a SliverGrid.list convenience constructor
4 participants