This commit is contained in:
Phuoc Nguyen
2025-10-23 17:03:58 +07:00
parent 30c245b401
commit 9189b65ebf
22 changed files with 589 additions and 195 deletions

View File

@@ -0,0 +1,81 @@
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
/// Shell widget that provides bottom navigation for the app
class AppBottomNavShell extends StatelessWidget {
const AppBottomNavShell({
super.key,
required this.child,
});
final Widget child;
@override
Widget build(BuildContext context) {
return Scaffold(
body: child,
bottomNavigationBar: _AppBottomNavigationBar(),
);
}
}
class _AppBottomNavigationBar extends StatelessWidget {
@override
Widget build(BuildContext context) {
final location = GoRouterState.of(context).matchedLocation;
// Determine current index based on location
int currentIndex = 0;
if (location == '/') {
currentIndex = 0;
} else if (location.startsWith('/products')) {
currentIndex = 1;
} else if (location.startsWith('/categories')) {
currentIndex = 2;
} else if (location.startsWith('/settings')) {
currentIndex = 3;
}
return NavigationBar(
selectedIndex: currentIndex,
onDestinationSelected: (index) {
switch (index) {
case 0:
context.go('/');
break;
case 1:
context.go('/products');
break;
case 2:
context.go('/categories');
break;
case 3:
context.go('/settings');
break;
}
},
destinations: const [
NavigationDestination(
icon: Icon(Icons.point_of_sale_outlined),
selectedIcon: Icon(Icons.point_of_sale),
label: 'Home',
),
NavigationDestination(
icon: Icon(Icons.inventory_2_outlined),
selectedIcon: Icon(Icons.inventory_2),
label: 'Products',
),
NavigationDestination(
icon: Icon(Icons.category_outlined),
selectedIcon: Icon(Icons.category),
label: 'Categories',
),
NavigationDestination(
icon: Icon(Icons.settings_outlined),
selectedIcon: Icon(Icons.settings),
label: 'Settings',
),
],
);
}
}