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

View file

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

View file

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

View file

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