Skip to content

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. #174157

@alshareeforgect-pixel

Description

@alshareeforgect-pixel

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.

Originally posted by @ahmeddhus in #173925

Metadata

Metadata

Assignees

No one assigned

    Labels

    r: invalidIssue is closed as not valid

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions