2024-05-10 17:49:47 -04:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
import 'package:go_router/go_router.dart';
|
2024-05-14 10:11:25 -04:00
|
|
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
|
|
|
|
import 'package:whispering_pages/features/player/view/audioobok_player.dart';
|
2024-05-10 17:49:47 -04:00
|
|
|
|
|
|
|
|
/// Builds the "shell" for the app by building a Scaffold with a
|
|
|
|
|
/// BottomNavigationBar, where [child] is placed in the body of the Scaffold.
|
2024-05-14 10:11:25 -04:00
|
|
|
class ScaffoldWithNavBar extends HookConsumerWidget {
|
2024-05-10 17:49:47 -04:00
|
|
|
/// Constructs an [ScaffoldWithNavBar].
|
|
|
|
|
const ScaffoldWithNavBar({
|
|
|
|
|
required this.navigationShell,
|
|
|
|
|
Key? key,
|
|
|
|
|
}) : super(key: key ?? const ValueKey<String>('ScaffoldWithNavBar'));
|
|
|
|
|
|
|
|
|
|
/// The navigation shell and container for the branch Navigators.
|
|
|
|
|
final StatefulNavigationShell navigationShell;
|
|
|
|
|
|
|
|
|
|
@override
|
2024-05-14 10:11:25 -04:00
|
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
2024-05-10 17:49:47 -04:00
|
|
|
return Scaffold(
|
2024-05-14 10:11:25 -04:00
|
|
|
body: Stack(
|
|
|
|
|
children: [
|
|
|
|
|
navigationShell,
|
|
|
|
|
const AudiobookPlayer(),
|
|
|
|
|
],
|
|
|
|
|
),
|
2024-05-10 17:49:47 -04:00
|
|
|
bottomNavigationBar: BottomNavigationBar(
|
|
|
|
|
elevation: 0.0,
|
|
|
|
|
landscapeLayout: BottomNavigationBarLandscapeLayout.centered,
|
|
|
|
|
selectedFontSize: Theme.of(context).textTheme.labelMedium!.fontSize!,
|
|
|
|
|
unselectedFontSize: Theme.of(context).textTheme.labelMedium!.fontSize!,
|
2024-05-11 04:46:17 -04:00
|
|
|
showUnselectedLabels: false,
|
|
|
|
|
fixedColor: Theme.of(context).colorScheme.onBackground,
|
2024-05-10 17:49:47 -04:00
|
|
|
// type: BottomNavigationBarType.fixed,
|
|
|
|
|
|
|
|
|
|
// Here, the items of BottomNavigationBar are hard coded. In a real
|
|
|
|
|
// world scenario, the items would most likely be generated from the
|
|
|
|
|
// branches of the shell route, which can be fetched using
|
|
|
|
|
// `navigationShell.route.branches`.
|
|
|
|
|
items: const <BottomNavigationBarItem>[
|
|
|
|
|
BottomNavigationBarItem(
|
|
|
|
|
label: 'Home',
|
|
|
|
|
icon: Icon(Icons.home_outlined),
|
|
|
|
|
activeIcon: Icon(Icons.home),
|
|
|
|
|
),
|
|
|
|
|
BottomNavigationBarItem(
|
|
|
|
|
label: 'Settings',
|
|
|
|
|
icon: Icon(Icons.settings_outlined),
|
|
|
|
|
activeIcon: Icon(Icons.settings),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
currentIndex: navigationShell.currentIndex,
|
|
|
|
|
onTap: (int index) => _onTap(context, index),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Navigate to the current location of the branch at the provided index when
|
|
|
|
|
/// tapping an item in the BottomNavigationBar.
|
|
|
|
|
void _onTap(BuildContext context, int index) {
|
|
|
|
|
// When navigating to a new branch, it's recommended to use the goBranch
|
|
|
|
|
// method, as doing so makes sure the last navigation state of the
|
|
|
|
|
// Navigator for the branch is restored.
|
|
|
|
|
navigationShell.goBranch(
|
|
|
|
|
index,
|
|
|
|
|
// A common pattern when using bottom navigation bars is to support
|
|
|
|
|
// navigating to the initial location when tapping the item that is
|
|
|
|
|
// already active. This example demonstrates how to support this behavior,
|
|
|
|
|
// using the initialLocation parameter of goBranch.
|
|
|
|
|
initialLocation: index == navigationShell.currentIndex,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|