Skip to content

Commit

Permalink
fix(app): tutorial navigation off if clicked too fast
Browse files Browse the repository at this point in the history
  • Loading branch information
tamslo committed Feb 25, 2025
1 parent 7f9f790 commit 8e3a7e9
Showing 1 changed file with 42 additions and 16 deletions.
58 changes: 42 additions & 16 deletions app/lib/common/widgets/tutorial/tutorial_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,11 @@ class TutorialBuilder extends HookWidget {
pageView,
Padding(
padding: EdgeInsets.only(top: PharMeTheme.smallSpace),
child: _buildActionBar(context, currentPageIndex, pageController),
child: _buildActionBar(
context,
currentPageIndex,
pageController,
),
),
],
),
Expand Down Expand Up @@ -123,6 +127,22 @@ class TutorialBuilder extends HookWidget {
final directionButtonTextStyle =
PharMeTheme.textTheme.titleLarge!.copyWith(fontSize: 20);
const directionButtonIconSize = 22.0;
void navigateIfSafe(void Function() navigate, { required bool isForward }) {
if (pageController.page == null) {
navigate();
return;
}
final pageChangeProgress = pageController.page! % 1;
if (pageChangeProgress == 0) {
navigate();
return;
}
const allowPageChangeThreshold = 0.5;
final allowPageChange = isForward
? pageChangeProgress >= allowPageChangeThreshold
: pageChangeProgress <= (1 - allowPageChangeThreshold);
if (allowPageChange) navigate();
}
return Row(
mainAxisAlignment: showFirstButton
? MainAxisAlignment.spaceBetween
Expand All @@ -131,15 +151,18 @@ class TutorialBuilder extends HookWidget {
children: [
if (showFirstButton) DirectionButton(
direction: ButtonDirection.backward,
onPressed: isFirstPage
? () {
initiateRouteBack();
routeBackToContent(context.router, popNull: true);
}
: () => pageController.previousPage(
duration: Duration(milliseconds: 500),
curve: Curves.ease,
),
onPressed: () => navigateIfSafe(
isFirstPage
? () {
initiateRouteBack();
routeBackToContent(context.router, popNull: true);
}
: () => pageController.previousPage(
duration: Duration(milliseconds: 500),
curve: Curves.ease,
),
isForward: false,
),
text: isFirstPage
? firstBackButtonText!
: context.l10n.onboarding_prev,
Expand All @@ -148,12 +171,15 @@ class TutorialBuilder extends HookWidget {
),
DirectionButton(
direction: ButtonDirection.forward,
onPressed: isLastPage
? Navigator.of(context).pop
: () => pageController.nextPage(
duration: Duration(milliseconds: 500),
curve: Curves.ease,
),
onPressed: () => navigateIfSafe(
isLastPage
? Navigator.of(context).pop
: () => pageController.nextPage(
duration: Duration(milliseconds: 500),
curve: Curves.ease,
),
isForward: true,
),
text: isLastPage && lastNextButtonText != null
? lastNextButtonText!
: context.l10n.action_continue,
Expand Down

0 comments on commit 8e3a7e9

Please sign in to comment.