My project contains a main_section where I display a navBar and a body. Depending on the device, I am displaying an specific navBar.
My problem is that I need it to disappear when the user scrolls down.
How can I achieve this behaviour?
This is the code:
class MainPage extends StatefulWidget {
const MainPage({Key? key}) : super(key: key);
@override
State<MainPage> createState() => _MainPageState();
}
class _MainPageState extends State<MainPage> {
@override
Widget build(BuildContext context) {
App.init(context);
final drawerProvider = Provider.of<DrawerProvider>(context);
return Scaffold(
key: drawerProvider.key,
extendBodyBehindAppBar: true,
drawer: !Responsive.isDesktop(context) ? const _MobileDrawer() : null,
body: SafeArea(
child: Stack(
children: [
const _Body(),
const ArrowOnTop(),
Responsive.isTablet(context) || Responsive.isMobile(context)
? const _NavBarTablet()
: const _NavbarDesktop(),
],
),
),
);
}
}
2
Answers
You can do whatever you want using NestedScrollView and SliverAppBar.
You can add SliverAppBar to the headerSliverBuilder property of the NestedScrollView widget and other widgets you want to appear on the body property.
You can add appbar widget data in form of row in body section.
Sample code for this: