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_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<UserInfoSelectionScreen> createState() => _UserInfoSelectionScreenState();
State<UserInfoSelectionScreen> createState() =>
_UserInfoSelectionScreenState();
}
class _UserInfoSelectionScreenState extends State<UserInfoSelectionScreen> {
@ -51,7 +53,7 @@ class _UserInfoSelectionScreenState extends State<UserInfoSelectionScreen> {
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<UserInfoSelectionScreen> {
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<UserInfoSelectionScreen> {
AppState appState = getIt.get<AppState>();
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<UserInfoSelectionScreen> {
// 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<UserInfoSelectionScreen> {
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<UserInfoSelectionScreen> {
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<UserInfoSelectionScreen> {
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<UserInfoSelectionScreen> {
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<UserInfoSelectionScreen> {
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<UserInfoSelectionScreen> {
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<UserInfoSelectionScreen> {
icon: AppAssets.edit_icon,
iconColor: AppColors.primaryRedColor,
onPressed: () {
context.read<SymptomsCheckerViewModel>().setUserInfoPage(0, isSinglePageEdit: false);
context
.read<SymptomsCheckerViewModel>()
.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<UserInfoSelectionScreen> {
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,
),
),

Loading…
Cancel
Save