Basically i have a shellroute builder (go router) where i want to display the appbar and bottomnavigationbar on all child routes.
ShellRoute(
navigatorKey: _shellNavigatorKey,
builder: (context, state, child) => DashboardScreen(child: child),
The issue I'm facing is how to make all child routes which are widget.child on DashboardScreen scrolling hide/show/float the sliverappbar?!
class DashboardScreen extends ConsumerStatefulWidget {
const DashboardScreen({Key? key, required this.child}) : super(key: key);
final Widget child;
...
DefaultTabController(
length: 6,
child: Scaffold(
bottomNavigationBar: bottomMenuBuilder(context),
padding: EdgeInsets.zero,
body: NestedScrollView(
floatHeaderSlivers: true,
headerSliverBuilder:
(BuildContext context, bool innerBoxIsScrolled) {
return <Widget>[
const SliverAppBar(
title: Text("floating appbar"),
centerTitle: false,
automaticallyImplyLeading: false,
floating: true,
actions: [
Icon(Icons.search, size: 30, color: Colors.white),
],
elevation: 0.0,
),
];
},
body: widget.child,
),
),
)
I was facing the same issue and came up with a (dirty) workaround. I simply disable user scrolling for the NestedScrollView and all child scroll views. Then I stack a custom scrollview on top of my ShellRoute and listen for the scroll notification of this scroll view. I use the offset to calculate the offets for NestedScrollView and the child scroll views.
Here is my code:
EDIT I filed an issue: https://github.com/flutter/flutter/issues/138209