@@ -8,11 +8,13 @@ import 'package:floaty/shared/components/switcher.dart';
88import 'package:floaty/whitelabels.dart' ;
99import 'package:flutter/material.dart' ;
1010import 'package:flutter_riverpod/flutter_riverpod.dart' ;
11+ import 'package:go_router/go_router.dart' ;
1112
1213import 'package:floaty/features/api/models/definitions.dart' ;
1314import 'package:floaty/shared/controllers/root_provider.dart' ;
1415import 'package:floaty/features/player/components/custom_player/mini_player_overlay.dart' ;
1516import 'package:floaty/features/player/controllers/media_player_service.dart' ;
17+ import 'package:hive_ce_flutter/hive_flutter.dart' ;
1618// No router import here — RootLayout is a plain shell widget.
1719
1820// RootLayout is a plain shell widget. A single global key is used so
@@ -36,6 +38,7 @@ class RootLayoutState extends ConsumerState<RootLayout>
3638 bool ? _lastSidebarCollapsed;
3739 bool _textGuardInitialized = false ;
3840 bool updateReady = updatercontroller.updateReady;
41+ int _selectedIndex = 0 ;
3942 @override
4043 void initState () {
4144 super .initState ();
@@ -81,6 +84,12 @@ class RootLayoutState extends ConsumerState<RootLayout>
8184 final screenWidth = MediaQuery .of (context).size.width;
8285 isSmallScreen = screenWidth < 600 ;
8386 bool subed = false ;
87+ final settingsBox = Hive .box ('settings' );
88+ //TODO: put back
89+ final bottomNavEnabled = false ;
90+ // final bottomNavEnabled =
91+ // settingsBox.get('bottom_navigation', defaultValue: true) as bool;
92+ final useBottomNav = isSmallScreen && bottomNavEnabled;
8493
8594 final isSidebarCollapsed = isSmallScreen ? false : rootState.isCollapsed;
8695
@@ -288,24 +297,54 @@ class RootLayoutState extends ConsumerState<RootLayout>
288297 surfaceTintColor: colorScheme.surfaceContainer,
289298 title: rootState.appBarTitle,
290299 actions: rootState.appBarActions,
291- leading: rootState.appBarLeading ??
292- (isSmallScreen
293- ? IconButton (
294- icon: const Icon (Icons .menu),
295- onPressed: () {
296- scaffoldKey.currentState? .openDrawer ();
297- },
298- )
299- : (Navigator .of (context).canPop ()
300- ? IconButton (
301- icon: const Icon (Icons .arrow_back),
302- onPressed: () {
303- Navigator .of (context).pop ();
304- },
305- )
306- : null )),
300+ leading: (() {
301+ if (rootState.appBarLeading != null ) return rootState.appBarLeading;
302+ if (isSmallScreen) {
303+ // On small screens:
304+ // - If bottom nav is NOT enabled, show the menu button.
305+ // - If bottom nav IS enabled, show a back button except on root routes.
306+ if (! useBottomNav) {
307+ return IconButton (
308+ icon: const Icon (Icons .menu),
309+ onPressed: () {
310+ scaffoldKey.currentState? .openDrawer ();
311+ },
312+ );
313+ }
314+
315+ final currentPath = GoRouter .of (context).state.uri.path;
316+ const rootRoutes = [
317+ '/home' ,
318+ '/browse' ,
319+ '/history' ,
320+ '/offline' ,
321+ '/more'
322+ ];
323+ final isRootRoute =
324+ rootRoutes.any ((r) => currentPath.startsWith (r));
325+ if (isRootRoute) return null ;
326+ return IconButton (
327+ icon: const Icon (Icons .arrow_back),
328+ onPressed: () {
329+ if (GoRouter .of (context).canPop ()) {
330+ context.pop ();
331+ } else {
332+ context.go ('/home' );
333+ }
334+ },
335+ );
336+ }
337+ return Navigator .of (context).canPop ()
338+ ? IconButton (
339+ icon: const Icon (Icons .arrow_back),
340+ onPressed: () {
341+ Navigator .of (context).pop ();
342+ },
343+ )
344+ : null ;
345+ }()),
307346 ),
308- drawer: isSmallScreen ? sidebar : null ,
347+ drawer: ( isSmallScreen && ! useBottomNav) ? sidebar : null ,
309348 body: SafeArea (
310349 child: Row (
311350 children: [
@@ -330,6 +369,41 @@ class RootLayoutState extends ConsumerState<RootLayout>
330369 ],
331370 ),
332371 ),
372+ bottomNavigationBar: useBottomNav
373+ ? NavigationBar (
374+ selectedIndex: _selectedIndex,
375+ onDestinationSelected: (idx) {
376+ String route = '/home' ;
377+ switch (idx) {
378+ case 0 :
379+ route = '/home' ;
380+ break ;
381+ case 1 :
382+ route = '/history' ;
383+ break ;
384+ case 2 :
385+ route = '/browse' ;
386+ break ;
387+ case 3 :
388+ route = '/more' ;
389+ break ;
390+ }
391+ setState (() {
392+ _selectedIndex = idx;
393+ });
394+ context.go (route);
395+ },
396+ destinations: const [
397+ NavigationDestination (icon: Icon (Icons .home), label: 'Home' ),
398+ NavigationDestination (
399+ icon: Icon (Icons .history), label: 'History' ),
400+ NavigationDestination (
401+ icon: Icon (Icons .view_carousel), label: 'Browse' ),
402+ NavigationDestination (
403+ icon: Icon (Icons .more_horiz), label: 'More' ),
404+ ],
405+ )
406+ : null ,
333407 );
334408 }
335409}
0 commit comments