6177214e-ce7c-49e3-99de-ff9721b26f63 — Commit b515f5d7
Changed files
comwell_key_app/assets/translations/da-DK.json | 4 +- comwell_key_app/assets/translations/en-US.json | 4 +- .../lib/common/components/generic_dialog.dart | 70 +++++++++------ .../components/date_time_picker.dart | 100 ++++++++++++++------- comwell_key_app/lib/utils/address_utils.dart | 4 + 5 files changed, 120 insertions(+), 62 deletions(-)
Diff
diff --git a/comwell_key_app/assets/translations/da-DK.json b/comwell_key_app/assets/translations/da-DK.json
index e575072f..a4ff3683 100644
--- a/comwell_key_app/assets/translations/da-DK.json
+++ b/comwell_key_app/assets/translations/da-DK.json
@@ -316,5 +316,7 @@
"added_to_room": "Tilkøbt på værelse",
"force_update_title": "Opdater for at bruge appen",
"force_update_description": "Der er en nødvendig opdatering til appen, der gør at du skal opdatere for at kunne fortsætte.",
- "force_update_button": "Gå til App Store"
+ "force_update_button": "Gå til App Store",
+ "invalid_birthday": "Ugyldig fødselsdag",
+ "invalid_birthday_description": "Din gemte fødselsdag er ikke tilladt. Vælg en ny dato."
}
\ No newline at end of file
diff --git a/comwell_key_app/assets/translations/en-US.json b/comwell_key_app/assets/translations/en-US.json
index 317c7b2e..d9ceb0b5 100644
--- a/comwell_key_app/assets/translations/en-US.json
+++ b/comwell_key_app/assets/translations/en-US.json
@@ -319,5 +319,7 @@
"added_to_room": "Added to room",
"force_update_title": "Update required",
"force_update_description": "To continue using the app, please update to the latest version.",
- "force_update_button": "Go to App Store"
+ "force_update_button": "Go to App Store",
+ "invalid_birthday": "Invalid birthday",
+ "invalid_birthday_description": "Your saved birthday is not allowed. Please pick a new date."
}
diff --git a/comwell_key_app/lib/common/components/generic_dialog.dart b/comwell_key_app/lib/common/components/generic_dialog.dart
index a4c24ec6..47e83321 100644
--- a/comwell_key_app/lib/common/components/generic_dialog.dart
+++ b/comwell_key_app/lib/common/components/generic_dialog.dart
@@ -24,12 +24,13 @@ class GenericDialog extends StatelessWidget {
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
+ final showCancel = cancelButtonText.isNotEmpty;
return Dialog(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(16),
),
child: SizedBox(
- height: 282,
+ height: 202 + (showCancel ? 80 : 0),
child: Padding(
padding: const EdgeInsets.only(left: 20, right: 20, top: 20),
child: Column(
@@ -49,35 +50,50 @@ class GenericDialog extends StatelessWidget {
const SizedBox(height: 20),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16),
- child: OutlinedButton(
- style: OutlinedButton.styleFrom(
- side: const BorderSide(color: colorDivider),
- minimumSize: const Size(280, 52),
- maximumSize: const Size(280, 52),
- ),
- onPressed: onConfirm,
- child: Text(
- confirmButtonText,
- style: theme.textTheme.headlineSmall?.copyWith(color: confirmButtonTextColor),
- ),
- ),
+ child: showCancel
+ ? OutlinedButton(
+ style: OutlinedButton.styleFrom(
+ side: const BorderSide(color: colorDivider),
+ minimumSize: const Size(280, 52),
+ maximumSize: const Size(280, 52),
+ ),
+ onPressed: onConfirm,
+ child: Text(
+ confirmButtonText,
+ style: theme.textTheme.headlineSmall?.copyWith(color: confirmButtonTextColor),
+ ),
+ )
+ : ElevatedButton(
+ style: theme.elevatedButtonTheme.style?.copyWith(
+ shape: WidgetStatePropertyAll(
+ RoundedRectangleBorder(
+ borderRadius: BorderRadius.circular(25))),
+ ),
+ onPressed: onConfirm,
+ child: Text(
+ confirmButtonText,
+ style: theme.textTheme.headlineSmall?.copyWith(color: Colors.white),
+ ),
+ ),
),
- const SizedBox(height: 5),Padding(
- padding: const EdgeInsets.symmetric(horizontal: 16),
- child: ElevatedButton(
- style: theme.elevatedButtonTheme.style?.copyWith(
- shape: WidgetStatePropertyAll(
- RoundedRectangleBorder(
- borderRadius: BorderRadius.circular(25))),
- ),
- onPressed: onCancel,
- child: Text(
- cancelButtonText,
- style: theme.textTheme.headlineSmall?.copyWith(color: Colors.white)
+ if (showCancel) ...[
+ const SizedBox(height: 5),
+ Padding(
+ padding: const EdgeInsets.symmetric(horizontal: 16),
+ child: ElevatedButton(
+ style: theme.elevatedButtonTheme.style?.copyWith(
+ shape: WidgetStatePropertyAll(
+ RoundedRectangleBorder(
+ borderRadius: BorderRadius.circular(25))),
+ ),
+ onPressed: onCancel,
+ child: Text(
+ cancelButtonText,
+ style: theme.textTheme.headlineSmall?.copyWith(color: Colors.white)
+ ),
),
),
- ),
-
+ ],
const SizedBox(height: 10),
],
),
diff --git a/comwell_key_app/lib/profile_settings/components/date_time_picker.dart b/comwell_key_app/lib/profile_settings/components/date_time_picker.dart
index a9332ec7..1e02a8e8 100644
--- a/comwell_key_app/lib/profile_settings/components/date_time_picker.dart
+++ b/comwell_key_app/lib/profile_settings/components/date_time_picker.dart
@@ -4,6 +4,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_svg/svg.dart';
import 'package:comwell_key_app/profile_settings/cubit/profile_settings_cubit.dart';
+import 'package:comwell_key_app/common/components/generic_dialog.dart';
class DateTimePicker extends StatefulWidget {
final String title;
@@ -23,43 +24,76 @@ class _DatePickerState extends State<DateTimePicker> {
return DateTime(today.year - 18, today.month, today.day);
}
- Future<void> _selectDate(BuildContext context) async => showDatePicker(
- builder: (context, child) {
- final theme = Theme.of(context);
+ Future<void> _selectDate(BuildContext context) async {
+ final maxDate = _maxDate;
+ final initial = widget.initialValue;
+ if (initial.isAfter(maxDate)) {
+ // Show generic dialog to user
+ await showDialog(
+ context: context,
+ builder: (context) => GenericDialog(
+ title: 'invalid_birthday'.tr(),
+ content: 'invalid_birthday_description'.tr(),
+ confirmButtonText: 'OK',
+ confirmButtonTextColor: Colors.white,
+ cancelButtonText: '',
+ onConfirm: () {
+ Navigator.of(context).pop();
+ },
+ onCancel: () {},
+ ),
+ );
+ // Delete the invalid birthday (set to default value)
+ if (context.mounted) {
+ final defaultBirthday = maxDate;
+ setState(() => _selectedDate = null);
+ context.read<ProfileSettingsCubit>().updateBirthDate(defaultBirthday);
+ // Open the date picker after dialog is closed
+ await Future.delayed(Duration(milliseconds: 100));
+ await _showValidDatePicker(context, defaultBirthday, maxDate);
+ }
+ return;
+ }
+ await _showValidDatePicker(context, initial, maxDate);
+ }
- return Theme(
- data: theme.copyWith(
- colorScheme: ColorScheme.light(
- primary: sandColor,
- onPrimary: Colors.white,
- onSurface: colorHeadlineText,
- surface: Colors.white,
- onError: Colors.red,
- ),
- textButtonTheme: TextButtonThemeData(
- style: TextButton.styleFrom(
- foregroundColor: colorHeadlineText,
- overlayColor: sandColor,
- ),
+ Future<void> _showValidDatePicker(BuildContext context, DateTime initial, DateTime maxDate) async {
+ await showDatePicker(
+ builder: (context, child) {
+ final theme = Theme.of(context);
+ return Theme(
+ data: theme.copyWith(
+ colorScheme: ColorScheme.light(
+ primary: sandColor,
+ onPrimary: Colors.white,
+ onSurface: colorHeadlineText,
+ surface: Colors.white,
+ onError: Colors.red,
+ ),
+ textButtonTheme: TextButtonThemeData(
+ style: TextButton.styleFrom(
+ foregroundColor: colorHeadlineText,
+ overlayColor: sandColor,
),
),
- child: child!,
- );
- },
- context: context,
- initialDate: widget.initialValue,
- firstDate: DateTime(0),
- lastDate: _maxDate,
- errorInvalidText: "profile_settings_invalid_date".tr(),
- ).then((DateTime? selected) {
- if (selected != null && selected != _selectedDate) {
- setState(() => _selectedDate = selected);
-
- if (context.mounted) {
- context.read<ProfileSettingsCubit>().updateBirthDate(selected);
- }
+ ),
+ child: child!,
+ );
+ },
+ context: context,
+ initialDate: initial,
+ firstDate: DateTime(0),
+ lastDate: maxDate,
+ errorInvalidText: "profile_settings_invalid_date".tr(),
+ ).then((DateTime? selected) {
+ if (selected != null && selected != _selectedDate) {
+ setState(() => _selectedDate = selected);
+ if (context.mounted) {
+ context.read<ProfileSettingsCubit>().updateBirthDate(selected);
}
- });
+ }
+ });
+ }
@override
Widget build(BuildContext context) {
diff --git a/comwell_key_app/lib/utils/address_utils.dart b/comwell_key_app/lib/utils/address_utils.dart
index aa425fb1..7721cb43 100644
--- a/comwell_key_app/lib/utils/address_utils.dart
+++ b/comwell_key_app/lib/utils/address_utils.dart
@@ -3,6 +3,10 @@
String formatAddress(Address? address) {
final List<String> parts = [];
+ if (address?.street.isNotEmpty ?? false) {
+ parts.add(address?.street ?? '');
+ }
+
if (address?.zipCode.isNotEmpty ?? false) {
parts.add(address?.zipCode ?? '');
}