calorimeter/lib/main.dart
2024-06-09 20:11:54 +02:00

61 lines
1.5 KiB
Dart

import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:go_router/go_router.dart';
import 'package:kalodings/calendar.dart';
import 'package:kalodings/food_entry_bloc.dart';
import 'package:kalodings/perdate_widget.dart';
import 'package:kalodings/storage/storage.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
var storage = await FoodStorage.create();
runApp(MainApp(storage: storage));
}
class MainApp extends StatelessWidget {
final FoodStorage storage;
const MainApp({required this.storage, super.key});
@override
Widget build(BuildContext context) {
return BlocProvider(
create: (BuildContext context) {
return FoodEntryBloc(FoodEntryState.init(), storage: storage);
},
child: MaterialApp.router(
theme: ThemeData.dark(),
routerConfig: router,
),
);
}
}
final router = GoRouter(routes: [
GoRoute(
path: '/',
name: 'perDayToday',
builder: (context, state) {
return PerDateWidget(DateTime.now());
}),
GoRoute(
path: '/day',
name: 'perDay',
builder: (context, state) {
DateTime day;
if (state.extra == null || state.extra is! DateTime) {
day = DateTime.now();
} else {
day = state.extra as DateTime;
}
return PerDateWidget(day);
}),
GoRoute(
path: '/calendar',
name: 'calendar',
builder: (context, state) {
return const CalendarWidget();
}),
]);