62 lines
1.8 KiB
Dart
62 lines
1.8 KiB
Dart
import "package:flutter/material.dart";
|
|
|
|
import "../main.dart";
|
|
import "dashboard_screen.dart";
|
|
import "settings_screen.dart";
|
|
import "admin_users_screen.dart";
|
|
|
|
/// The app's root shell — a persistent bottom navigation bar (DriverVault mockup
|
|
/// layout) hosting the Garage, Settings and (for admins) Users sections in an
|
|
/// IndexedStack so each keeps its state as you switch tabs.
|
|
class RootShell extends StatefulWidget {
|
|
const RootShell({super.key});
|
|
@override
|
|
State<RootShell> createState() => _RootShellState();
|
|
}
|
|
|
|
class _RootShellState extends State<RootShell> {
|
|
int _index = 0;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final isAdmin = authService.user?.isAdmin == true;
|
|
|
|
final pages = <Widget>[
|
|
const DashboardScreen(),
|
|
const SettingsScreen(),
|
|
if (isAdmin) const AdminUsersScreen(),
|
|
];
|
|
|
|
final destinations = <NavigationDestination>[
|
|
const NavigationDestination(
|
|
icon: Icon(Icons.grid_view_outlined),
|
|
selectedIcon: Icon(Icons.grid_view_rounded),
|
|
label: "Garage",
|
|
),
|
|
const NavigationDestination(
|
|
icon: Icon(Icons.settings_outlined),
|
|
selectedIcon: Icon(Icons.settings),
|
|
label: "Settings",
|
|
),
|
|
if (isAdmin)
|
|
const NavigationDestination(
|
|
icon: Icon(Icons.group_outlined),
|
|
selectedIcon: Icon(Icons.group),
|
|
label: "Users",
|
|
),
|
|
];
|
|
|
|
// Guard against the index falling out of range if admin status changes.
|
|
final index = _index.clamp(0, pages.length - 1);
|
|
|
|
return Scaffold(
|
|
body: IndexedStack(index: index, children: pages),
|
|
bottomNavigationBar: NavigationBar(
|
|
selectedIndex: index,
|
|
onDestinationSelected: (i) => setState(() => _index = i),
|
|
destinations: destinations,
|
|
),
|
|
);
|
|
}
|
|
}
|