New
This commit is contained in:
@@ -1,13 +1,13 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:hive_flutter/hive_flutter.dart';
|
||||
import 'package:google_fonts/google_fonts.dart';
|
||||
|
||||
import 'models/scripture.dart';
|
||||
import 'theme/app_theme.dart';
|
||||
import 'screens/splash_screen.dart';
|
||||
import 'models/user_profile.dart';
|
||||
import 'models/cycle_entry.dart';
|
||||
import 'providers/user_provider.dart';
|
||||
|
||||
void main() async {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
@@ -26,7 +26,8 @@ void main() async {
|
||||
Hive.registerAdapter(CyclePhaseAdapter());
|
||||
Hive.registerAdapter(UserRoleAdapter());
|
||||
Hive.registerAdapter(BibleTranslationAdapter());
|
||||
Hive.registerAdapter(ScriptureAdapter()); // Register Scripture adapter
|
||||
Hive.registerAdapter(ScriptureAdapter());
|
||||
Hive.registerAdapter(AppThemeModeAdapter()); // Register new adapter
|
||||
|
||||
// Open boxes and load scriptures in parallel
|
||||
await Future.wait([
|
||||
@@ -38,17 +39,52 @@ void main() async {
|
||||
runApp(const ProviderScope(child: ChristianPeriodTrackerApp()));
|
||||
}
|
||||
|
||||
class ChristianPeriodTrackerApp extends StatelessWidget {
|
||||
// Helper to convert hex string to Color
|
||||
Color _colorFromHex(String hexColor) {
|
||||
try {
|
||||
final hexCode = hexColor.replaceAll('0x', '');
|
||||
return Color(int.parse('FF$hexCode', radix: 16));
|
||||
} catch (e) {
|
||||
return AppColors.sageGreen; // Fallback to default
|
||||
}
|
||||
}
|
||||
|
||||
class ChristianPeriodTrackerApp extends ConsumerWidget {
|
||||
const ChristianPeriodTrackerApp({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final userProfile = ref.watch(userProfileProvider);
|
||||
|
||||
final ThemeMode themeMode;
|
||||
final Color accentColor;
|
||||
|
||||
if (userProfile != null) {
|
||||
accentColor = _colorFromHex(userProfile.accentColor);
|
||||
switch (userProfile.themeMode) {
|
||||
case AppThemeMode.light:
|
||||
themeMode = ThemeMode.light;
|
||||
break;
|
||||
case AppThemeMode.dark:
|
||||
themeMode = ThemeMode.dark;
|
||||
break;
|
||||
case AppThemeMode.system:
|
||||
default:
|
||||
themeMode = ThemeMode.system;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
// Default theme for initial load or if profile is null
|
||||
themeMode = ThemeMode.system;
|
||||
accentColor = AppColors.sageGreen;
|
||||
}
|
||||
|
||||
return MaterialApp(
|
||||
title: 'Christian Period Tracker',
|
||||
debugShowCheckedModeBanner: false,
|
||||
theme: AppTheme.lightTheme,
|
||||
darkTheme: AppTheme.darkTheme,
|
||||
themeMode: ThemeMode.system,
|
||||
theme: AppTheme.getLightTheme(accentColor),
|
||||
darkTheme: AppTheme.getDarkTheme(accentColor),
|
||||
themeMode: themeMode,
|
||||
home: const SplashScreen(),
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user