From 7b0947f93fdc6fcb0714f7129fd7afaa2e88b624 Mon Sep 17 00:00:00 2001 From: Marco Date: Sun, 9 Jun 2024 23:25:18 +0200 Subject: [PATCH] many many many changes --- lib/app_drawer.dart | 8 -- lib/calendar.dart | 20 ---- lib/enter_food_widget.dart | 3 - lib/main.dart | 30 +++--- lib/perdate_widget.dart | 40 ++++---- linux/flutter/generated_plugin_registrant.cc | 4 + linux/flutter/generated_plugins.cmake | 1 + macos/Flutter/GeneratedPluginRegistrant.swift | 4 + pubspec.lock | 93 +++++++++++++++++++ pubspec.yaml | 4 + .../flutter/generated_plugin_registrant.cc | 3 + windows/flutter/generated_plugins.cmake | 1 + 12 files changed, 146 insertions(+), 65 deletions(-) delete mode 100644 lib/calendar.dart diff --git a/lib/app_drawer.dart b/lib/app_drawer.dart index 8e64e3d..1ede28c 100644 --- a/lib/app_drawer.dart +++ b/lib/app_drawer.dart @@ -1,5 +1,4 @@ import 'package:flutter/material.dart'; -import 'package:go_router/go_router.dart'; class AppDrawer extends StatelessWidget { const AppDrawer({ @@ -25,13 +24,6 @@ class AppDrawer extends StatelessWidget { ), title: const Text('MenĂ¼')), ), - ListTile( - trailing: const Icon(Icons.today), - title: const Text('Kalender'), - onTap: () { - context.goNamed('calendar'); - }, - ), ListTile( title: const Text('Einstellungen'), trailing: const Icon(Icons.settings), diff --git a/lib/calendar.dart b/lib/calendar.dart deleted file mode 100644 index 84323b0..0000000 --- a/lib/calendar.dart +++ /dev/null @@ -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(), - ), - ); - } -} diff --git a/lib/enter_food_widget.dart b/lib/enter_food_widget.dart index 3a63737..b7857ad 100644 --- a/lib/enter_food_widget.dart +++ b/lib/enter_food_widget.dart @@ -1,7 +1,4 @@ -import 'dart:developer'; - import 'package:flutter/material.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:kalodings/food_entry_bloc.dart'; import 'package:kalodings/row_with_spacers_widget.dart'; diff --git a/lib/main.dart b/lib/main.dart index 71a0025..13c0649 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,7 +1,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:flutter_localizations/flutter_localizations.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'; @@ -24,6 +24,14 @@ class MainApp extends StatelessWidget { return FoodEntryBloc(FoodEntryState.init(), storage: storage); }, child: MaterialApp.router( + localizationsDelegates: const [ + GlobalMaterialLocalizations.delegate, + GlobalWidgetsLocalizations.delegate, + GlobalCupertinoLocalizations.delegate, + ], + supportedLocales: const [ + Locale('de'), + ], theme: ThemeData.dark(), routerConfig: router, ), @@ -36,25 +44,25 @@ final router = GoRouter(routes: [ path: '/', name: 'perDayToday', builder: (context, state) { + context + .read() + .add(PageChangedEvent(changedToDate: DateTime.now())); return PerDateWidget(DateTime.now()); }), GoRoute( path: '/day', name: 'perDay', builder: (context, state) { - DateTime day; + DateTime date; if (state.extra == null || state.extra is! DateTime) { - day = DateTime.now(); + date = DateTime.now(); } else { - day = state.extra as DateTime; + date = state.extra as DateTime; } + context + .read() + .add(PageChangedEvent(changedToDate: date)); - return PerDateWidget(day); - }), - GoRoute( - path: '/calendar', - name: 'calendar', - builder: (context, state) { - return const CalendarWidget(); + return PerDateWidget(date); }), ]); diff --git a/lib/perdate_widget.dart b/lib/perdate_widget.dart index 3268b64..9b43454 100644 --- a/lib/perdate_widget.dart +++ b/lib/perdate_widget.dart @@ -7,29 +7,15 @@ import 'package:kalodings/food_entry_bloc.dart'; import 'package:kalodings/food_entry_widget.dart'; import 'package:kalodings/sum_widget.dart'; -class PerDateWidget extends StatefulWidget { +class PerDateWidget extends StatelessWidget { final DateTime date; const PerDateWidget(this.date, {super.key}); - @override - State createState() => _PerDateWidgetState(); -} - -class _PerDateWidgetState extends State { - @override - void initState() { - super.initState(); - - context - .read() - .add(PageChangedEvent(changedToDate: widget.date)); - } - @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( - title: Text(widget.date.toString()), + title: Text(date.toString()), ), drawer: const AppDrawer(), body: BlocBuilder( @@ -45,7 +31,7 @@ class _PerDateWidgetState extends State { onAdd: (context, entry) { context .read() - .add(FoodEntryEvent(entry: entry, date: widget.date)); + .add(FoodEntryEvent(entry: entry, date: date)); }, ); } @@ -55,8 +41,7 @@ class _PerDateWidgetState extends State { onDelete: (callbackContext) { callbackContext.read().add( FoodDeletionEvent( - entryID: state.foodEntries[index].id, - date: widget.date), + entryID: state.foodEntries[index].id, date: date), ); }, ); @@ -65,12 +50,21 @@ class _PerDateWidgetState extends State { }, ), floatingActionButton: FloatingActionButton( - onPressed: () { - context.goNamed('calendar'); + onPressed: () async { + 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)), ); } - - void deleteCallback(BuildContext context, String idToDelete, DateTime date) {} } diff --git a/linux/flutter/generated_plugin_registrant.cc b/linux/flutter/generated_plugin_registrant.cc index e71a16d..10e19fe 100644 --- a/linux/flutter/generated_plugin_registrant.cc +++ b/linux/flutter/generated_plugin_registrant.cc @@ -6,6 +6,10 @@ #include "generated_plugin_registrant.h" +#include 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); } diff --git a/linux/flutter/generated_plugins.cmake b/linux/flutter/generated_plugins.cmake index 2e1de87..2284757 100644 --- a/linux/flutter/generated_plugins.cmake +++ b/linux/flutter/generated_plugins.cmake @@ -3,6 +3,7 @@ # list(APPEND FLUTTER_PLUGIN_LIST + flutter_localization ) list(APPEND FLUTTER_FFI_PLUGIN_LIST diff --git a/macos/Flutter/GeneratedPluginRegistrant.swift b/macos/Flutter/GeneratedPluginRegistrant.swift index e777c67..34745dc 100644 --- a/macos/Flutter/GeneratedPluginRegistrant.swift +++ b/macos/Flutter/GeneratedPluginRegistrant.swift @@ -5,8 +5,12 @@ import FlutterMacOS import Foundation +import flutter_localization import path_provider_foundation +import shared_preferences_foundation func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { + FlutterLocalizationPlugin.register(with: registry.registrar(forPlugin: "FlutterLocalizationPlugin")) PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin")) + SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin")) } diff --git a/pubspec.lock b/pubspec.lock index 77477ff..bbfe2a1 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -73,6 +73,14 @@ packages: url: "https://pub.dev" source: hosted version: "2.1.2" + file: + dependency: transitive + description: + name: file + sha256: "5fc22d7c25582e38ad9a8515372cd9a93834027aacf1801cf01164dac0ffa08c" + url: "https://pub.dev" + source: hosted + version: "7.0.0" fixnum: dependency: transitive description: @@ -102,6 +110,19 @@ packages: url: "https://pub.dev" source: hosted 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: dependency: "direct dev" description: flutter @@ -120,6 +141,14 @@ packages: url: "https://pub.dev" source: hosted 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: dependency: transitive description: @@ -280,6 +309,62 @@ packages: url: "https://pub.dev" source: hosted 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: dependency: transitive description: flutter @@ -373,6 +458,14 @@ packages: url: "https://pub.dev" source: hosted version: "14.2.2" + web: + dependency: transitive + description: + name: web + sha256: "97da13628db363c635202ad97068d47c5b8aa555808e7a9411963c533b449b27" + url: "https://pub.dev" + source: hosted + version: "0.5.1" win32: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index d07c22e..6563a44 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -10,7 +10,11 @@ dependencies: flutter: sdk: flutter flutter_bloc: ^8.1.5 + flutter_localization: ^0.2.0 + flutter_localizations: + sdk: flutter go_router: ^14.1.4 + intl: any path_provider: ^2.1.3 quiver: ^3.2.1 uuid: ^4.4.0 diff --git a/windows/flutter/generated_plugin_registrant.cc b/windows/flutter/generated_plugin_registrant.cc index 8b6d468..9f5b3e5 100644 --- a/windows/flutter/generated_plugin_registrant.cc +++ b/windows/flutter/generated_plugin_registrant.cc @@ -6,6 +6,9 @@ #include "generated_plugin_registrant.h" +#include void RegisterPlugins(flutter::PluginRegistry* registry) { + FlutterLocalizationPluginCApiRegisterWithRegistrar( + registry->GetRegistrarForPlugin("FlutterLocalizationPluginCApi")); } diff --git a/windows/flutter/generated_plugins.cmake b/windows/flutter/generated_plugins.cmake index b93c4c3..f040a63 100644 --- a/windows/flutter/generated_plugins.cmake +++ b/windows/flutter/generated_plugins.cmake @@ -3,6 +3,7 @@ # list(APPEND FLUTTER_PLUGIN_LIST + flutter_localization ) list(APPEND FLUTTER_FFI_PLUGIN_LIST