I have a code that has these main widgets:
CustomScrollView(
physics: const AlwaysScrollableScrollPhysics(
parent: BouncingScrollPhysics(),
),
slivers: [
SliverFillRemaining(
hasScrollBody: true,
child: ListView(
children: [],
),
),
],
),
I have it this way because around the ListView
widget I have a Column
so that on top of I have a widget that simulates a title.
I chose to work with all of them this way so that when my list has 2-3 items, the entire list and title show on the centre of the screen, and the outer scroll is bouncing with the title.
When the list is longer, what I wanted to accomplish was almost what I got, but I want to know if I’m able to control the scrolling with these rules:
- Scroll the list;
- If the list has ended (either top or bottom), scroll the
CustomScrollView
2
Answers
You can use sliver_tools package to pin the title only for an amount of scroll. I created an example by modifying this medium tutorial. The example will seem like https://imgur.com/a/W3nND7x
I haven’t delved that deep into scrolling yet, so i can only tell you what my approach would be. And i hope i understand your wanted behaviour correctly.
Similar to your example snippet use a
CustomScrollView
withSliverFixedExtentList
for the parts of your outer list.If you now want an inner list in the middle that is scrollable as well, use
SliverToBoxAdapter
withSizedBox
.And if you want an inner scrollable list at the end that is expanded to the remaining screen space, then use
SliverFillRemaining
.To now scroll the outer list if the inner lists reach the scroll end, use a
ScrollController
withOverscrollNotification
.And then you have inner scrollable lists that scroll the outer list when they reach the end of their own scroll: