calorimeter/lib/main.dart

61 lines
1.5 KiB
Dart
Raw Normal View History

import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
2024-06-09 12:42:17 +00:00
import 'package:go_router/go_router.dart';
import 'package:kalodings/calendar.dart';
import 'package:kalodings/food_entry_bloc.dart';
2024-06-09 17:06:10 +00:00
import 'package:kalodings/perdate_widget.dart';
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();
2024-06-09 17:06:10 +00:00
runApp(MainApp(storage: storage));
}
class MainApp extends StatelessWidget {
2024-06-09 17:06:10 +00:00
final FoodStorage storage;
const MainApp({required this.storage, super.key});
@override
Widget build(BuildContext context) {
return BlocProvider(
create: (BuildContext context) {
2024-06-09 17:06:10 +00:00
return FoodEntryBloc(FoodEntryState.init(), storage: storage);
},
2024-06-09 12:42:17 +00:00
child: MaterialApp.router(
theme: ThemeData.dark(),
routerConfig: router,
),
);
}
}
2024-06-09 12:42:17 +00:00
final router = GoRouter(routes: [
GoRoute(
path: '/',
name: 'perDayToday',
builder: (context, state) {
2024-06-09 17:06:10 +00:00
return PerDateWidget(DateTime.now());
2024-06-09 12:42:17 +00:00
}),
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;
}
2024-06-09 17:06:10 +00:00
return PerDateWidget(day);
2024-06-09 12:42:17 +00:00
}),
GoRoute(
path: '/calendar',
name: 'calendar',
builder: (context, state) {
2024-06-09 17:06:10 +00:00
return const CalendarWidget();
2024-06-09 12:42:17 +00:00
}),
]);