import 'package:calorimeter/storage/storage.dart'; import 'package:calorimeter/utils/router.dart'; import 'package:calorimeter/utils/settings_bloc.dart'; import 'package:calorimeter/utils/theme_bloc.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_localizations/flutter_localizations.dart'; void main() async { WidgetsFlutterBinding.ensureInitialized(); var storage = await FoodStorage.create(); await storage.buildFoodLookupDatabase(); var kcalLimit = await storage.readLimit(); var brightness = await storage.readBrightness(); runApp( MainApp( storage: storage, kcalLimit: kcalLimit, brightness: brightness, ), ); } class MainApp extends StatelessWidget { final FoodStorage storage; final double kcalLimit; final String brightness; const MainApp( {required this.storage, required this.kcalLimit, required this.brightness, super.key}); @override Widget build(BuildContext context) { return SafeArea( child: MultiBlocProvider( providers: [ BlocProvider( create: (context) => SettingsDataBloc( SettingsState(kcalLimit: kcalLimit), storage: storage), ), BlocProvider( create: (context) => ThemeDataBloc( ThemeState(brightness: brightness), storage: storage), ), ], child: BlocBuilder( builder: (context, state) { var newBrightness = Brightness.light; if (state.brightness == 'dark') { newBrightness = Brightness.dark; } return MaterialApp.router( localizationsDelegates: const [ GlobalMaterialLocalizations.delegate, GlobalWidgetsLocalizations.delegate, GlobalCupertinoLocalizations.delegate, ], supportedLocales: const [ Locale('de'), ], theme: ThemeData( dividerTheme: const DividerThemeData(space: 2), colorScheme: ColorScheme.fromSeed( seedColor: Colors.lightBlue, brightness: newBrightness, ), ), routerConfig: getRouterConfig(), ); }, ), ), ); } }