2024-10-03 21:21:13 +00:00
|
|
|
import 'package:calorimeter/perdate/perdate_pageview.dart';
|
2024-09-06 17:00:25 +00:00
|
|
|
import 'package:calorimeter/storage/storage.dart';
|
|
|
|
import 'package:calorimeter/utils/settings_bloc.dart';
|
|
|
|
import 'package:calorimeter/utils/theme_bloc.dart';
|
2024-05-29 22:58:26 +00:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
2024-06-09 21:25:18 +00:00
|
|
|
import 'package:flutter_localizations/flutter_localizations.dart';
|
2024-10-03 21:21:13 +00:00
|
|
|
import 'package:go_router/go_router.dart';
|
2024-06-09 17:06:10 +00:00
|
|
|
|
|
|
|
void main() async {
|
2024-06-09 18:11:54 +00:00
|
|
|
WidgetsFlutterBinding.ensureInitialized();
|
2024-10-03 21:21:13 +00:00
|
|
|
|
|
|
|
WidgetsFlutterBinding.ensureInitialized();
|
|
|
|
|
2024-09-04 20:47:32 +00:00
|
|
|
var storage = await FoodStorage.create();
|
|
|
|
await storage.buildFoodLookupDatabase();
|
2024-06-11 17:05:42 +00:00
|
|
|
var kcalLimit = await storage.readLimit();
|
2024-06-12 12:42:29 +00:00
|
|
|
var brightness = await storage.readBrightness();
|
2024-05-29 22:58:26 +00:00
|
|
|
|
2024-06-12 12:42:29 +00:00
|
|
|
runApp(
|
|
|
|
MainApp(
|
|
|
|
storage: storage,
|
|
|
|
kcalLimit: kcalLimit,
|
|
|
|
brightness: brightness,
|
|
|
|
),
|
|
|
|
);
|
2024-05-29 22:58:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
class MainApp extends StatelessWidget {
|
2024-09-04 20:47:32 +00:00
|
|
|
final FoodStorage storage;
|
2024-06-11 17:05:42 +00:00
|
|
|
final double kcalLimit;
|
2024-06-12 12:42:29 +00:00
|
|
|
final String brightness;
|
2024-06-11 17:05:42 +00:00
|
|
|
|
2024-06-12 12:42:29 +00:00
|
|
|
const MainApp(
|
|
|
|
{required this.storage,
|
|
|
|
required this.kcalLimit,
|
|
|
|
required this.brightness,
|
|
|
|
super.key});
|
2024-05-29 22:58:26 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2024-09-04 20:47:32 +00:00
|
|
|
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<ThemeDataBloc, ThemeState>(
|
|
|
|
builder: (context, state) {
|
2024-09-05 14:36:35 +00:00
|
|
|
var newBrightness = Brightness.light;
|
2024-09-04 20:47:32 +00:00
|
|
|
if (state.brightness == 'dark') {
|
2024-09-05 14:36:35 +00:00
|
|
|
newBrightness = Brightness.dark;
|
2024-09-04 20:47:32 +00:00
|
|
|
}
|
2024-06-12 12:42:29 +00:00
|
|
|
|
2024-10-03 21:21:13 +00:00
|
|
|
return MaterialApp.router(
|
|
|
|
routerConfig: GoRouter(
|
|
|
|
routes: [
|
|
|
|
GoRoute(
|
|
|
|
path: '/',
|
|
|
|
builder: (context, state) {
|
|
|
|
return PerDatePageview(
|
|
|
|
initalDate: DateTime.now().copyWith(
|
|
|
|
hour: 0,
|
|
|
|
minute: 0,
|
|
|
|
second: 0,
|
|
|
|
millisecond: 0,
|
|
|
|
microsecond: 0,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
2024-09-04 20:47:32 +00:00
|
|
|
localizationsDelegates: const [
|
|
|
|
GlobalMaterialLocalizations.delegate,
|
|
|
|
GlobalWidgetsLocalizations.delegate,
|
|
|
|
GlobalCupertinoLocalizations.delegate,
|
|
|
|
],
|
|
|
|
supportedLocales: const [
|
|
|
|
Locale('de'),
|
|
|
|
],
|
2024-09-05 14:36:35 +00:00
|
|
|
theme: ThemeData(
|
2024-09-06 00:23:47 +00:00
|
|
|
dividerTheme: const DividerThemeData(space: 2),
|
2024-09-05 14:36:35 +00:00
|
|
|
colorScheme: ColorScheme.fromSeed(
|
|
|
|
seedColor: Colors.lightBlue,
|
|
|
|
brightness: newBrightness,
|
|
|
|
),
|
|
|
|
),
|
2024-09-04 20:47:32 +00:00
|
|
|
);
|
|
|
|
},
|
|
|
|
),
|
2024-05-29 22:58:26 +00:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|