many many many changes

This commit is contained in:
Marco 2024-06-09 23:25:18 +02:00
parent 2a707e51e4
commit 7b0947f93f
12 changed files with 146 additions and 65 deletions

View File

@ -1,5 +1,4 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
class AppDrawer extends StatelessWidget { class AppDrawer extends StatelessWidget {
const AppDrawer({ const AppDrawer({
@ -25,13 +24,6 @@ class AppDrawer extends StatelessWidget {
), ),
title: const Text('Menü')), title: const Text('Menü')),
), ),
ListTile(
trailing: const Icon(Icons.today),
title: const Text('Kalender'),
onTap: () {
context.goNamed('calendar');
},
),
ListTile( ListTile(
title: const Text('Einstellungen'), title: const Text('Einstellungen'),
trailing: const Icon(Icons.settings), trailing: const Icon(Icons.settings),

View File

@ -1,20 +0,0 @@
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
class CalendarWidget extends StatelessWidget {
const CalendarWidget({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
body: CalendarDatePicker(
onDateChanged: (value) {
context.goNamed('perDay', extra: value);
},
initialDate: DateTime.now(),
firstDate: DateTime.now().subtract(const Duration(days: 30)),
lastDate: DateTime.now(),
),
);
}
}

View File

@ -1,7 +1,4 @@
import 'dart:developer';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:kalodings/food_entry_bloc.dart'; import 'package:kalodings/food_entry_bloc.dart';
import 'package:kalodings/row_with_spacers_widget.dart'; import 'package:kalodings/row_with_spacers_widget.dart';

View File

@ -1,7 +1,7 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:go_router/go_router.dart'; import 'package:go_router/go_router.dart';
import 'package:kalodings/calendar.dart';
import 'package:kalodings/food_entry_bloc.dart'; import 'package:kalodings/food_entry_bloc.dart';
import 'package:kalodings/perdate_widget.dart'; import 'package:kalodings/perdate_widget.dart';
import 'package:kalodings/storage/storage.dart'; import 'package:kalodings/storage/storage.dart';
@ -24,6 +24,14 @@ class MainApp extends StatelessWidget {
return FoodEntryBloc(FoodEntryState.init(), storage: storage); return FoodEntryBloc(FoodEntryState.init(), storage: storage);
}, },
child: MaterialApp.router( child: MaterialApp.router(
localizationsDelegates: const [
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
],
supportedLocales: const [
Locale('de'),
],
theme: ThemeData.dark(), theme: ThemeData.dark(),
routerConfig: router, routerConfig: router,
), ),
@ -36,25 +44,25 @@ final router = GoRouter(routes: [
path: '/', path: '/',
name: 'perDayToday', name: 'perDayToday',
builder: (context, state) { builder: (context, state) {
context
.read<FoodEntryBloc>()
.add(PageChangedEvent(changedToDate: DateTime.now()));
return PerDateWidget(DateTime.now()); return PerDateWidget(DateTime.now());
}), }),
GoRoute( GoRoute(
path: '/day', path: '/day',
name: 'perDay', name: 'perDay',
builder: (context, state) { builder: (context, state) {
DateTime day; DateTime date;
if (state.extra == null || state.extra is! DateTime) { if (state.extra == null || state.extra is! DateTime) {
day = DateTime.now(); date = DateTime.now();
} else { } else {
day = state.extra as DateTime; date = state.extra as DateTime;
} }
context
.read<FoodEntryBloc>()
.add(PageChangedEvent(changedToDate: date));
return PerDateWidget(day); return PerDateWidget(date);
}),
GoRoute(
path: '/calendar',
name: 'calendar',
builder: (context, state) {
return const CalendarWidget();
}), }),
]); ]);

View File

@ -7,29 +7,15 @@ import 'package:kalodings/food_entry_bloc.dart';
import 'package:kalodings/food_entry_widget.dart'; import 'package:kalodings/food_entry_widget.dart';
import 'package:kalodings/sum_widget.dart'; import 'package:kalodings/sum_widget.dart';
class PerDateWidget extends StatefulWidget { class PerDateWidget extends StatelessWidget {
final DateTime date; final DateTime date;
const PerDateWidget(this.date, {super.key}); const PerDateWidget(this.date, {super.key});
@override
State<PerDateWidget> createState() => _PerDateWidgetState();
}
class _PerDateWidgetState extends State<PerDateWidget> {
@override
void initState() {
super.initState();
context
.read<FoodEntryBloc>()
.add(PageChangedEvent(changedToDate: widget.date));
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
appBar: AppBar( appBar: AppBar(
title: Text(widget.date.toString()), title: Text(date.toString()),
), ),
drawer: const AppDrawer(), drawer: const AppDrawer(),
body: BlocBuilder<FoodEntryBloc, FoodEntryState>( body: BlocBuilder<FoodEntryBloc, FoodEntryState>(
@ -45,7 +31,7 @@ class _PerDateWidgetState extends State<PerDateWidget> {
onAdd: (context, entry) { onAdd: (context, entry) {
context context
.read<FoodEntryBloc>() .read<FoodEntryBloc>()
.add(FoodEntryEvent(entry: entry, date: widget.date)); .add(FoodEntryEvent(entry: entry, date: date));
}, },
); );
} }
@ -55,8 +41,7 @@ class _PerDateWidgetState extends State<PerDateWidget> {
onDelete: (callbackContext) { onDelete: (callbackContext) {
callbackContext.read<FoodEntryBloc>().add( callbackContext.read<FoodEntryBloc>().add(
FoodDeletionEvent( FoodDeletionEvent(
entryID: state.foodEntries[index].id, entryID: state.foodEntries[index].id, date: date),
date: widget.date),
); );
}, },
); );
@ -65,12 +50,21 @@ class _PerDateWidgetState extends State<PerDateWidget> {
}, },
), ),
floatingActionButton: FloatingActionButton( floatingActionButton: FloatingActionButton(
onPressed: () { onPressed: () async {
context.goNamed('calendar'); var router = GoRouter.of(context);
var datePicked = await showDatePicker(
locale: const Locale('de'),
context: context,
initialDate: date,
currentDate: DateTime.now(),
firstDate:
DateTime.now().subtract(const Duration(days: 365 * 10)),
lastDate: DateTime.now(),
);
router.goNamed('perDay', extra: datePicked);
}, },
child: const Icon(Icons.today)), child: const Icon(Icons.today)),
); );
} }