From e26f6e6fffc8ce40aaed1a32d7d15c461f07fa43 Mon Sep 17 00:00:00 2001 From: jjoonleo Date: Mon, 7 Jul 2025 12:57:58 +0900 Subject: [PATCH] feat: implement step validation and revalidation in schedule multi-page form navigation --- .../components/schedule_multi_page_form.dart | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/lib/presentation/schedule_create/components/schedule_multi_page_form.dart b/lib/presentation/schedule_create/components/schedule_multi_page_form.dart index 60fd7f71..49f273a3 100644 --- a/lib/presentation/schedule_create/components/schedule_multi_page_form.dart +++ b/lib/presentation/schedule_create/components/schedule_multi_page_form.dart @@ -118,6 +118,8 @@ class _ScheduleMultiPageFormState extends State } void _onNextPageButtonClicked(BuildContext context) { + // Revalidate the current step before proceeding + switch (_pageCubitTypes[_tabController.index]) { case const (ScheduleNameCubit): context.read().scheduleNameSubmitted(); @@ -136,6 +138,7 @@ class _ScheduleMultiPageFormState extends State } if (_tabController.index < _tabController.length - 1) { _updateCurrentPageIndex(_tabController.index + 1); + _revalidateCurrentStep(context); } else { widget.onSaved?.call(); Navigator.of(context).pop(); // Close the form @@ -144,6 +147,9 @@ class _ScheduleMultiPageFormState extends State } void _onPreviousPageButtonClicked() { + // Set validity to true when going to previous page + context.read().add(ScheduleFormValidated(isValid: true)); + if (_tabController.index > 0) { _updateCurrentPageIndex(_tabController.index - 1); } else { @@ -160,6 +166,7 @@ class _ScheduleMultiPageFormState extends State } void _updateCurrentPageIndex(int index) { + final previousIndex = _tabController.index; _tabController.index = index; _pageViewController.animateToPage( index, @@ -167,4 +174,33 @@ class _ScheduleMultiPageFormState extends State curve: Curves.easeInOut, ); } + + void _revalidateCurrentStep(BuildContext context) { + switch (_pageCubitTypes[_tabController.index]) { + case const (ScheduleNameCubit): + final currentState = context.read().state; + context + .read() + .add(ScheduleFormValidated(isValid: currentState.isValid)); + break; + case const (ScheduleDateTimeCubit): + final currentState = context.read().state; + context + .read() + .add(ScheduleFormValidated(isValid: currentState.isValid)); + break; + case const (SchedulePlaceMovingTimeCubit): + final currentState = context.read().state; + context + .read() + .add(ScheduleFormValidated(isValid: currentState.isValid)); + break; + case const (ScheduleFormSpareTimeCubit): + final currentState = context.read().state; + context + .read() + .add(ScheduleFormValidated(isValid: currentState.isValid)); + break; + } + } }