Complete UserInfo Selection Module

pull/113/head
faizatflutter 1 month ago
parent cf26e71645
commit fbe124f6ee

@ -38,6 +38,7 @@ class SymptomsCheckerViewModel extends ChangeNotifier {
// User Info Flow State
int _userInfoCurrentPage = 0;
bool _isSinglePageEditMode = false; // Track if editing single page or full flow
String? _selectedGender;
DateTime? _dateOfBirth;
int? _selectedAge;
@ -53,6 +54,8 @@ class SymptomsCheckerViewModel extends ChangeNotifier {
// User Info Getters
int get userInfoCurrentPage => _userInfoCurrentPage;
bool get isSinglePageEditMode => _isSinglePageEditMode;
String? get selectedGender => _selectedGender;
DateTime? get dateOfBirth => _dateOfBirth;
@ -275,6 +278,7 @@ class SymptomsCheckerViewModel extends ChangeNotifier {
_tooltipOrganId = null;
// Reset user info flow
_userInfoCurrentPage = 0;
_isSinglePageEditMode = false;
_selectedGender = null;
_dateOfBirth = null;
_selectedAge = null;
@ -288,8 +292,15 @@ class SymptomsCheckerViewModel extends ChangeNotifier {
// User Info Flow Methods
/// Set current page in user info flow
void setUserInfoPage(int page) {
void setUserInfoPage(int page, {bool isSinglePageEdit = false}) {
_userInfoCurrentPage = page;
_isSinglePageEditMode = isSinglePageEdit;
notifyListeners();
}
/// Set single page edit mode
void setSinglePageEditMode(bool isSingleEdit) {
_isSinglePageEditMode = isSingleEdit;
notifyListeners();
}

@ -165,7 +165,7 @@ class _UserInfoSelectionScreenState extends State<UserInfoSelectionScreen> {
title: "Gender".needTranslation,
subTitle: genderText,
onTap: () {
viewModel.setUserInfoPage(0);
viewModel.setUserInfoPage(0, isSinglePageEdit: true);
context.navigateWithName(AppRoutes.userInfoFlowManager);
},
trailingIcon: AppAssets.edit_icon,
@ -178,7 +178,7 @@ class _UserInfoSelectionScreenState extends State<UserInfoSelectionScreen> {
subTitle: ageText,
iconColor: AppColors.greyTextColor,
onTap: () {
viewModel.setUserInfoPage(1);
viewModel.setUserInfoPage(1, isSinglePageEdit: true);
context.navigateWithName(AppRoutes.userInfoFlowManager);
},
trailingIcon: AppAssets.edit_icon,
@ -190,7 +190,7 @@ class _UserInfoSelectionScreenState extends State<UserInfoSelectionScreen> {
title: "Height".needTranslation,
subTitle: heightText,
onTap: () {
viewModel.setUserInfoPage(2);
viewModel.setUserInfoPage(2, isSinglePageEdit: true);
context.navigateWithName(AppRoutes.userInfoFlowManager);
},
trailingIcon: AppAssets.edit_icon,
@ -202,7 +202,7 @@ class _UserInfoSelectionScreenState extends State<UserInfoSelectionScreen> {
title: "Weight".needTranslation,
subTitle: weightText,
onTap: () {
viewModel.setUserInfoPage(3);
viewModel.setUserInfoPage(3, isSinglePageEdit: true);
context.navigateWithName(AppRoutes.userInfoFlowManager);
},
trailingIcon: AppAssets.edit_icon,
@ -240,7 +240,7 @@ class _UserInfoSelectionScreenState extends State<UserInfoSelectionScreen> {
icon: AppAssets.edit_icon,
iconColor: AppColors.primaryRedColor,
onPressed: () {
context.read<SymptomsCheckerViewModel>().setUserInfoPage(0);
context.read<SymptomsCheckerViewModel>().setUserInfoPage(0, isSinglePageEdit: false);
context.navigateWithName(AppRoutes.userInfoFlowManager);
},
backgroundColor: AppColors.primaryRedColor.withValues(alpha: 0.11),
@ -254,7 +254,7 @@ class _UserInfoSelectionScreenState extends State<UserInfoSelectionScreen> {
child: CustomButton(
text: "Yes, It is".needTranslation,
icon: AppAssets.tickIcon,
iconColor: AppColors.whiteColor,
iconColor: hasEmptyFields ? AppColors.greyTextColor : AppColors.whiteColor,
onPressed: hasEmptyFields
? () {} // Empty function for disabled state
: () => context.navigateWithName(AppRoutes.organSelectorPage),

@ -24,7 +24,7 @@ class UserInfoFlowManager extends StatefulWidget {
}
class _UserInfoFlowManagerState extends State<UserInfoFlowManager> {
final PageController _pageController = PageController();
late PageController _pageController;
late SymptomsCheckerViewModel _viewModel;
// Page titles
@ -39,6 +39,8 @@ class _UserInfoFlowManagerState extends State<UserInfoFlowManager> {
void initState() {
super.initState();
_viewModel = context.read<SymptomsCheckerViewModel>();
// Initialize PageController with the current page from ViewModel
_pageController = PageController(initialPage: _viewModel.userInfoCurrentPage);
}
@override
@ -48,6 +50,13 @@ class _UserInfoFlowManagerState extends State<UserInfoFlowManager> {
}
void _onNext() {
// If in single page edit mode, just save and go back
if (_viewModel.isSinglePageEditMode) {
context.pop();
return;
}
// Otherwise, continue with normal flow
if (_viewModel.userInfoCurrentPage < 3) {
_viewModel.nextUserInfoPage();
_pageController.animateToPage(
@ -162,6 +171,8 @@ class _UserInfoFlowManagerState extends State<UserInfoFlowManager> {
return Consumer<SymptomsCheckerViewModel>(builder: (BuildContext context, viewModel, child) {
bool isLastPage = viewModel.isUserInfoLastPage;
bool isFirstPage = viewModel.isUserInfoFirstPage;
bool isSingleEdit = viewModel.isSinglePageEditMode;
return Container(
decoration: BoxDecoration(
color: AppColors.whiteColor,
@ -170,33 +181,44 @@ class _UserInfoFlowManagerState extends State<UserInfoFlowManager> {
padding: EdgeInsets.only(left: 24.w, right: 24.w, top: 16.h),
child: SafeArea(
top: false,
child: Row(
children: [
if (!isFirstPage) ...[
Expanded(
child: CustomButton(
text: "Previous".needTranslation,
onPressed: _onPrevious,
backgroundColor: AppColors.primaryRedColor.withValues(alpha: 0.11),
borderColor: Colors.transparent,
textColor: AppColors.primaryRedColor,
fontSize: 16.f,
),
),
SizedBox(width: 12.w),
],
Expanded(
child: CustomButton(
text: isLastPage ? "Submit".needTranslation : "Next".needTranslation,
child: isSingleEdit
? // Single page edit mode - show only Save button
CustomButton(
text: "Save".needTranslation,
onPressed: _onNext,
backgroundColor: AppColors.primaryRedColor,
borderColor: AppColors.primaryRedColor,
textColor: AppColors.whiteColor,
fontSize: 16.f,
)
: // Complete flow mode - show Previous/Next buttons
Row(
children: [
if (!isFirstPage) ...[
Expanded(
child: CustomButton(
text: "Previous".needTranslation,
onPressed: _onPrevious,
backgroundColor: AppColors.primaryRedColor.withValues(alpha: 0.11),
borderColor: Colors.transparent,
textColor: AppColors.primaryRedColor,
fontSize: 16.f,
),
),
SizedBox(width: 12.w),
],
Expanded(
child: CustomButton(
text: isLastPage ? "Submit".needTranslation : "Next".needTranslation,
onPressed: _onNext,
backgroundColor: AppColors.primaryRedColor,
borderColor: AppColors.primaryRedColor,
textColor: AppColors.whiteColor,
fontSize: 16.f,
),
),
],
),
),
],
),
),
);
});
@ -217,8 +239,9 @@ class _UserInfoFlowManagerState extends State<UserInfoFlowManager> {
crossAxisAlignment: CrossAxisAlignment.start,
children: [
SizedBox(height: 24.h),
_buildProgressBar(),
SizedBox(height: 24.h),
// Only show progress bar in complete flow mode
if (!_viewModel.isSinglePageEditMode) _buildProgressBar(),
if (!_viewModel.isSinglePageEditMode) SizedBox(height: 24.h),
SizedBox(
height: 600.h,
child: PageView(

Loading…
Cancel
Save