126 lines
3.4 KiB
Dart
126 lines
3.4 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:provider/provider.dart';
|
|
import 'package:go_router/go_router.dart';
|
|
import 'screens/home/home_screen.dart';
|
|
import 'screens/pay/pay_screen.dart';
|
|
import 'screens/history_screen.dart';
|
|
import 'screens/profile_screen.dart';
|
|
import 'theme/app_theme.dart';
|
|
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
|
import 'package:qpay/screens/pay/pay_controller.dart';
|
|
|
|
const String testEnv = "assets/.env";
|
|
const String liveEnv = "assets/.env";
|
|
|
|
void main() async {
|
|
await dotenv.load(fileName: testEnv);
|
|
runApp(
|
|
ChangeNotifierProvider(
|
|
create: (context) => PayController(),
|
|
child: const MyApp(),
|
|
),
|
|
);
|
|
}
|
|
|
|
class MyApp extends StatelessWidget {
|
|
const MyApp({super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return MaterialApp.router(
|
|
title: 'QPay',
|
|
theme: AppTheme.lightTheme,
|
|
routerConfig: GoRouter(
|
|
initialLocation: '/',
|
|
routes: [
|
|
ShellRoute(
|
|
builder: (context, state, child) {
|
|
return ScaffoldWithNavBar(child: child);
|
|
},
|
|
routes: [
|
|
GoRoute(
|
|
path: '/',
|
|
builder: (context, state) => const HomeScreen(),
|
|
),
|
|
GoRoute(
|
|
path: '/make-payment',
|
|
builder: (context, state) => const PayScreen(),
|
|
),
|
|
GoRoute(
|
|
path: '/history',
|
|
builder: (context, state) => const HistoryScreen(),
|
|
),
|
|
GoRoute(
|
|
path: '/profile',
|
|
builder: (context, state) => const ProfileScreen(),
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
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('/');
|
|
break;
|
|
case 1:
|
|
context.go('/make-payment');
|
|
break;
|
|
case 2:
|
|
context.go('/history');
|
|
break;
|
|
case 3:
|
|
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.payment_outlined),
|
|
selectedIcon: Icon(Icons.payment),
|
|
label: 'Pay',
|
|
),
|
|
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('/make-payment')) return 1;
|
|
if (location.startsWith('/history')) return 2;
|
|
if (location.startsWith('/profile')) return 3;
|
|
return 0;
|
|
}
|
|
}
|