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

@ -165,7 +165,7 @@ class _UserInfoSelectionScreenState extends State<UserInfoSelectionScreen> {
title: "Gender".needTranslation, title: "Gender".needTranslation,
subTitle: genderText, subTitle: genderText,
onTap: () { onTap: () {
viewModel.setUserInfoPage(0); viewModel.setUserInfoPage(0, isSinglePageEdit: true);
context.navigateWithName(AppRoutes.userInfoFlowManager); context.navigateWithName(AppRoutes.userInfoFlowManager);
}, },
trailingIcon: AppAssets.edit_icon, trailingIcon: AppAssets.edit_icon,
@ -178,7 +178,7 @@ class _UserInfoSelectionScreenState extends State<UserInfoSelectionScreen> {
subTitle: ageText, subTitle: ageText,
iconColor: AppColors.greyTextColor, iconColor: AppColors.greyTextColor,
onTap: () { onTap: () {
viewModel.setUserInfoPage(1); viewModel.setUserInfoPage(1, isSinglePageEdit: true);
context.navigateWithName(AppRoutes.userInfoFlowManager); context.navigateWithName(AppRoutes.userInfoFlowManager);
}, },
trailingIcon: AppAssets.edit_icon, trailingIcon: AppAssets.edit_icon,
@ -190,7 +190,7 @@ class _UserInfoSelectionScreenState extends State<UserInfoSelectionScreen> {
title: "Height".needTranslation, title: "Height".needTranslation,
subTitle: heightText, subTitle: heightText,
onTap: () { onTap: () {
viewModel.setUserInfoPage(2); viewModel.setUserInfoPage(2, isSinglePageEdit: true);
context.navigateWithName(AppRoutes.userInfoFlowManager); context.navigateWithName(AppRoutes.userInfoFlowManager);
}, },
trailingIcon: AppAssets.edit_icon, trailingIcon: AppAssets.edit_icon,
@ -202,7 +202,7 @@ class _UserInfoSelectionScreenState extends State<UserInfoSelectionScreen> {
title: "Weight".needTranslation, title: "Weight".needTranslation,
subTitle: weightText, subTitle: weightText,
onTap: () { onTap: () {
viewModel.setUserInfoPage(3); viewModel.setUserInfoPage(3, isSinglePageEdit: true);
context.navigateWithName(AppRoutes.userInfoFlowManager); context.navigateWithName(AppRoutes.userInfoFlowManager);
}, },
trailingIcon: AppAssets.edit_icon, trailingIcon: AppAssets.edit_icon,
@ -240,7 +240,7 @@ 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); 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),
@ -254,7 +254,7 @@ 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: 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.navigateWithName(AppRoutes.organSelectorPage),

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

Loading…
Cancel
Save