Skip to content

Commit

Permalink
Add NestedBackButtonDispatcher
Browse files Browse the repository at this point in the history
  • Loading branch information
LucasAschenbach committed Apr 1, 2021
1 parent b3f0081 commit e3d4f29
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/src/advanced_navigator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';

part 'route_information_provider.dart';
part 'back_button_dispatcher.dart';

/// A function for building a page stack from route information
typedef PathFactory = RouterConfiguration Function(RouteInformation);
Expand Down
24 changes: 24 additions & 0 deletions lib/src/back_button_dispatcher.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
part of 'advanced_navigator.dart';

class NestedBackButtonDispatcher extends ChildBackButtonDispatcher {
NestedBackButtonDispatcher(
BackButtonDispatcher parent, {
@required Route route,
}) : _route = route,
super(parent);

final Route _route;

@override
Future<bool> invokeCallback(Future<bool> defaultValue) {
// only pop if navigator is contained in top-most route
if (_route.isCurrent) {
return super.invokeCallback(defaultValue);
} else {
parent.forget(this);
var value = parent.invokeCallback(defaultValue);
parent.deferTo(this);
return value;
}
}
}

0 comments on commit e3d4f29

Please sign in to comment.