runable
This commit is contained in:
@@ -1,8 +1,31 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'screens/home_screen.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:hive_ce/hive.dart';
|
||||
import 'package:hive_ce_flutter/adapters.dart';
|
||||
import 'package:minhthu/core/constants/app_constants.dart';
|
||||
import 'package:minhthu/core/theme/app_theme.dart';
|
||||
import 'package:minhthu/features/scanner/data/models/scan_item.dart';
|
||||
import 'package:minhthu/features/scanner/presentation/pages/home_page.dart';
|
||||
import 'package:minhthu/features/scanner/presentation/pages/detail_page.dart';
|
||||
|
||||
void main() {
|
||||
runApp(const MyApp());
|
||||
void main() async {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
|
||||
// Initialize Hive
|
||||
await Hive.initFlutter();
|
||||
|
||||
// Register Hive adapters
|
||||
Hive.registerAdapter(ScanItemAdapter());
|
||||
|
||||
// Open Hive boxes
|
||||
await Hive.openBox<ScanItem>(AppConstants.scanHistoryBox);
|
||||
|
||||
runApp(
|
||||
const ProviderScope(
|
||||
child: MyApp(),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
class MyApp extends StatelessWidget {
|
||||
@@ -10,14 +33,30 @@ class MyApp extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return MaterialApp(
|
||||
title: 'Barcode Scanner App',
|
||||
theme: ThemeData(
|
||||
colorScheme: ColorScheme.fromSeed(seedColor: Colors.blue),
|
||||
useMaterial3: true,
|
||||
),
|
||||
final router = GoRouter(
|
||||
initialLocation: '/',
|
||||
routes: [
|
||||
GoRoute(
|
||||
path: '/',
|
||||
builder: (context, state) => const HomePage(),
|
||||
),
|
||||
GoRoute(
|
||||
path: '/detail/:barcode',
|
||||
builder: (context, state) {
|
||||
final barcode = state.pathParameters['barcode'] ?? '';
|
||||
return DetailPage(barcode: barcode);
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
|
||||
return MaterialApp.router(
|
||||
title: 'Barcode Scanner',
|
||||
theme: AppTheme.lightTheme,
|
||||
darkTheme: AppTheme.darkTheme,
|
||||
themeMode: ThemeMode.system,
|
||||
routerConfig: router,
|
||||
debugShowCheckedModeBanner: false,
|
||||
home: const HomeScreen(),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user