6177214e-ce7c-49e3-99de-ff9721b26f63 — Commit a87a98d4

AuthorEdmir Suljic<esu@dwarf.dk>
Date2025-05-02 16:44:04 +0200
Fixed bug on address change in profile settings. Moved birthdate from profile settings to comwell club

Changed files

.../lib/my_booking/my_booking_page.dart            |  6 +--
 .../comwell_club_signup_bottom_sheet.dart          | 35 ++++++++++------
 comwell_key_app/lib/profile/profile_page.dart      |  4 +-
 .../lib/profile/profile_repository.dart            | 47 ++++++++++++----------
 .../components/date_time_picker.dart               |  2 +-
 .../cubit/profile_settings_cubit.dart              | 20 +++++++--
 .../profile_settings/profile_settings_page.dart    | 29 +++++--------
 comwell_key_app/lib/utils/share_button_utils.dart  |  4 +-
 8 files changed, 82 insertions(+), 65 deletions(-)

Diff

diff --git a/comwell_key_app/lib/my_booking/my_booking_page.dart b/comwell_key_app/lib/my_booking/my_booking_page.dart
index 659c7e8e..2a0c655d 100644
--- a/comwell_key_app/lib/my_booking/my_booking_page.dart
+++ b/comwell_key_app/lib/my_booking/my_booking_page.dart
@@ -230,7 +230,7 @@ class MyBookingPage extends StatelessWidget {
),
),
const SizedBox(height: 16),
- Row(
+ Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Column(
@@ -288,7 +288,7 @@ class MyBookingPage extends StatelessWidget {
children: [
Text(
'my_balance'.tr(),
- style: theme.textTheme.bodyMedium?.copyWith(
+ style: theme.textTheme.bodyLarge?.copyWith(
color: Colors.white,
),
),
@@ -296,7 +296,7 @@ class MyBookingPage extends StatelessWidget {
children: [
Text(
'${booking.totalCharge} kr',
- style: theme.textTheme.bodyMedium?.copyWith(
+ style: theme.textTheme.bodyLarge?.copyWith(
color: Colors.white,
),
),
diff --git a/comwell_key_app/lib/profile/components/comwell_club_signup_bottom_sheet.dart b/comwell_key_app/lib/profile/components/comwell_club_signup_bottom_sheet.dart
index 633c5cef..ea4d33b7 100644
--- a/comwell_key_app/lib/profile/components/comwell_club_signup_bottom_sheet.dart
+++ b/comwell_key_app/lib/profile/components/comwell_club_signup_bottom_sheet.dart
@@ -54,7 +54,7 @@ class _ComwellClubSignupBottomSheetState
topRight: Radius.circular(24),
),
),
- height: MediaQuery.of(context).copyWith().size.height * 0.6,
+ height: MediaQuery.of(context).copyWith().size.height * 0.7,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
@@ -146,6 +146,14 @@ class _ComwellClubSignupBottomSheetState
),
),
),
+ const SizedBox(height: 16),
+ Padding(
+ padding: const EdgeInsets.symmetric(horizontal: 16),
+ child: DateTimePicker(
+ title: "profile_settings_birthday".tr(),
+ initialValue: widget.user.birthDate,
+ ),
+ ),
const SizedBox(height: 10),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16),
@@ -179,7 +187,8 @@ class _ComwellClubSignupBottomSheetState
text: "tos_accept_link".tr(),
recognizer: TapGestureRecognizer()
..onTap = () {
- launchUrl(Uri.parse('https://comwell.com/club/club-regler'));
+ launchUrl(Uri.parse(
+ 'https://comwell.com/club/club-regler'));
},
style: TextStyle(
fontSize:
@@ -227,8 +236,8 @@ class _ComwellClubSignupBottomSheetState
text: "read_more".tr(),
recognizer: TapGestureRecognizer()
..onTap = () {
- launchUrl(Uri.parse('https://comwell.com/club/club-permission'));
-
+ launchUrl(Uri.parse(
+ 'https://comwell.com/club/club-permission'));
},
style: TextStyle(
fontSize: theme.textTheme.bodySmall!.fontSize,
@@ -261,14 +270,16 @@ class _ComwellClubSignupBottomSheetState
minimumSize: const Size(double.infinity, 52),
),
onPressed: () async {
- final response = cubit.state.isToSAccepted && _selectedGender.isNotEmpty
- ? await cubit.onComwellClubSignupClick(widget.user.copyWith(
- gender: _selectedGender,
- address: Address(
- zipCode: _postNumberController.text,
- street: '',
- city: '',
- country: '')))
+ final response = cubit.state.isToSAccepted &&
+ _selectedGender.isNotEmpty
+ ? await cubit.onComwellClubSignupClick(widget.user
+ .copyWith(
+ gender: _selectedGender,
+ address: Address(
+ zipCode: _postNumberController.text,
+ street: '',
+ city: '',
+ country: '')))
: null;
if (response != null) {
diff --git a/comwell_key_app/lib/profile/profile_page.dart b/comwell_key_app/lib/profile/profile_page.dart
index bdb836d9..c7b40d8b 100644
--- a/comwell_key_app/lib/profile/profile_page.dart
+++ b/comwell_key_app/lib/profile/profile_page.dart
@@ -47,7 +47,7 @@ class ProfilePage extends StatelessWidget {
Widget _buildProfilePage(ProfileCubit cubit, BuildContext context) {
final user = cubit.state.user;
- final isActive = cubit.state.user!.clubLevel != '';
+ final isActive = cubit.state.user!.clubLevel != 'L1';
return SafeArea(
child: Column(
@@ -70,7 +70,7 @@ class ProfilePage extends StatelessWidget {
children: [
ComwellCard(
content: getCardContent(context, cubit, isActive),
- backgroundColor: isActive ? sandColor : earthColor[10]!),
+ backgroundColor: isActive ? sandColor : sandColor[10]!),
],
),
),
diff --git a/comwell_key_app/lib/profile/profile_repository.dart b/comwell_key_app/lib/profile/profile_repository.dart
index 4659a595..7893f3c0 100644
--- a/comwell_key_app/lib/profile/profile_repository.dart
+++ b/comwell_key_app/lib/profile/profile_repository.dart
@@ -27,27 +27,6 @@ class ProfileRepository {
await authenticationRepository.logOut();
}
- Future<User> fetchProfileSettings() async {
- try {
- final response = await api.fetchProfileSettings();
- final data = response.data as Json;
- final userDto = UserDto.fromJson(data);
- final user = userDto.toUser();
-
- try {
- await db.userDAO.saveUser(userDto);
- } catch (dbError) {
- print("Database error while saving user: ${dbError.toString()}");
- // Continue execution even if database save fails
- }
-
- return user;
- } catch (e) {
- print("Error fetching profile settings: ${e.toString()}");
- rethrow;
- }
- }
-
Future<User> signupForComwellClub(User user) async {
final response = await api.signupForComwellClub(user);
final data = response.data as Json;
@@ -56,4 +35,30 @@ class ProfileRepository {
await db.userDAO.saveUser(userDto);
return updatedUser;
}
+
+ Future<User> fetchProfileSettings() async {
+ try {
+ final user = await db.userDAO.getUser();
+ return user;
+ } catch (e) {
+ try {
+ final response = await api.fetchProfileSettings();
+ final data = response.data as Json;
+ final userDto = UserDto.fromJson(data);
+ final user = userDto.toUser();
+
+ try {
+ await db.userDAO.saveUser(userDto);
+ } catch (dbError) {
+ print("Database error while saving user: ${dbError.toString()}");
+ // Continue execution even if database save fails
+ }
+
+ return user;
+ } catch (e) {
+ print("Error fetching profile settings: ${e.toString()}");
+ rethrow;
+ }
+ }
+ }
}
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 872efb39..e4cbb1e3 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
@@ -28,7 +28,7 @@ class _DatePickerState extends State<DateTimePicker> {
Future<void> _selectDate(BuildContext context) async => showDatePicker(
context: context,
initialDate: widget.initialValue,
- firstDate: DateTime(1930),
+ firstDate: DateTime(0),
lastDate: _maxDate,
errorInvalidText: "profile_settings_invalid_date".tr(),
).then((DateTime? selected) {
diff --git a/comwell_key_app/lib/profile_settings/cubit/profile_settings_cubit.dart b/comwell_key_app/lib/profile_settings/cubit/profile_settings_cubit.dart
index 5a53c07e..f039e864 100644
--- a/comwell_key_app/lib/profile_settings/cubit/profile_settings_cubit.dart
+++ b/comwell_key_app/lib/profile_settings/cubit/profile_settings_cubit.dart
@@ -7,6 +7,7 @@ import 'package:comwell_key_app/profile_settings/repostiory/profile_settings_rep
import 'package:comwell_key_app/tracking/comwell_tracking.dart';
import 'package:comwell_key_app/utils/locator.dart';
import 'package:equatable/equatable.dart';
+import 'package:flutter/material.dart';
part 'profile_settings_state.dart';
@@ -14,17 +15,26 @@ class ProfileSettingsCubit extends Cubit<ProfileSettingsState> {
final ProfileRepository profileRepository;
final ProfileSettingsRepository profileSettingsRepository;
final AuthenticationRepository authenticationRepository;
+ final TextEditingController firstNameController = TextEditingController();
+ final TextEditingController lastNameController = TextEditingController();
+ final TextEditingController phoneNumberController = TextEditingController();
+
ProfileSettingsCubit(
{required this.profileRepository,
required this.profileSettingsRepository,
- required this.authenticationRepository})
+ required this.authenticationRepository,
+ firstNameController,
+ lastNameController,
+ phoneNumberController})
: super(const ProfileSettingsState.initial());
void init() async {
emit(const ProfileSettingsState(isLoading: true, user: null, error: null));
try {
- // Fetch profile settings
final user = await profileRepository.fetchProfileSettings();
+ firstNameController.text = user.firstName;
+ lastNameController.text = user.lastName;
+ phoneNumberController.text = user.phoneNumber;
emit(ProfileSettingsState(isLoading: false, user: user, error: null));
} catch (e) {
emit(ProfileSettingsState(isLoading: false, user: null, error: Error()));
@@ -32,7 +42,7 @@ class ProfileSettingsCubit extends Cubit<ProfileSettingsState> {
}
void deleteProfile() async {
- try {
+ try {
await profileSettingsRepository.deleteProfile();
locator<ComwellTracking>().trackEvent('delete_profile');
await authenticationRepository.logOut();
@@ -44,6 +54,8 @@ class ProfileSettingsCubit extends Cubit<ProfileSettingsState> {
}
}
+
+ //TODO: Add this to the comwell signup page when backend is ready
void updateBirthDate(DateTime birthDate) {
if (state.user != null) {
final updatedUser = state.user!.copyWith(birthDate: birthDate);
@@ -51,7 +63,7 @@ class ProfileSettingsCubit extends Cubit<ProfileSettingsState> {
}
}
- void updateAddress(User user, Address address) {
+ void updateAddress(Address address) {
print("update address: ${address}");
final updatedUser = state.user!.copyWith(address: address);
diff --git a/comwell_key_app/lib/profile_settings/profile_settings_page.dart b/comwell_key_app/lib/profile_settings/profile_settings_page.dart
index 7992e5bc..b0779df1 100644
--- a/comwell_key_app/lib/profile_settings/profile_settings_page.dart
+++ b/comwell_key_app/lib/profile_settings/profile_settings_page.dart
@@ -20,10 +20,8 @@ import 'package:flutter_svg/flutter_svg.dart';
import 'package:modal_bottom_sheet/modal_bottom_sheet.dart';
class ProfileSettingsPage extends StatelessWidget {
- final TextEditingController _firstNameController = TextEditingController();
- final TextEditingController _lastNameController = TextEditingController();
- final TextEditingController _phoneNumberController = TextEditingController();
- ProfileSettingsPage({super.key});
+
+ const ProfileSettingsPage({super.key});
@override
Widget build(BuildContext context) {
@@ -57,9 +55,6 @@ class ProfileSettingsPage extends StatelessWidget {
Widget _buildProfileSettingsPage(
ThemeData theme, ProfileSettingsState state, BuildContext context) {
- _firstNameController.text = state.user!.firstName;
- _lastNameController.text = state.user!.lastName;
- _phoneNumberController.text = state.user!.phoneNumber;
final cubit = context.read<ProfileSettingsCubit>();
return Scaffold(
@@ -84,9 +79,8 @@ class ProfileSettingsPage extends StatelessWidget {
fieldName: "profile_settings_firstname".tr(),
initialValue: state.user!.firstName,
readOnly: false,
- controller: _firstNameController,
+ controller: cubit.firstNameController,
onSubmitted: (value) {
- print("onSubmitted: $value");
cubit.updateFirstName(value);
}),
const SizedBox(height: 8),
@@ -94,7 +88,7 @@ class ProfileSettingsPage extends StatelessWidget {
fieldName: "profile_settings_lastname".tr(),
initialValue: state.user!.lastName,
readOnly: false,
- controller: _lastNameController,
+ controller: cubit.lastNameController,
onSubmitted: (value) {
cubit.updateLastName(value);
}),
@@ -109,7 +103,7 @@ class ProfileSettingsPage extends StatelessWidget {
IntlPhoneField(
title: "profile_settings_phone".tr(),
phoneNumber: state.user!.phoneNumber,
- controller: _phoneNumberController,
+ controller: cubit.phoneNumberController,
readOnly: false,
onSubmitted: (value) {
cubit.updatePhoneNumber(value);
@@ -130,18 +124,13 @@ class ProfileSettingsPage extends StatelessWidget {
AddressBottomSheet(user: state.user!));
if (response is Address) {
- cubit.updateAddress(state.user!, response);
+ cubit.updateAddress(response);
} else {
print("Not an address $response");
}
},
showTitle: true),
const SizedBox(height: 8),
- DateTimePicker(
- title: "profile_settings_birthday".tr(),
- initialValue: state.user!.birthDate,
- ),
- const SizedBox(height: 8),
TextFieldWithTrailingIcon(
title: "profile_settings_edit_password".tr(),
text: "profile_settings_edit_password".tr(),
@@ -157,10 +146,10 @@ class ProfileSettingsPage extends StatelessWidget {
cubit.updateProfile(
User(
id: state.user!.id,
- firstName: _firstNameController.text,
- lastName: _lastNameController.text,
+ firstName: cubit.firstNameController.text,
+ lastName: cubit.lastNameController.text,
email: state.user!.email,
- phoneNumber: _phoneNumberController.text,
+ phoneNumber: cubit.phoneNumberController.text,
birthDate: state.user!.birthDate,
address: state.user!.address,
shopperReference: state.user!.shopperReference,
diff --git a/comwell_key_app/lib/utils/share_button_utils.dart b/comwell_key_app/lib/utils/share_button_utils.dart
index 98448109..0e7c3bfc 100644
--- a/comwell_key_app/lib/utils/share_button_utils.dart
+++ b/comwell_key_app/lib/utils/share_button_utils.dart
@@ -2,9 +2,9 @@ import 'package:comwell_key_app/overview/models/guest.dart';
Iterable<String> generateInitials(Iterable<Guest> guests) {
return guests
- .map((guest) => guest.name.split(' ').map((name) => name[0]).join(''));
+ .map((guest) => guest.name.split(' ').map((name) => name[0].toUpperCase()).join(''));
}
String generateInitialsString(String name) {
- return name.split(' ').map((name) => name[0]).join('');
+ return name.split(' ').map((name) => name[0].toUpperCase()).join('');
}