Skip to content

Commit

Permalink
Merge pull request #413 from cvolzke4/back_button_over_dialog
Browse files Browse the repository at this point in the history
Allow back button to be pressed on dialog displayed over web view.
  • Loading branch information
charafau authored May 20, 2019
2 parents 1d1daeb + 2fda5d6 commit 9c05312
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions lib/src/webview_scaffold.dart
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,15 @@ class _WebviewScaffoldState extends State<WebviewScaffold> {
_onBack = webviewReference.onBack.listen((_) async {
if (!mounted) return;

// Equivalent of Navigator.maybePop(), except that [webviewReference]
// is closed when the pop goes ahead. Whether the pop was performed
// can't be determined from the return value of Navigator.maybePop().
final route = ModalRoute.of(context);
final pop = await route?.willPop();
// The willPop/pop pair here is equivalent to Navigator.maybePop(),
// which is what's called from the flutter back button handler.
final pop = await _topMostRoute.willPop();
if (pop == RoutePopDisposition.pop) {
webviewReference.close();
// Close the webview if it's on the route at the top of the stack.
final isOnTopMostRoute = _topMostRoute == ModalRoute.of(context);
if (isOnTopMostRoute) {
webviewReference.close();
}
Navigator.pop(context);
}
});
Expand All @@ -100,6 +102,16 @@ class _WebviewScaffoldState extends State<WebviewScaffold> {
}
}

/// Equivalent to [Navigator.of(context)._history.last].
Route<dynamic> get _topMostRoute {
var topMost;
Navigator.popUntil(context, (route) {
topMost = route;
return true;
});
return topMost;
}

@override
void dispose() {
super.dispose();
Expand Down

0 comments on commit 9c05312

Please sign in to comment.