Here is my code. The Appbar stays static when I scroll down. If you need more of the code, let me know.
I'm using auto_route flutter and the routes InvestHomeRouter() and BonusHomeRouter() lead to other scaffolds that have no own appbar and have singleChildScrollviews as bodys.
I want the parent scaffold to hide the appbar if the children scaffolds detect any scrolling down.
class Home extends StatelessWidget {
`const Home({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return SafeArea(
child: AutoTabsRouter(
routes: [
InvestHomeRouter(),
BonusHomeRouter()
],
builder: (context, child, animation) {
final tabsRouter = AutoTabsRouter.of(context);
return HomeScaffold(
tabsRouter: tabsRouter,
child: child,
animation: animation,
);
}));
}
}
class HomeScaffold extends StatefulWidget {
HomeScaffold(
{required this.tabsRouter,
required this.animation,
required this.child,
Key? key})
: super(key: key);
final Widget child;
final Animation<double> animation;
final TabsRouter tabsRouter;
@override
State<HomeScaffold> createState() => _HomeScaffoldState();
}
class _HomeScaffoldState extends State<HomeScaffold> {
int activeIndex = 0;
@override
Widget build(BuildContext context) {
return Scaffold(
body: NestedScrollView(
floatHeaderSlivers: true,
headerSliverBuilder: (context, innerBoxIsScrolled) => [
SliverAppBar(
floating: true,
],
),
],
body: FadeTransition(
opacity: widget.animation,
child: widget.child),
),
);
}