From fbe124f6ee76c8df0b6667cc4c11b166315468c0 Mon Sep 17 00:00:00 2001 From: faizatflutter Date: Sun, 14 Dec 2025 09:00:57 +0300 Subject: [PATCH] Complete UserInfo Selection Module --- .../symptoms_checker_view_model.dart | 13 +++- .../symptoms_checker/user_info_selection.dart | 12 ++-- .../user_info_flow_manager.dart | 71 ++++++++++++------- 3 files changed, 65 insertions(+), 31 deletions(-) diff --git a/lib/features/symptoms_checker/symptoms_checker_view_model.dart b/lib/features/symptoms_checker/symptoms_checker_view_model.dart index 1b43fc2..fe66cf7 100644 --- a/lib/features/symptoms_checker/symptoms_checker_view_model.dart +++ b/lib/features/symptoms_checker/symptoms_checker_view_model.dart @@ -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(); } diff --git a/lib/presentation/symptoms_checker/user_info_selection.dart b/lib/presentation/symptoms_checker/user_info_selection.dart index 9a66a65..91f3d36 100644 --- a/lib/presentation/symptoms_checker/user_info_selection.dart +++ b/lib/presentation/symptoms_checker/user_info_selection.dart @@ -165,7 +165,7 @@ class _UserInfoSelectionScreenState extends State { 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 { 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 { 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 { 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 { icon: AppAssets.edit_icon, iconColor: AppColors.primaryRedColor, onPressed: () { - context.read().setUserInfoPage(0); + context.read().setUserInfoPage(0, isSinglePageEdit: false); context.navigateWithName(AppRoutes.userInfoFlowManager); }, backgroundColor: AppColors.primaryRedColor.withValues(alpha: 0.11), @@ -254,7 +254,7 @@ class _UserInfoSelectionScreenState extends State { 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), diff --git a/lib/presentation/symptoms_checker/user_info_selection/user_info_flow_manager.dart b/lib/presentation/symptoms_checker/user_info_selection/user_info_flow_manager.dart index 725d78e..523470e 100644 --- a/lib/presentation/symptoms_checker/user_info_selection/user_info_flow_manager.dart +++ b/lib/presentation/symptoms_checker/user_info_selection/user_info_flow_manager.dart @@ -24,7 +24,7 @@ class UserInfoFlowManager extends StatefulWidget { } class _UserInfoFlowManagerState extends State { - final PageController _pageController = PageController(); + late PageController _pageController; late SymptomsCheckerViewModel _viewModel; // Page titles @@ -39,6 +39,8 @@ class _UserInfoFlowManagerState extends State { void initState() { super.initState(); _viewModel = context.read(); + // Initialize PageController with the current page from ViewModel + _pageController = PageController(initialPage: _viewModel.userInfoCurrentPage); } @override @@ -48,6 +50,13 @@ class _UserInfoFlowManagerState extends State { } 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 { return Consumer(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 { 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 { 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(