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)),
); );
} }
void deleteCallback(BuildContext context, String idToDelete, DateTime date) {}
} }

View File

@ -6,6 +6,10 @@
#include "generated_plugin_registrant.h" #include "generated_plugin_registrant.h"
#include <flutter_localization/flutter_localization_plugin.h>
void fl_register_plugins(FlPluginRegistry* registry) { void fl_register_plugins(FlPluginRegistry* registry) {
g_autoptr(FlPluginRegistrar) flutter_localization_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "FlutterLocalizationPlugin");
flutter_localization_plugin_register_with_registrar(flutter_localization_registrar);
} }

View File

@ -3,6 +3,7 @@
# #
list(APPEND FLUTTER_PLUGIN_LIST list(APPEND FLUTTER_PLUGIN_LIST
flutter_localization
) )
list(APPEND FLUTTER_FFI_PLUGIN_LIST list(APPEND FLUTTER_FFI_PLUGIN_LIST

View File

@ -5,8 +5,12 @@
import FlutterMacOS import FlutterMacOS
import Foundation import Foundation
import flutter_localization
import path_provider_foundation import path_provider_foundation
import shared_preferences_foundation
func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
FlutterLocalizationPlugin.register(with: registry.registrar(forPlugin: "FlutterLocalizationPlugin"))
PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin")) PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin"))
SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin"))
} }

View File

@ -73,6 +73,14 @@ packages:
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "2.1.2" version: "2.1.2"
file:
dependency: transitive
description:
name: file
sha256: "5fc22d7c25582e38ad9a8515372cd9a93834027aacf1801cf01164dac0ffa08c"
url: "https://pub.dev"
source: hosted
version: "7.0.0"
fixnum: fixnum:
dependency: transitive dependency: transitive
description: description:
@ -102,6 +110,19 @@ packages:
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "4.0.0" version: "4.0.0"
flutter_localization:
dependency: "direct main"
description:
name: flutter_localization
sha256: faaeb1eba307473032e2c2af737f36ced61fc98735608410d0a6d9c231b50912
url: "https://pub.dev"
source: hosted
version: "0.2.0"
flutter_localizations:
dependency: "direct main"
description: flutter
source: sdk
version: "0.0.0"
flutter_test: flutter_test:
dependency: "direct dev" dependency: "direct dev"
description: flutter description: flutter
@ -120,6 +141,14 @@ packages:
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "14.1.4" version: "14.1.4"
intl:
dependency: "direct main"
description:
name: intl
sha256: d6f56758b7d3014a48af9701c085700aac781a92a87a62b1333b46d8879661cf
url: "https://pub.dev"
source: hosted
version: "0.19.0"
leak_tracker: leak_tracker:
dependency: transitive dependency: transitive
description: description:
@ -280,6 +309,62 @@ packages:
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "3.2.1" version: "3.2.1"
shared_preferences:
dependency: transitive
description:
name: shared_preferences
sha256: d3bbe5553a986e83980916ded2f0b435ef2e1893dfaa29d5a7a790d0eca12180
url: "https://pub.dev"
source: hosted
version: "2.2.3"
shared_preferences_android:
dependency: transitive
description:
name: shared_preferences_android
sha256: "93d0ec9dd902d85f326068e6a899487d1f65ffcd5798721a95330b26c8131577"
url: "https://pub.dev"
source: hosted
version: "2.2.3"
shared_preferences_foundation:
dependency: transitive
description:
name: shared_preferences_foundation
sha256: "0a8a893bf4fd1152f93fec03a415d11c27c74454d96e2318a7ac38dd18683ab7"
url: "https://pub.dev"
source: hosted
version: "2.4.0"
shared_preferences_linux:
dependency: transitive
description:
name: shared_preferences_linux
sha256: "9f2cbcf46d4270ea8be39fa156d86379077c8a5228d9dfdb1164ae0bb93f1faa"
url: "https://pub.dev"
source: hosted
version: "2.3.2"
shared_preferences_platform_interface:
dependency: transitive
description:
name: shared_preferences_platform_interface
sha256: "22e2ecac9419b4246d7c22bfbbda589e3acf5c0351137d87dd2939d984d37c3b"
url: "https://pub.dev"
source: hosted
version: "2.3.2"
shared_preferences_web:
dependency: transitive
description:
name: shared_preferences_web
sha256: "9aee1089b36bd2aafe06582b7d7817fd317ef05fc30e6ba14bff247d0933042a"
url: "https://pub.dev"
source: hosted
version: "2.3.0"
shared_preferences_windows:
dependency: transitive
description:
name: shared_preferences_windows
sha256: "841ad54f3c8381c480d0c9b508b89a34036f512482c407e6df7a9c4aa2ef8f59"
url: "https://pub.dev"
source: hosted
version: "2.3.2"
sky_engine: sky_engine:
dependency: transitive dependency: transitive
description: flutter description: flutter
@ -373,6 +458,14 @@ packages:
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "14.2.2" version: "14.2.2"
web:
dependency: transitive
description:
name: web
sha256: "97da13628db363c635202ad97068d47c5b8aa555808e7a9411963c533b449b27"
url: "https://pub.dev"
source: hosted
version: "0.5.1"
win32: win32:
dependency: transitive dependency: transitive
description: description:

View File

@ -10,7 +10,11 @@ dependencies:
flutter: flutter:
sdk: flutter sdk: flutter
flutter_bloc: ^8.1.5 flutter_bloc: ^8.1.5
flutter_localization: ^0.2.0
flutter_localizations:
sdk: flutter
go_router: ^14.1.4 go_router: ^14.1.4
intl: any
path_provider: ^2.1.3 path_provider: ^2.1.3
quiver: ^3.2.1 quiver: ^3.2.1
uuid: ^4.4.0 uuid: ^4.4.0

View File

@ -6,6 +6,9 @@
#include "generated_plugin_registrant.h" #include "generated_plugin_registrant.h"
#include <flutter_localization/flutter_localization_plugin_c_api.h>
void RegisterPlugins(flutter::PluginRegistry* registry) { void RegisterPlugins(flutter::PluginRegistry* registry) {
FlutterLocalizationPluginCApiRegisterWithRegistrar(
registry->GetRegistrarForPlugin("FlutterLocalizationPluginCApi"));
} }

View File

@ -3,6 +3,7 @@
# #
list(APPEND FLUTTER_PLUGIN_LIST list(APPEND FLUTTER_PLUGIN_LIST
flutter_localization
) )
list(APPEND FLUTTER_FFI_PLUGIN_LIST list(APPEND FLUTTER_FFI_PLUGIN_LIST