calorimeter/lib/main.dart

58 lines
1.3 KiB
Dart
Raw Normal View History

2024-06-09 12:42:17 +00:00
// ignore_for_file: prefer_const_constructors
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';
import 'package:kalodings/perday_widget.dart';
void main() {
runApp(const MainApp());
}
class MainApp extends StatelessWidget {
const MainApp({super.key});
@override
Widget build(BuildContext context) {
return BlocProvider(
create: (BuildContext context) {
return FoodEntryBloc(FoodEntryState.init());
},
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) {
return PerDay(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 PerDay(day);
}),
GoRoute(
path: '/calendar',
name: 'calendar',
builder: (context, state) {
return CalendarWidget();
}),
]);