From ff5664530734655085f17ad25024799395f0661e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakob=20K=C3=B6rber?= <56073945+jakobkoerber@users.noreply.github.com> Date: Mon, 1 Apr 2024 00:29:10 +0200 Subject: [PATCH] Fix User Interface Errors (#234) --- lib/base/localization/app_de.arb | 11 ++++- lib/base/localization/app_en.arb | 11 ++++- lib/base/util/places_util.dart | 18 +++++++- .../views/confirm_view.dart | 12 +++-- .../model/cafeterias/dish_label.dart | 22 ---------- .../model/cafeterias/dish_label.g.dart | 19 -------- .../viewModels/cafeterias_viewmodel.dart | 5 +-- .../homeWidget/cafeteria_widget_view.dart | 2 +- lib/placesComponent/views/map_widget.dart | 44 +++---------------- .../views/settings_view.dart | 2 +- pubspec.lock | 14 +++--- 11 files changed, 62 insertions(+), 98 deletions(-) delete mode 100644 lib/placesComponent/model/cafeterias/dish_label.dart delete mode 100644 lib/placesComponent/model/cafeterias/dish_label.g.dart diff --git a/lib/base/localization/app_de.arb b/lib/base/localization/app_de.arb index d66393b9..e196188c 100644 --- a/lib/base/localization/app_de.arb +++ b/lib/base/localization/app_de.arb @@ -20,7 +20,6 @@ "contactMore":"Kontakt & Mehr", "tokenPermissions":"Berechtigungen für Token", "permissionChangePossibleInTUMonline":"Du kannst deine Berechtigungen in TUMOnline ändern", - "logout":"Abmelden", "login":"Anmelden", "notLoggedIn":"Nicht angemeldet", "welcomeToTheApp":"Willkommen in der\n TUM Campus App", @@ -252,6 +251,16 @@ } }, "closed":"Geschlossen", + "closedOn":"{day} geschlossen", + "@closedOn":{ + "description":"Day", + "placeholders":{ + "day":{ + "type":"String", + "example":"Montag" + } + } + }, "closedToday":"Heute geschlossen", "submitFeedback":"Feedback einreichen", "yourEmailAddress":"Deine E-Mail-Adresse", diff --git a/lib/base/localization/app_en.arb b/lib/base/localization/app_en.arb index 2c38e9d3..065f1313 100644 --- a/lib/base/localization/app_en.arb +++ b/lib/base/localization/app_en.arb @@ -20,7 +20,6 @@ "contactMore":"Contact & More", "tokenPermissions":"Token Permissions", "permissionChangePossibleInTUMonline":"You can change your permissions on TUMOnline", - "logout":"Logout", "login":"Login", "notLoggedIn":"Not Logged In", "welcomeToTheApp":"Welcome to the TUM Campus App", @@ -252,6 +251,16 @@ } }, "closed":"Closed", + "closedOn":"Closed on {day}", + "@closedOn":{ + "description":"Day", + "placeholders":{ + "day":{ + "type":"String", + "example":"Monday" + } + } + }, "closedToday":"Closed Today", "submitFeedback":"Submit Feedback", "yourEmailAddress":"Your Email Address", diff --git a/lib/base/util/places_util.dart b/lib/base/util/places_util.dart index bbfcb14b..33eceee3 100644 --- a/lib/base/util/places_util.dart +++ b/lib/base/util/places_util.dart @@ -1,7 +1,9 @@ import 'package:campus_flutter/base/extensions/context.dart'; +import 'package:campus_flutter/base/extensions/date_time.dart'; import 'package:campus_flutter/base/util/string_parser.dart'; import 'package:campus_flutter/placesComponent/model/cafeterias/opening_hours.dart'; import 'package:flutter/material.dart'; +import 'package:intl/intl.dart'; class PlacesUtil { static Widget? openingHours( @@ -9,14 +11,26 @@ class PlacesUtil { DateTime? dateTime, BuildContext context, ) { - if (openingHours != null && dateTime != null) { + if (openingHours != null && !openingHours.$1 && dateTime != null) { + return Padding( + padding: EdgeInsets.only(left: context.padding), + child: Text( + dateTime.isAtSameDay(DateTime.now()) + ? context.localizations.closedToday + : context.localizations.closedOn( + DateFormat.EEEE(context.localizations.localeName) + .format(dateTime), + ), + ), + ); + } else if (openingHours?.$2 != null && dateTime != null) { final dayString = StringParser.getDayString(dateTime, context); return Padding( padding: EdgeInsets.only(left: context.padding), child: Text( context.localizations.open( dayString, - openingHours.$2!.start, + openingHours!.$2!.start, openingHours.$2!.end, ), ), diff --git a/lib/onboardingComponent/views/confirm_view.dart b/lib/onboardingComponent/views/confirm_view.dart index a1d71599..ca7d5d4a 100644 --- a/lib/onboardingComponent/views/confirm_view.dart +++ b/lib/onboardingComponent/views/confirm_view.dart @@ -62,7 +62,9 @@ class _ConfirmViewState extends ConsumerState { value.compareTo(const Duration(seconds: 9, milliseconds: 2)) == -1) { setState(() { - currentText = 1; + if (mounted) { + currentText = 1; + } }); } else if (value .compareTo(const Duration(seconds: 9, milliseconds: 3)) == @@ -70,13 +72,17 @@ class _ConfirmViewState extends ConsumerState { value.compareTo(const Duration(seconds: 16, milliseconds: 24)) == -1) { setState(() { - currentText = 2; + if (mounted) { + currentText = 2; + } }); } else if (value.compareTo(Duration.zero) == 1 && value.compareTo(const Duration(seconds: 5, milliseconds: 16)) == -1) { setState(() { - currentText = 0; + if (mounted) { + currentText = 0; + } }); } } diff --git a/lib/placesComponent/model/cafeterias/dish_label.dart b/lib/placesComponent/model/cafeterias/dish_label.dart deleted file mode 100644 index e0a206ea..00000000 --- a/lib/placesComponent/model/cafeterias/dish_label.dart +++ /dev/null @@ -1,22 +0,0 @@ -import 'package:json_annotation/json_annotation.dart'; - -part 'dish_label.g.dart'; - -@JsonSerializable() -class DishLabel { - @JsonKey(name: "enum_name") - final String name; - final Map text; - final String abbreviation; - - DishLabel({ - required this.name, - required this.text, - required this.abbreviation, - }); - - factory DishLabel.fromJson(Map json) => - _$DishLabelFromJson(json); - - Map toJson() => _$DishLabelToJson(this); -} diff --git a/lib/placesComponent/model/cafeterias/dish_label.g.dart b/lib/placesComponent/model/cafeterias/dish_label.g.dart deleted file mode 100644 index 04ce6657..00000000 --- a/lib/placesComponent/model/cafeterias/dish_label.g.dart +++ /dev/null @@ -1,19 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of 'dish_label.dart'; - -// ************************************************************************** -// JsonSerializableGenerator -// ************************************************************************** - -DishLabel _$DishLabelFromJson(Map json) => DishLabel( - name: json['enum_name'] as String, - text: Map.from(json['text'] as Map), - abbreviation: json['abbreviation'] as String, - ); - -Map _$DishLabelToJson(DishLabel instance) => { - 'enum_name': instance.name, - 'text': instance.text, - 'abbreviation': instance.abbreviation, - }; diff --git a/lib/placesComponent/viewModels/cafeterias_viewmodel.dart b/lib/placesComponent/viewModels/cafeterias_viewmodel.dart index 8ec652ea..6c6a827e 100644 --- a/lib/placesComponent/viewModels/cafeterias_viewmodel.dart +++ b/lib/placesComponent/viewModels/cafeterias_viewmodel.dart @@ -1,7 +1,6 @@ import 'package:campus_flutter/base/enums/campus.dart'; import 'package:campus_flutter/base/enums/user_preference.dart'; import 'package:campus_flutter/base/extensions/context.dart'; -import 'package:campus_flutter/base/extensions/campus_exception.dart'; import 'package:campus_flutter/base/routing/routes.dart'; import 'package:campus_flutter/base/services/location_service.dart'; import 'package:campus_flutter/main.dart'; @@ -217,9 +216,7 @@ class CafeteriasViewModel { ) { return MealPlanService.getCafeteriaMenu(forcedRefresh, cafeteria).then( (response) => response.$2, - onError: (error) => Future>.error( - CampusException("Unable to fetch meal plan"), - ), + onError: (error) => error, ); } diff --git a/lib/placesComponent/views/homeWidget/cafeteria_widget_view.dart b/lib/placesComponent/views/homeWidget/cafeteria_widget_view.dart index 4beea856..930dde07 100644 --- a/lib/placesComponent/views/homeWidget/cafeteria_widget_view.dart +++ b/lib/placesComponent/views/homeWidget/cafeteria_widget_view.dart @@ -73,7 +73,7 @@ class _CafeteriaWidgetViewState extends ConsumerState { ), subtitle: PlacesUtil.openingHours( snapshot.data?.$1.openingHoursForDate(snapshot.data?.$2?.date), - snapshot.data?.$2!.date, + snapshot.data?.$2?.date, context, ), child: _dynamicContent(snapshot), diff --git a/lib/placesComponent/views/map_widget.dart b/lib/placesComponent/views/map_widget.dart index 7879209e..f02f5355 100644 --- a/lib/placesComponent/views/map_widget.dart +++ b/lib/placesComponent/views/map_widget.dart @@ -96,47 +96,12 @@ class MapWidget extends ConsumerStatefulWidget { ConsumerState createState() => _MapWidgetState(); } -class _MapWidgetState extends ConsumerState - with WidgetsBindingObserver { +class _MapWidgetState extends ConsumerState { final Completer _controller = Completer(); bool isMapVisible = false; - @override - void initState() { - super.initState(); - WidgetsBinding.instance.addObserver(this); - _setMapStyle(); - } - - Future _setMapStyle({bool platformChanged = false}) async { - final controller = await _controller.future; - setBrightness(controller, platformChanged); - } - - void setBrightness(GoogleMapController controller, bool platformChanged) { - final brightness = Theme.of(context).brightness; - if (brightness == (platformChanged ? Brightness.light : Brightness.dark)) { - controller.setMapStyle(getIt.get().darkTheme); - } else { - controller.setMapStyle(getIt.get().lightTheme); - } - } - - @override - void didChangePlatformBrightness() { - setState(() { - _setMapStyle(platformChanged: true); - }); - } - - @override - void dispose() { - WidgetsBinding.instance.removeObserver(this); - super.dispose(); - } - @override Widget build(BuildContext context) { return Padding( @@ -167,6 +132,9 @@ class _MapWidgetState extends ConsumerState opacity: isMapVisible ? 1.0 : 0.01, duration: const Duration(milliseconds: 200), child: GoogleMap( + style: Theme.of(context).brightness == Brightness.light + ? getIt.get().lightTheme + : getIt.get().darkTheme, mapType: MapType.normal, padding: widget.controlPadding ?? EdgeInsets.zero, initialCameraPosition: CameraPosition( @@ -192,7 +160,9 @@ class _MapWidgetState extends ConsumerState Future.delayed( const Duration(milliseconds: 250), () => setState(() { - isMapVisible = true; + if (mounted) { + isMapVisible = true; + } }), ); }, diff --git a/lib/settingsComponent/views/settings_view.dart b/lib/settingsComponent/views/settings_view.dart index 8aed8e94..b2883252 100644 --- a/lib/settingsComponent/views/settings_view.dart +++ b/lib/settingsComponent/views/settings_view.dart @@ -77,7 +77,7 @@ class SettingsView extends ConsumerWidget { textAlign: TextAlign.center, ) : Text( - context.localizations.logout, + context.localizations.reset, style: Theme.of(context).textTheme.bodyMedium?.copyWith( color: Colors.red, fontWeight: FontWeight.w500, diff --git a/pubspec.lock b/pubspec.lock index 0b852bee..938648ba 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -125,10 +125,10 @@ packages: dependency: "direct dev" description: name: build_runner - sha256: "581bacf68f89ec8792f5e5a0b2c4decd1c948e97ce659dc783688c8a88fbec21" + sha256: "3ac61a79bfb6f6cc11f693591063a7f19a7af628dc52f141743edac5c16e8c22" url: "https://pub.dev" source: hosted - version: "2.4.8" + version: "2.4.9" build_runner_core: dependency: transitive description: @@ -569,10 +569,10 @@ packages: dependency: "direct main" description: name: go_router - sha256: "7ecb2f391edbca5473db591b48555a8912dde60edd0fb3013bd6743033b2d3f8" + sha256: "5ed2687bc961f33a752017ccaa7edead3e5601b28b6376a5901bf24728556b85" url: "https://pub.dev" source: hosted - version: "13.2.1" + version: "13.2.2" google_identity_services_web: dependency: transitive description: @@ -610,7 +610,7 @@ packages: description: path: "packages/google_maps_flutter/google_maps_flutter_ios" ref: main - resolved-ref: c13a2045826d0465e4014949c11582460072fc87 + resolved-ref: "76ec0f6a67acefeff16dba1dcbd3ec7323ec7883" url: "https://github.com/jakobkoerber/packages.git" source: git version: "2.5.2" @@ -1672,10 +1672,10 @@ packages: dependency: transitive description: name: win32 - sha256: "8cb58b45c47dcb42ab3651533626161d6b67a2921917d8d429791f76972b3480" + sha256: "0a989dc7ca2bb51eac91e8fd00851297cfffd641aa7538b165c62637ca0eaa4a" url: "https://pub.dev" source: hosted - version: "5.3.0" + version: "5.4.0" win32_registry: dependency: transitive description: