flutter_layout_grid icon indicating copy to clipboard operation
flutter_layout_grid copied to clipboard

Feature Request: Scrollable LayoutGrid with Builder Functionality

Open clragon opened this issue 2 years ago • 2 comments

I am exploring this package as a potential alternative to flutter_staggered_grid_view, which no longer supports scrollable staggered grid views (it supports staggered grids, but these are not buildable or scrollable).

This package allows full control over placing items in rows and columns, which is invaluable for creative layouts. However, I couldn't find any option for using a Builder, which is a critical feature for my use case.

Ideally, a LayoutGrid builder should operate like other builders in Flutter. Instead of receiving a list of children, it would rather have a Widget Function(BuildContext context, int index) parameter to dynamically build its children. Using this approach, the Grid could build children only when they are in the viewport. This also means, the Grid would be scrollable and transform it into a LayoutGridView, based on Flutter's naming convention, where Views are scrollable. This functionality is crucial for larger grids with many children, as building all children at all times can lead to significant performance issues.

The usual practice in Flutter for lists and grids is to first create a Sliver version (a builder without a ScrollView), then provide a version wrapped in a BoxScrollView. For example, a ListView is a SliverList wrapped in a BoxScrollView.

The API might look similar to this:

  • a SliverLayoutGrid widget, which is a Sliver that uses a SliverChildBuilderDelegate to build its children.
  • a LayoutGridView widget which is a BoxScrollView that internally uses a SliverLayoutGrid. It could come with both a children list parameter and a .builder constructor. This would not replace the usual LayoutGrid, which is not scrollable.

Incorporating this functionality may entail a significant refactor, and I'm unsure about its feasibility with the current layout algorithm (since flutter_staggered_grid_view removed StaggeredGridView due to performance issues with its layout algorithm). It also deviates somewhat from a pure CSS grid. However, this enhancement would make the package incredibly versatile.

The key use case for this feature is to create infinite, paginated, quilted/staggered image layouts. Pagination can be added externally as long as a Sliver version with a builder is available. I typically use infinite_scroll_pagination to enable this functionality with any Sliver.

clragon avatar Jul 09 '23 11:07 clragon

I am searchig the same functionality, like the CSS grid or flex system, where the row elements expands to the height of the tallest row element, would be very useful if this package had some similar functionality.

Velkamhell97 avatar Jul 31 '23 22:07 Velkamhell97

I was about to make the same request, it would be very useful, specially for not having to set an specific row number.

itsmeemaaario-student avatar Sep 26 '23 12:09 itsmeemaaario-student