infinite_scroll_pagination icon indicating copy to clipboard operation
infinite_scroll_pagination copied to clipboard

Missing the ability to insert Sliver children

Open creativecreatorormaybenot opened this issue 4 years ago • 6 comments

Feature request

This request is similar to https://github.com/EdsonBueno/infinite_scroll_pagination/issues/48, however, the use case is actually not yet covered by the package (not that I know). Namely, we need section headers, which requires to have slivers as children of the paged list.

Current support

What you can do currently is implement a sticky header:

slivers: [
  StickySliverHeader(...),
  PagedSliverList(...),
],

However, you cannot have section headers, i.e.:

PagedSliverList(
  pagingController: viewModel.pagingController,
  builderDelegate: PagedChildBuilderDelegate<LearningPlansOverviewItem>(
    itemBuilder: (context, item, index) {
      if (item is SectionHeaderItem) {
        return SliverHeader(...);
      }
      return RegularItemTile(...);
  ),
),

Proposal

It would be nice to have a version of the PagedSliverList that allows to have a PagedSliverBuilderDelegate that allows you to return Slivers instead of regular widgets (render box contract).

@EdsonBueno if you have another idea how to solve this, let me know.

Hi @creativecreatorormaybenot , I'm curious to know how you'd do that with a regular SliverList, because it seems to me that not even SliverList works this way.

EdsonBueno avatar Oct 17 '21 20:10 EdsonBueno

@EdsonBueno Why do you think that this is not possible?

The way you do it is by placing the sticky headers as slivers into the CustomScrollView (see this for example). You do not place inside of the SliverList, but that is also not how it is supposed to work.

The reason this is not possible with PagedSliverList is that the headers need to be added as part of the paging. That is, to support this, PagedSliverList would need to work with the sliver contract in a way where it places the header slivers in between sections of render box children.

By doing this, we would loose the ability to build children on demand, since CustomScrollView takes all its children at once, and not via a builder. This library relies on having the children built on demand to know when it's time to fetch more items.

EdsonBueno avatar Oct 19 '21 09:10 EdsonBueno

@EdsonBueno You can implement the same logic using a builder.

That is also what I am saying btw - this is possible without pagination / a builder, but with the pagination package it is not possible at the moment. It would of course need to be implemented.

We need this feature.

For now, we can use this plugin to use sticky headers inside listview https://pub.dev/packages/sticky_headers

ariefwijaya avatar Dec 17 '22 06:12 ariefwijaya

Adding some more example to this request. I stumbled upon exactly this same problem recently. My use case is as follows:

  • Full page needs to be vertically scrollable.
  • Page starts with title, followed by on horizontal list, followed by a paged grid which is grouped in sections with section title as header.

I stumbled upon this example for sticky header which uses sliver_tools for sticky header. They use simple trick of returning a MultiSliver in a sliver based list.

The way PagedSliverList is implemented in this package, it only accepts PagedChildBuilderDelegate which has an item builder from which we are not allowed to return sliver based widget. It is mandatory to return a RenderBox based widget. It breaks if we return a RenderSliver based widget from PagedChildBuilderDelegate's item builder.

therohansanap avatar May 18 '23 09:05 therohansanap