import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_localizations/flutter_localizations.dart'; import 'package:go_router/go_router.dart'; import 'package:kalodings/settings_bloc.dart'; import 'package:kalodings/perdate_widget.dart'; import 'package:kalodings/settings.dart'; import 'package:kalodings/storage/storage.dart'; void main() async { WidgetsFlutterBinding.ensureInitialized(); var storage = await FoodStorage.create(); var kcalLimit = await storage.readLimit(); runApp(MainApp(storage: storage, kcalLimit: kcalLimit)); } class MainApp extends StatelessWidget { final FoodStorage storage; final double kcalLimit; const MainApp({required this.storage, required this.kcalLimit, super.key}); @override Widget build(BuildContext context) { return BlocProvider( create: (context) => SettingsDataBloc(SettingsState(kcalLimit: kcalLimit), storage: storage), child: MaterialApp.router( localizationsDelegates: const [ GlobalMaterialLocalizations.delegate, GlobalWidgetsLocalizations.delegate, GlobalCupertinoLocalizations.delegate, ], supportedLocales: const [ Locale('de'), ], theme: ThemeData.dark(), routerConfig: router, ), ); } } final router = GoRouter(initialLocation: '/day', routes: [ GoRoute( path: '/day', name: 'perDay', builder: (context, state) { DateTime date; if (state.extra == null || state.extra is! DateTime) { date = DateTime.now(); } else { date = state.extra as DateTime; } return PerDateWidget(date: date); }), GoRoute( path: '/settings', name: 'settings', builder: (context, state) { return const SettingsWidget(); }, ) ]);