only explain api left.

faiz_dev
faizatflutter 1 week ago
parent 8c91b6830a
commit 4ee0d1d3c8

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

Loading…
Cancel
Save