File tree Expand file tree Collapse file tree 1 file changed +18
-6
lines changed Expand file tree Collapse file tree 1 file changed +18
-6
lines changed Original file line number Diff line number Diff line change @@ -79,13 +79,15 @@ class _WebviewScaffoldState extends State<WebviewScaffold> {
7979 _onBack = webviewReference.onBack.listen ((_) async {
8080 if (! mounted) return ;
8181
82- // Equivalent of Navigator.maybePop(), except that [webviewReference]
83- // is closed when the pop goes ahead. Whether the pop was performed
84- // can't be determined from the return value of Navigator.maybePop().
85- final route = ModalRoute .of (context);
86- final pop = await route? .willPop ();
82+ // The willPop/pop pair here is equivalent to Navigator.maybePop(),
83+ // which is what's called from the flutter back button handler.
84+ final pop = await _topMostRoute.willPop ();
8785 if (pop == RoutePopDisposition .pop) {
88- webviewReference.close ();
86+ // Close the webview if it's on the route at the top of the stack.
87+ final isEditorOnTopMostRoute = _topMostRoute == ModalRoute .of (context);
88+ if (isEditorOnTopMostRoute) {
89+ webviewReference.close ();
90+ }
8991 Navigator .pop (context);
9092 }
9193 });
@@ -100,6 +102,16 @@ class _WebviewScaffoldState extends State<WebviewScaffold> {
100102 }
101103 }
102104
105+ /// Equivalent to [Navigator.of(context)._history.last] .
106+ Route <dynamic > get _topMostRoute {
107+ var topMost;
108+ Navigator .popUntil (context, (route) {
109+ topMost = route;
110+ return true ;
111+ });
112+ return topMost;
113+ }
114+
103115 @override
104116 void dispose () {
105117 super .dispose ();
You can’t perform that action at this time.
0 commit comments