timetracker/lib/core/router/app_router.dart
2026-08-03 21:51:48 +02:00

74 lines
2.9 KiB
Dart

import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart';
import 'package:timetrack/features/timer/presentation/timer_screen.dart';
import 'package:timetrack/features/entries/presentation/entries_screen.dart';
import 'package:timetrack/features/projects/presentation/projects_screen.dart';
import 'package:timetrack/features/reports/presentation/reports_screen.dart';
import 'package:timetrack/features/settings/presentation/settings_screen.dart';
part 'app_router.g.dart';
@riverpod
GoRouter appRouter(AppRouterRef ref) {
return GoRouter(
initialLocation: AppRoutes.timer,
routes: [
StatefulShellRoute.indexedStack(
builder: (context, state, navigationShell) =>
ScaffoldWithNavBar(navigationShell: navigationShell),
branches: [
StatefulShellBranch(routes: [
GoRoute(path: AppRoutes.timer, builder: (context, state) => const TimerScreen()),
]),
StatefulShellBranch(routes: [
GoRoute(path: AppRoutes.entries, builder: (context, state) => const EntriesScreen()),
]),
StatefulShellBranch(routes: [
GoRoute(path: AppRoutes.projects, builder: (context, state) => const ProjectsScreen()),
]),
StatefulShellBranch(routes: [
GoRoute(path: AppRoutes.reports, builder: (context, state) => const ReportsScreen()),
]),
StatefulShellBranch(routes: [
GoRoute(path: AppRoutes.settings, builder: (context, state) => const SettingsScreen()),
]),
],
),
],
);
}
class AppRoutes {
AppRoutes._();
static const timer = '/timer';
static const entries = '/entries';
static const projects = '/projects';
static const reports = '/reports';
static const settings = '/settings';
}
class ScaffoldWithNavBar extends StatelessWidget {
const ScaffoldWithNavBar({super.key, required this.navigationShell});
final StatefulNavigationShell navigationShell;
@override
Widget build(BuildContext context) {
return Scaffold(
body: navigationShell,
bottomNavigationBar: NavigationBar(
selectedIndex: navigationShell.currentIndex,
onDestinationSelected: navigationShell.goBranch,
destinations: const [
NavigationDestination(icon: Icon(Icons.timer_outlined), selectedIcon: Icon(Icons.timer), label: 'Timer'),
NavigationDestination(icon: Icon(Icons.list_outlined), selectedIcon: Icon(Icons.list), label: 'Entries'),
NavigationDestination(icon: Icon(Icons.folder_outlined), selectedIcon: Icon(Icons.folder), label: 'Projects'),
NavigationDestination(icon: Icon(Icons.bar_chart_outlined), selectedIcon: Icon(Icons.bar_chart), label: 'Reports'),
NavigationDestination(icon: Icon(Icons.settings_outlined), selectedIcon: Icon(Icons.settings), label: 'Settings'),
],
),
);
}
}