Repository navigation
Floating SliverPersistantHeader hidden by pinned SliverAppBar #64137
Description
Hi,
I'm trying to have a SliverAppBar (which is fixed/pinned to the top) and under it a floating persistant header.
It goes like this :
import 'package:flutter/material.dart';
class SliverExample extends StatefulWidget {
@override
_SliverExampleState createState() => _SliverExampleState();
}
class _SliverExampleState extends State<SliverExample> {
@override
Widget build(BuildContext context) {
return Scaffold(
body: CustomScrollView(
physics: BouncingScrollPhysics(),
slivers: [
SliverAppBar(
pinned: true,
title: Text('Pinned AppBar'),
),
SliverPersistentHeader(
floating: true,
delegate: FloatingHeader(),
),
SliverList(
delegate: SliverChildListDelegate([
Container(
height: 2000,
color: Colors.white,
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text('TOP'),
Text('MIDDLE'),
Text('BOTTOM'),
]))),
]))
],
),
);
}
}
class FloatingHeader extends SliverPersistentHeaderDelegate {
@override
Widget build(
BuildContext context, double shrinkOffset, bool overlapsContent) {
return Container(
color: Colors.red,
child: Center(
child:
Text('Floating Header', style: TextStyle(color: Colors.white))),
);
}
@override
bool shouldRebuild(SliverPersistentHeaderDelegate _) => true;
@override
double get maxExtent => 250.0;
@override
double get minExtent => 80.0;
}
It works, but the problem is when you scroll down (and so the floating header disappear), and scroll back up so the header appears again, it appears but the top part is hidden by the SliverAppBar.
Then when you scroll back to the top of the page, everything is positionned as you would expect it to be (the SliverAppBar at the top and under it the floating header completely visible).
Here is what it looks like :
I don't know if this is a bug or I'm missing something.
How can I deal with that ? Such as the floating persistant header always appears completely under the SliverAppBar when you scroll back up after scrolling down for a while.

Activity
darshankawar commentedon Aug 19, 2020
Hi @RobinLbt,
The experience seems to be as expected to me. Unless you scroll down completely, you won't see the
Topsection appear belowFloating Headerand for it, you'll need to scroll down completely because you have wrapped the entire scaffold body withCustomScrollView.This is working as intended.
RobinLbt commentedon Aug 19, 2020
Thank you for your quick answer @darshankawar,
I'm not sure if we are talking about the same thing, I'm not trying to put the SliverAppBar below the floating header.
If you look at the gif, you can see when I'm scrolling down and then up:
darshankawar commentedon Aug 19, 2020
@RobinLbt I see what you are saying. Probably I misread your issue. Keeping this issue open for further analysis.
flutter doctor -v
HansMuller commentedon Aug 19, 2020
CC @Piinks - have we seen this issue before?
goderbauer commentedon Aug 19, 2020
Can the top appbar just live outside the scrollview, e.g. by setting
Scaffold.appBar?Piinks commentedon Aug 19, 2020
Just playing around with this a bit, I borrowed from this popular Medium article about Sliver composition and plugged in your reproduction:
https://medium.com/flutter/slivers-demystified-6ff68ab0296f
Does this create the effect you were looking for @RobinLbt ? I highly recommend the article as well. :)
RobinLbt commentedon Aug 20, 2020
@Piinks thank you for providing an example. It's definitely better !
There is still a problem, the floating header appears only at the top of the page now, not when you scroll down and then scroll up a bit (in the middle of the page for example) like it should.
Is it even possible ?
RobinLbt commentedon Aug 21, 2020
Yes this is working ! I'm closing the issue. Thanks you everyone.
github-actions commentedon Aug 13, 2021
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of
flutter doctor -vand a minimal reproduction of the issue.