import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:go_router/go_router.dart'; import '../features/dashboard/dashboard_screen.dart'; import '../features/blocks/blocks_screen.dart'; import '../features/blocks/block_detail_screen.dart'; import '../features/wallet/wallet_screen.dart'; import '../features/transactions/transactions_screen.dart'; import '../features/transactions/send_tx_screen.dart'; import '../features/mining/mining_screen.dart'; final appRouterProvider = Provider((ref) { return GoRouter( initialLocation: '/', routes: [ ShellRoute( builder: (context, state, child) => ScaffoldWithNav(child: child), routes: [ GoRoute( path: '/', builder: (context, state) => const DashboardScreen(), ), GoRoute( path: '/blocks', builder: (context, state) => const BlocksScreen(), ), GoRoute( path: '/blocks/:hash', builder: (context, state) => BlockDetailScreen( hash: state.pathParameters['hash']!, ), ), GoRoute( path: '/wallets', builder: (context, state) => const WalletScreen(), ), GoRoute( path: '/transactions', builder: (context, state) => const TransactionsScreen(), ), GoRoute( path: '/transactions/send', builder: (context, state) => const SendTxScreen(), ), GoRoute( path: '/mining', builder: (context, state) => const MiningScreen(), ), ], ), ], ); }); class ScaffoldWithNav extends StatelessWidget { final Widget child; const ScaffoldWithNav({super.key, required this.child}); @override Widget build(BuildContext context) { return Scaffold( body: child, bottomNavigationBar: NavigationBar( selectedIndex: _calculateIndex(GoRouterState.of(context).uri.path), onDestinationSelected: (index) => _onTap(context, index), destinations: const [ NavigationDestination(icon: Icon(Icons.dashboard), label: 'Dashboard'), NavigationDestination(icon: Icon(Icons.view_in_ar), label: 'Blocks'), NavigationDestination(icon: Icon(Icons.account_balance_wallet), label: 'Wallets'), NavigationDestination(icon: Icon(Icons.swap_horiz), label: 'Transactions'), NavigationDestination(icon: Icon(Icons.hardware), label: 'Mining'), ], ), ); } int _calculateIndex(String path) { if (path.startsWith('/blocks')) return 1; if (path.startsWith('/wallets')) return 2; if (path.startsWith('/transactions')) return 3; if (path.startsWith('/mining')) return 4; return 0; } void _onTap(BuildContext context, int index) { switch (index) { case 0: context.go('/'); case 1: context.go('/blocks'); case 2: context.go('/wallets'); case 3: context.go('/transactions'); case 4: context.go('/mining'); } } }