sliver_tools icon indicating copy to clipboard operation
sliver_tools copied to clipboard

Workaround for adding Sliver into an IndexedStack

Open alexda12 opened this issue 1 year ago • 1 comments

Hi, firstly - thanks for such a fantastic, easy to use sliver package. I use this extensively and its really allowed me to create with ease sliver related functionality.

I'm now finding however a limitation - maybe you can provide a potential workaround. I have a Tab where I have 3 tabviews, the contents of each tabview is a Sliver. Prior to placing each tabview in a sliver, I used an IndexedStack which basically promoted the currently active tabs data, thus making it current and displaying the List. This works perfectly ... however, once I switched to using a SliverList for each of the 3 tabviews, I found that the IndexedStack did not permit a SliverList to be a direct child.

I therefore tried to provide a workaround , such as :

return SliverStack (children: [
      SliverOffstage(
        offstage: tabIndex == 0 ? false : true,
        sliver: SliverIgnorePointer(
          ignoring: tabIndex == 0 ? false : true,
          sliver: SliverVisibility(
            maintainState: true,
            sliver: sliverListData1,
            visible: tabIndex == 0 ? true : false,
          ),
        ),
      ),
      SliverOffstage(
        offstage: tabIndex == 1 ? false : true,
        sliver: SliverIgnorePointer(
          ignoring: tabIndex == 1 ? false : true,
          sliver: SliverVisibility(
            maintainState: true,
            sliver: sliverListData2,
            visible: tabIndex == 1 ? true : false,
          ),
        ),
      ),
      SliverOffstage (
        offstage: tabIndex == 2 ? false : true,
        sliver: SliverIgnorePointer(
          ignoring: tabIndex == 2 ? false : true,
          sliver: SliverVisibility (
            maintainState: true,
            sliver: sliverListData3,
            visible: tabIndex == 2 ? true : false,
          ),
        ),
      ),
    ]);

As you can see, I add all three list views on top of each other and only show the data for the active tab. That works perfectly. The issue I have however is that even though we only show 1 active SliverList at a time, the hidden SliverLists appear to still receive events (and thus rebuild) when we scroll the primary (active) SliverList.

I was playing around with using :

Offstage, Opacity, Visibility, Absorbing, Ignore etc widgets to try and prevent the hidden Widgets from receiving and rebuilding but since they are placed on a SliverStack (and no SliverIndexedStack) they still receive events and thus cause further issues.

So, to conclude - is there any plans for a SliverIndexStack or do you know of any way to accomplish the above ?

TIA.

alexda12 avatar Aug 10 '23 11:08 alexda12

I'm not planning on adding new features myself in the nearby future.

But I do have a draft PR open which does something similar

Kavantix avatar Nov 08 '23 10:11 Kavantix