Files
base_flutter/lib/main.dart
2025-09-26 18:48:14 +07:00

64 lines
1.7 KiB
Dart

import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'core/constants/app_constants.dart';
import 'core/database/hive_service.dart';
import 'core/theme/app_theme.dart';
import 'core/routing/routing.dart';
import 'shared/presentation/providers/app_providers.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
try {
// Initialize Hive database service
await HiveService.initialize();
runApp(
const ProviderScope(
child: MyApp(),
),
);
} catch (e, stackTrace) {
// Handle initialization error
debugPrint('❌ Failed to initialize app: $e');
debugPrint('Stack trace: $stackTrace');
// You might want to show an error screen here
runApp(MaterialApp(
home: Scaffold(
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Icon(Icons.error, color: Colors.red, size: 64),
const SizedBox(height: 16),
const Text('Failed to initialize app'),
const SizedBox(height: 8),
Text(e.toString()),
],
),
),
),
));
}
}
class MyApp extends ConsumerWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context, WidgetRef ref) {
final themeMode = ref.watch(themeModeProvider);
final router = ref.watch(routerProvider);
return MaterialApp.router(
title: AppConstants.appName,
debugShowCheckedModeBanner: false,
theme: AppTheme.lightTheme,
darkTheme: AppTheme.darkTheme,
themeMode: themeMode,
routerConfig: router,
);
}
}