Flutter - NestedScrollView's Body disappear under AppBar / Slivers

1k Views Asked by At

Why is the default behavior of a NestedScrollView to "scroll body" beyond app bar? And to have a body of X pixels is not respected neither.

How do you make the Container / Body widget not scroll beyond Sliver since it's obvious it doesn't need to do that. It's just one text. If the content is actually bigger than the body - then yes, it should scroll.

It's the same using SliverFillRemaining inside the Sliver - it takes "more" than what remains.

Example Code:

return Scaffold(
  body: NestedScrollView(
    headerSliverBuilder: (context, innerBoxIsScrolled) {
      return [
        SliverAppBar(
          pinned: true,
          title: Text("AppBar Title")
        )
      ];
    },
    body: Container(
      color: Colors.blue,
      height: 100, // Value not respected
      child: Text("This will disappear"),
    ),
  ),
);

Example Behaviour:

I can scroll the body beyond AppBar and then it's just gone. I can't find a reason for this to be the default behaviour.

enter image description here

0

There are 0 best solutions below