fix: move the onBack outside of the navigator to prevent userstory from popping the entire stack

This commit is contained in:
Freek van de Ven 2024-07-06 12:33:46 +02:00 committed by Bart Ribbers
parent bb01592f54
commit f840d1b019
4 changed files with 21 additions and 15 deletions

View file

@ -3,13 +3,15 @@ import "package:flutter_availability/flutter_availability.dart";
import "package:flutter_availability/src/ui/screens/template_availability_day_overview.dart";
///
final homePageRoute = MaterialPageRoute(
MaterialPageRoute homePageRoute(VoidCallback onExit) => MaterialPageRoute(
builder: (context) => AvailabilityOverview(
onBack: () => Navigator.of(context).pop(),
onEditDateRange: (range) {
Navigator.of(context).push(availabilityViewRoute(range.start));
onEditDateRange: (range) async {
await Navigator.of(context).push(availabilityViewRoute(range.start));
},
onViewTemplates: () {},
onExit: () {
onExit();
},
),
);

View file

@ -8,7 +8,7 @@ class AvailabilityOverview extends StatefulWidget {
const AvailabilityOverview({
required this.onEditDateRange,
required this.onViewTemplates,
required this.onBack,
required this.onExit,
super.key,
});
@ -18,8 +18,8 @@ class AvailabilityOverview extends StatefulWidget {
/// Callback for when the user wants to navigate to the overview of templates
final VoidCallback onViewTemplates;
/// Callback invoked when a user attempts to go back
final VoidCallback onBack;
/// Callback for when the user wants to navigate back
final VoidCallback onExit;
@override
State<AvailabilityOverview> createState() => _AvailabilityOverviewState();
@ -103,7 +103,7 @@ class _AvailabilityOverviewState extends State<AvailabilityOverview> {
return options.baseScreenBuilder(
context,
onBack,
widget.onExit,
body,
);
}

View file

@ -26,6 +26,7 @@ class AvailabilityUserStory extends StatefulWidget {
const AvailabilityUserStory({
required this.userId,
required this.options,
this.onExit,
super.key,
});
@ -35,6 +36,9 @@ class AvailabilityUserStory extends StatefulWidget {
///
final AvailabilityOptions options;
/// Callback for when the user wants to navigate back
final VoidCallback? onExit;
///
static MaterialPageRoute route(String userId, AvailabilityOptions options) =>
MaterialPageRoute(
@ -61,7 +65,7 @@ class _AvailabilityUserStoryState extends State<AvailabilityUserStory> {
service: _service,
child: Navigator(
onGenerateInitialRoutes: (state, route) => [
homePageRoute,
homePageRoute(widget.onExit ?? () {}),
],
),
);

View file

@ -11,7 +11,7 @@ dependencies:
flutter:
sdk: flutter
intl: any
rxdart: ^0.28.0
rxdart: ^0.27.0
flutter_availability_data_interface:
git:
url: https://github.com/Iconica-Development/flutter_availability