Files
velocity-pay-flutter/lib/main.dart
2025-06-10 22:17:38 +02:00

122 lines
3.3 KiB
Dart

import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:go_router/go_router.dart';
import 'providers/transaction_provider.dart';
import 'screens/home_screen.dart';
import 'screens/make_payment_screen.dart';
import 'screens/history_screen.dart';
import 'screens/profile_screen.dart';
import 'theme/app_theme.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return ChangeNotifierProvider(
create: (_) => TransactionProvider(),
child: 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 MakePaymentScreen(),
),
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;
}
}