calorimeter/lib/main.dart

67 lines
1.8 KiB
Dart
Raw Normal View History

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-06-09 12:42:17 +00:00
import 'package:go_router/go_router.dart';
import 'package:kalodings/settings_bloc.dart';
2024-06-09 17:06:10 +00:00
import 'package:kalodings/perdate_widget.dart';
import 'package:kalodings/settings.dart';
2024-06-09 17:06:10 +00:00
import 'package:kalodings/storage/storage.dart';
void main() async {
2024-06-09 18:11:54 +00:00
WidgetsFlutterBinding.ensureInitialized();
2024-06-09 17:06:10 +00:00
var storage = await FoodStorage.create();
var kcalLimit = await storage.readLimit();
runApp(MainApp(storage: storage, kcalLimit: kcalLimit));
}
class MainApp extends StatelessWidget {
2024-06-09 17:06:10 +00:00
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),
2024-06-09 12:42:17 +00:00
child: MaterialApp.router(
2024-06-09 21:25:18 +00:00
localizationsDelegates: const [
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
],
supportedLocales: const [
Locale('de'),
],
2024-06-09 12:42:17 +00:00
theme: ThemeData.dark(),
routerConfig: router,
),
);
}
}
2024-06-09 12:42:17 +00:00
final router = GoRouter(initialLocation: '/day', routes: [
2024-06-09 12:42:17 +00:00
GoRoute(
path: '/day',
name: 'perDay',
builder: (context, state) {
2024-06-09 21:25:18 +00:00
DateTime date;
2024-06-09 12:42:17 +00:00
if (state.extra == null || state.extra is! DateTime) {
2024-06-09 21:25:18 +00:00
date = DateTime.now();
2024-06-09 12:42:17 +00:00
} else {
2024-06-09 21:25:18 +00:00
date = state.extra as DateTime;
2024-06-09 12:42:17 +00:00
}
return PerDateWidget(date: date);
2024-06-09 12:42:17 +00:00
}),
GoRoute(
path: '/settings',
name: 'settings',
builder: (context, state) {
return const SettingsWidget();
},
)
2024-06-09 12:42:17 +00:00
]);