diff --git a/lib/presentation/symptoms_checker/user_info_selection.dart b/lib/presentation/symptoms_checker/user_info_selection.dart index 91f3d36..e5163f5 100644 --- a/lib/presentation/symptoms_checker/user_info_selection.dart +++ b/lib/presentation/symptoms_checker/user_info_selection.dart @@ -3,6 +3,7 @@ import 'package:hmg_patient_app_new/core/app_assets.dart'; import 'package:hmg_patient_app_new/core/app_export.dart'; import 'package:hmg_patient_app_new/core/app_state.dart'; import 'package:hmg_patient_app_new/core/dependencies.dart'; +import 'package:hmg_patient_app_new/core/utils/date_util.dart'; import 'package:hmg_patient_app_new/core/utils/utils.dart'; import 'package:hmg_patient_app_new/extensions/route_extensions.dart'; import 'package:hmg_patient_app_new/extensions/string_extensions.dart'; @@ -17,7 +18,8 @@ class UserInfoSelectionScreen extends StatefulWidget { const UserInfoSelectionScreen({super.key}); @override - State createState() => _UserInfoSelectionScreenState(); + State createState() => + _UserInfoSelectionScreenState(); } class _UserInfoSelectionScreenState extends State { @@ -51,7 +53,7 @@ class _UserInfoSelectionScreenState extends State { if (user.dateofBirth != null && user.dateofBirth!.isNotEmpty) { try { - DateTime dob = DateTime.parse(user.dateofBirth!); + DateTime dob = DateUtil.convertStringToDate(user.dateofBirth!); viewModel.setDateOfBirth(dob); } catch (e) { // If date parsing fails, ignore and let user fill manually @@ -85,19 +87,25 @@ class _UserInfoSelectionScreenState extends State { width: 40.h, margin: EdgeInsets.only(right: 10.h), padding: EdgeInsets.all(8.h), - decoration: RoundedRectangleBorder().toSmoothCornerDecoration(borderRadius: 12.r, color: AppColors.greyColor), - child: Utils.buildSvgWithAssets(icon: leadingIcon, iconColor: iconColor)), + decoration: RoundedRectangleBorder() + .toSmoothCornerDecoration( + borderRadius: 12.r, color: AppColors.greyColor), + child: Utils.buildSvgWithAssets( + icon: leadingIcon, iconColor: iconColor)), Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ title.toText16(weight: FontWeight.w500), - subTitle.toText14(color: AppColors.primaryRedColor, weight: FontWeight.w500), + subTitle.toText14( + color: AppColors.primaryRedColor, + weight: FontWeight.w500), ], ), ], ), ), - Utils.buildSvgWithAssets(icon: trailingIcon, height: 24.h, width: 24.h), + Utils.buildSvgWithAssets( + icon: trailingIcon, height: 24.h, width: 24.h), ], ), ); @@ -114,8 +122,27 @@ class _UserInfoSelectionScreenState extends State { AppState appState = getIt.get(); String name = ""; + int? userAgeFromDOB; + if (appState.isAuthenticated) { - name = "${appState.getAuthenticatedUser()!.firstName!} ${appState.getAuthenticatedUser()!.lastName!} "; + final user = appState.getAuthenticatedUser(); + name = "${user!.firstName!} ${user.lastName!} "; + + // Calculate age from authenticated user's DOB if available + if (user.dateofBirth != null && user.dateofBirth!.isNotEmpty) { + try { + DateTime dob = DateUtil.convertStringToDate(user.dateofBirth!); + final now = DateTime.now(); + int age = now.year - dob.year; + if (now.month < dob.month || + (now.month == dob.month && now.day < dob.day)) { + age--; + } + userAgeFromDOB = age; + } catch (e) { + // If date parsing fails, ignore + } + } } else { name = "Guest"; } @@ -132,12 +159,15 @@ class _UserInfoSelectionScreenState extends State { // Get display values String genderText = viewModel.selectedGender ?? "Not set"; - // Show age calculated from DOB, not the DOB itself - String ageText = viewModel.selectedAge != null ? "${viewModel.selectedAge} Years" : "Not set"; - String heightText = - viewModel.selectedHeight != null ? "${viewModel.selectedHeight!.round()} ${viewModel.isHeightCm ? 'cm' : 'ft'}" : "Not set"; - String weightText = - viewModel.selectedWeight != null ? "${viewModel.selectedWeight!.round()} ${viewModel.isWeightKg ? 'kg' : 'lbs'}" : "Not set"; + // Show age calculated from DOB (prefer viewModel's age, fallback to calculated from user's DOB) + int? displayAge = viewModel.selectedAge ?? userAgeFromDOB; + String ageText = displayAge != null ? "$displayAge Years" : "Not set"; + String heightText = viewModel.selectedHeight != null + ? "${viewModel.selectedHeight!.round()} ${viewModel.isHeightCm ? 'cm' : 'ft'}" + : "Not set"; + String weightText = viewModel.selectedWeight != null + ? "${viewModel.selectedWeight!.round()} ${viewModel.isWeightKg ? 'kg' : 'lbs'}" + : "Not set"; return Column( children: [ @@ -150,11 +180,17 @@ class _UserInfoSelectionScreenState extends State { children: [ Container( width: double.infinity, - decoration: RoundedRectangleBorder().toSmoothCornerDecoration(color: AppColors.whiteColor, borderRadius: 24.r), - padding: EdgeInsets.symmetric(vertical: 24.h, horizontal: 16.w), + decoration: RoundedRectangleBorder() + .toSmoothCornerDecoration( + color: AppColors.whiteColor, + borderRadius: 24.r), + padding: EdgeInsets.symmetric( + vertical: 24.h, horizontal: 16.w), child: Column( children: [ - "Hello $name, Is your information up to date?".needTranslation.toText18( + "Hello $name, Is your information up to date?" + .needTranslation + .toText18( weight: FontWeight.w600, color: AppColors.textColor, ), @@ -165,8 +201,10 @@ class _UserInfoSelectionScreenState extends State { title: "Gender".needTranslation, subTitle: genderText, onTap: () { - viewModel.setUserInfoPage(0, isSinglePageEdit: true); - context.navigateWithName(AppRoutes.userInfoFlowManager); + viewModel.setUserInfoPage(0, + isSinglePageEdit: true); + context.navigateWithName( + AppRoutes.userInfoFlowManager); }, trailingIcon: AppAssets.edit_icon, ), @@ -178,8 +216,10 @@ class _UserInfoSelectionScreenState extends State { subTitle: ageText, iconColor: AppColors.greyTextColor, onTap: () { - viewModel.setUserInfoPage(1, isSinglePageEdit: true); - context.navigateWithName(AppRoutes.userInfoFlowManager); + viewModel.setUserInfoPage(1, + isSinglePageEdit: true); + context.navigateWithName( + AppRoutes.userInfoFlowManager); }, trailingIcon: AppAssets.edit_icon, ), @@ -190,8 +230,10 @@ class _UserInfoSelectionScreenState extends State { title: "Height".needTranslation, subTitle: heightText, onTap: () { - viewModel.setUserInfoPage(2, isSinglePageEdit: true); - context.navigateWithName(AppRoutes.userInfoFlowManager); + viewModel.setUserInfoPage(2, + isSinglePageEdit: true); + context.navigateWithName( + AppRoutes.userInfoFlowManager); }, trailingIcon: AppAssets.edit_icon, ), @@ -202,8 +244,10 @@ class _UserInfoSelectionScreenState extends State { title: "Weight".needTranslation, subTitle: weightText, onTap: () { - viewModel.setUserInfoPage(3, isSinglePageEdit: true); - context.navigateWithName(AppRoutes.userInfoFlowManager); + viewModel.setUserInfoPage(3, + isSinglePageEdit: true); + context.navigateWithName( + AppRoutes.userInfoFlowManager); }, trailingIcon: AppAssets.edit_icon, ), @@ -225,7 +269,8 @@ class _UserInfoSelectionScreenState extends State { Widget _buildBottomCard(BuildContext context, bool hasEmptyFields) { return Container( - decoration: RoundedRectangleBorder().toSmoothCornerDecoration(color: AppColors.whiteColor, borderRadius: 24.r), + decoration: RoundedRectangleBorder().toSmoothCornerDecoration( + color: AppColors.whiteColor, borderRadius: 24.r), child: SafeArea( top: false, child: Column( @@ -240,10 +285,13 @@ class _UserInfoSelectionScreenState extends State { icon: AppAssets.edit_icon, iconColor: AppColors.primaryRedColor, onPressed: () { - context.read().setUserInfoPage(0, isSinglePageEdit: false); + context + .read() + .setUserInfoPage(0, isSinglePageEdit: false); context.navigateWithName(AppRoutes.userInfoFlowManager); }, - backgroundColor: AppColors.primaryRedColor.withValues(alpha: 0.11), + backgroundColor: + AppColors.primaryRedColor.withValues(alpha: 0.11), borderColor: Colors.transparent, textColor: AppColors.primaryRedColor, fontSize: 16.f, @@ -254,13 +302,22 @@ class _UserInfoSelectionScreenState extends State { child: CustomButton( text: "Yes, It is".needTranslation, icon: AppAssets.tickIcon, - iconColor: hasEmptyFields ? AppColors.greyTextColor : AppColors.whiteColor, + iconColor: hasEmptyFields + ? AppColors.greyTextColor + : AppColors.whiteColor, onPressed: hasEmptyFields ? () {} // Empty function for disabled state - : () => context.navigateWithName(AppRoutes.organSelectorPage), - backgroundColor: hasEmptyFields ? AppColors.greyLightColor : AppColors.primaryRedColor, - borderColor: hasEmptyFields ? AppColors.greyLightColor : AppColors.primaryRedColor, - textColor: hasEmptyFields ? AppColors.greyTextColor : AppColors.whiteColor, + : () => context + .navigateWithName(AppRoutes.organSelectorPage), + backgroundColor: hasEmptyFields + ? AppColors.greyLightColor + : AppColors.primaryRedColor, + borderColor: hasEmptyFields + ? AppColors.greyLightColor + : AppColors.primaryRedColor, + textColor: hasEmptyFields + ? AppColors.greyTextColor + : AppColors.whiteColor, fontSize: 16.f, ), ),