mirror of
https://github.com/koloideal/Casha.git
synced 2026-06-10 10:25:28 +03:00
80 lines
2.3 KiB
Dart
80 lines
2.3 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:go_router/go_router.dart';
|
|
import '../features/dashboard/screen.dart';
|
|
import '../features/add_transaction/screen.dart';
|
|
import '../features/categories/screen.dart';
|
|
|
|
final _shellKey = GlobalKey<NavigatorState>();
|
|
|
|
final appRouter = GoRouter(
|
|
initialLocation: '/dashboard',
|
|
routes: [
|
|
ShellRoute(
|
|
navigatorKey: _shellKey,
|
|
builder: (context, state, child) => AppShell(child: child),
|
|
routes: [
|
|
GoRoute(
|
|
path: '/dashboard',
|
|
pageBuilder: (context, state) => const NoTransitionPage(
|
|
child: DashboardScreen(),
|
|
),
|
|
),
|
|
GoRoute(
|
|
path: '/categories',
|
|
pageBuilder: (context, state) => const NoTransitionPage(
|
|
child: CategoriesScreen(),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
GoRoute(
|
|
path: '/add',
|
|
builder: (context, state) => const AddTransactionScreen(),
|
|
),
|
|
],
|
|
);
|
|
|
|
class AppShell extends StatelessWidget {
|
|
final Widget child;
|
|
const AppShell({super.key, required this.child});
|
|
|
|
int _locationToIndex(BuildContext context) {
|
|
final location = GoRouterState.of(context).uri.toString();
|
|
if (location.startsWith('/categories')) return 1;
|
|
return 0;
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final idx = _locationToIndex(context);
|
|
return Scaffold(
|
|
body: child,
|
|
floatingActionButton: FloatingActionButton(
|
|
onPressed: () => context.push('/add'),
|
|
backgroundColor: const Color(0xFF7C6DED),
|
|
child: const Icon(Icons.add, color: Colors.white),
|
|
),
|
|
floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
|
|
bottomNavigationBar: NavigationBar(
|
|
selectedIndex: idx,
|
|
onDestinationSelected: (i) {
|
|
if (i == 0) context.go('/dashboard');
|
|
if (i == 1) context.go('/categories');
|
|
},
|
|
destinations: const [
|
|
NavigationDestination(
|
|
icon: Icon(Icons.dashboard_outlined),
|
|
selectedIcon: Icon(Icons.dashboard_rounded),
|
|
label: 'Dashboard',
|
|
),
|
|
NavigationDestination(
|
|
icon: Icon(Icons.pie_chart_outline_rounded),
|
|
selectedIcon: Icon(Icons.pie_chart_rounded),
|
|
label: 'Categories',
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|