ScrollablePositionedList with SliverAppBar not working properly
Answering question myself
This problem has no solution for it. I have created an issue here
It looks like ScrollablePositionedList
with SliverAppBar
cannot work until Flutter Team does not add shrinkwrap
property to ScrollablePositionedList
.
Feature request to add shrinkwrap
is created here
Ravinder Kumar
I am a mobile developer who loves to write Native Android as well as Flutter mobile applications.
Updated on November 24, 2022Comments
-
Ravinder Kumar over 1 year
This is a repository to create a minimal reproducible example.
I want
SliverAppBar
hidden whenScrollablePositionedList.builder
is Scrolled. This is the relevant piece of code I am including here.NestedScrollView( headerSliverBuilder: (context, innerBoxIsScrolled) => [ SliverAppBar( backgroundColor: Colors.blue, expandedHeight: 112, snap: true, pinned: false, floating: true, forceElevated: true, actions: <Widget>[ IconButton( icon: Icon(Icons.event), ) ], flexibleSpace: SafeArea( child: Column( children: <Widget>[ Container( height: kToolbarHeight, child: Column( crossAxisAlignment: CrossAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center, children: <Widget>[ Text( 'Title', style: Theme.of(context) .textTheme .title .copyWith( fontSize: 16, color: Colors.white), ), SizedBox( height: 2, ), Text( 'Date', style: Theme.of(context) .textTheme .caption .copyWith( fontSize: 10, color: Colors.white), ), SizedBox( height: 2, ), Text( 'Another Text', style: Theme.of(context) .textTheme .subtitle .copyWith( fontSize: 14, color: Colors.white), ), ], ), ), Expanded( child: Container( height: kToolbarHeight, width: MediaQuery.of(context).size.width, color: Colors.white, child: Row( mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: <Widget>[ Text( 'Prev', ), Text( 'Next', ) ], ), ), ) ], ), ), ) ], body: ScrollablePositionedList.builder( physics: ScrollPhysics(), itemPositionsListener: itemPositionListener, itemScrollController: _itemScrollController, initialScrollIndex: 0, itemCount: 500, itemBuilder: (BuildContext ctxt, int index) { return Container( margin: EdgeInsets.all(16) , child: Text('$index')); })),
I tried two approaches so far none of them working properly,
Approach 1
I added
physics: ScrollPhysics(),
toScrollablePositionedList.builder
Output:
Appraoch 2
I added
physics: NeverScrollableScrollPhysics(),
toScrollablePositionedList.builder
SliverAppBar
hides this time but now I can not scroll to the very end ofScrollablePositionedList.builder
I have 500 items on my list but it scrolls up to only 14th item, see the output. Also, it lags too much on scrollOutput:
Thanks in advance.
-
ch271828n over 3 yearsHi did you find any alternative solution? Thanks!
-
Vimal Patel over 2 yearsYour answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation.You can find more information on how to write good answers in the help center. See [How to Answer]stackoverflow.com/questions/how-to-answer)
-
Ravinder Kumar over 2 yearsI don't see
ScrollablePositionedList
in your code.