import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; import 'package:go_router/go_router.dart'; import 'package:qpay/screens/confirm/confirm_screen.dart'; import 'package:qpay/screens/gateway/gateway_screen.dart'; import 'package:qpay/screens/onboarding/complete_screen.dart'; import 'package:qpay/screens/onboarding/landing/landing_screen.dart'; import 'package:qpay/screens/onboarding/login/login_screen.dart'; import 'package:qpay/screens/onboarding/onboarding_controller.dart'; import 'package:qpay/screens/onboarding/password/password_screen.dart'; import 'package:qpay/screens/onboarding/phone/phone_screen.dart'; import 'package:qpay/screens/onboarding/register/register_screen.dart'; import 'package:qpay/screens/onboarding/verify/verify_screen.dart'; import 'package:qpay/screens/pay/pay_screen.dart'; import 'package:qpay/screens/receipt/receipt_screen.dart'; import 'package:qpay/screens/recipient/recipients_screen.dart'; import 'package:qpay/screens/transaction_controller.dart'; import 'screens/home/home_screen.dart'; import 'screens/history/history_screen.dart'; import 'screens/profile_screen.dart'; import 'screens/splash_screen.dart'; import 'theme/app_theme.dart'; import 'package:flutter_dotenv/flutter_dotenv.dart'; import 'package:firebase_core/firebase_core.dart'; import 'firebase_options.dart'; const String testEnv = "assets/.env"; const String liveEnv = "assets/.env"; void main() async { WidgetsFlutterBinding.ensureInitialized(); await Firebase.initializeApp( options: DefaultFirebaseOptions.currentPlatform, ); await dotenv.load(fileName: testEnv); runApp( MultiProvider( providers: [ ChangeNotifierProvider(create: (_) => TransactionController()), ChangeNotifierProvider(create: (_) => OnboardingController()), ], child: const MyApp(), ), ); } class MyApp extends StatefulWidget { const MyApp({super.key}); @override State createState() => _MyAppState(); } class _MyAppState extends State { bool _showSplash = false; void _onSplashComplete() { setState(() { _showSplash = false; }); } @override Widget build(BuildContext context) { if (_showSplash) { return MaterialApp( title: 'Peak', theme: AppTheme.lightTheme, themeMode: ThemeMode.light, home: SplashScreen(onSplashComplete: _onSplashComplete), debugShowCheckedModeBanner: false, ); } return MaterialApp.router( title: 'Peak', theme: AppTheme.lightTheme, themeMode: ThemeMode.light, // Force light mode regardless of OS setting debugShowCheckedModeBanner: false, routerConfig: GoRouter( initialLocation: '/', routes: [ ShellRoute( builder: (context, state, child) { // If the current location is an onboarding route, don't show the navbar final location = GoRouterState.of(context).uri.toString(); if (location.startsWith('/onboarding/')) { return child; } return ScaffoldWithNavBar(child: child); }, routes: [ GoRoute( path: '/', builder: (context, state) => const HomeScreen(), ), GoRoute( path: '/home', builder: (context, state) => const HomeScreen(), ), GoRoute( path: '/make-payment', builder: (context, state) => const PayScreen(), ), GoRoute( path: '/confirm', builder: (context, state) => const ConfirmScreen(), ), GoRoute( path: '/gateway', builder: (context, state) => GatewayScreen(url: state.extra as String), ), GoRoute( path: '/receipt', builder: (context, state) => const ReceiptScreen(), ), GoRoute( path: '/recipients', builder: (context, state) => const RecipientsScreen(), ), GoRoute( path: '/history', builder: (context, state) => const HistoryScreen(), ), GoRoute( path: '/profile', builder: (context, state) => const ProfileScreen(), ), GoRoute( path: '/onboarding/landing', builder: (context, state) => const LandingScreen(), ), GoRoute( path: '/onboarding/register', builder: (context, state) => const RegisterScreen(), ), GoRoute( path: '/onboarding/phone', builder: (context, state) => const PhoneScreen(), ), GoRoute( path: '/onboarding/verify', builder: (context, state) => const VerifyScreen(), ), GoRoute( path: '/onboarding/password', builder: (context, state) => const PasswordScreen(), ), GoRoute( path: '/onboarding/login', builder: (context, state) => const LoginScreen(), ), GoRoute( path: '/onboarding/complete', builder: (context, state) => const CompleteScreen(), ), ], ), ], ), ); } } class ScaffoldWithNavBar extends StatelessWidget { const ScaffoldWithNavBar({super.key, required this.child}); final Widget child; @override Widget build(BuildContext context) { return Scaffold( body: child, bottomNavigationBar: NavigationBar( onDestinationSelected: (index) { switch (index) { case 0: context.go('/home'); break; // case 1: // context.go('/recipients'); // break; case 1: context.go('/history'); break; // case 2: // context.go('/profile'); // break; } }, selectedIndex: _calculateSelectedIndex(context), destinations: const [ NavigationDestination( icon: Icon(Icons.home_outlined), selectedIcon: Icon(Icons.home), label: 'Home', ), // NavigationDestination( // icon: Icon(Icons.contacts_outlined), // selectedIcon: Icon(Icons.contacts), // label: 'Recipients', // ), NavigationDestination( icon: Icon(Icons.history_outlined), selectedIcon: Icon(Icons.history), label: 'History', ), // NavigationDestination( // icon: Icon(Icons.person_outline), // selectedIcon: Icon(Icons.person), // label: 'Profile', // ), ], ), ); } int _calculateSelectedIndex(BuildContext context) { final String location = GoRouterState.of(context).uri.path; // if (location.startsWith('/recipients')) return 1; if (location.startsWith('/history')) return 1; // if (location.startsWith('/profile')) return 2; return 0; } }