I have the following scroll view
CustomScrollView(
physics: const NeverScrollableScrollPhysics(),
slivers: [
const SliverToBoxAdapter(
child: Placeholder(
fallbackHeight: 120,
),
),
const SliverToBoxAdapter(
child: SizedBox(
height: 180,
child: Placeholder(),
),
),
SliverFillRemaining(
child: _NavigationList(
items: routes.items,
),
),
],
),
Where I intend the parent list to not be scrollable but the nested list in the SliverFillRemaining
should be scrollable.
But what ends up happening is that the CustomScrollView
is still scrollable with the scroll bar and has quite a bit of overflow. The overflow seems to exactly match the height of the two placeholders combined. How can I make it so that the parent is not scrollable but the child is. Because now the scroll bar still shows up.
This is what it looks like. The app is full screen and there seems to be overflow and you can scroll using the scrollbar.
Btw I can’t solve this with a column because it will cause overflow errors also. And if you try to solve it with an column and expanded then you would need to wrap the column with a SingleChildScrollView to prevent those error, which you can’t do since there is an expanded in the Column.
THE QUESTION:
So very straightforward since I notice a misunderstanding of the issue in the answers. When you have a CustomScrollView and you add boxes with height and a SliverFillRemaining you would expect that there would not be any more overflow. This does seem to be the case and it matches the height of the boxes. And this is why the the parent CustomScrollView shows a scroll bar. My question is how do I prevent this.
6
Answers
So I approached it differently. Since the parent list is only scrollable with the scroll bar I decided to disable the scroll bar for the parent list. It solves the issue I had.
But it still seems a bug to me that boxes with height added to a CustomScrollView with a SliverFillRemaining create overflow.
For now I will accept this as the answer.
I made an example app with your code and it seems to be working as intended.
Please give it a try. I’m using flutter 3.3.9. If this does not help you, I would suggest posting the code of an example that fully reproduces your issue.
If you don’t intend the parent to scroll, then replace
CustomScrollView
with aColumn
, and make changes as below:Have you tried adding
hasScrollBody: false
to SliverFillRemaining? It should remove overflowsWith just using
SliverAppBar
you can achieve your desired output:just make
pinned: true
and givetoolbarHeight: *as per your need*,
I’m trying to use a
CustomScrollView
and twosliver
sections to freeze the header and scroll down other side. Help comments can be found in my solution:if using
ScrollConfiguration.of(context).copyWith(scrollbars: false)
as a behavior forScrollConfiguration
, The scrollbars are removed, but your scrolling in flutter web remains disabled.better use
MaterialScrollBehavior
widget like below: