Forráskód Böngészése

Fix back button handler to be compatible with the WillPopScope widget.

Clinton Volzke 6 éve
szülő
commit
debe702911
1 módosított fájl, 7 hozzáadás és 1 törlés
  1. 7 1
      lib/src/webview_scaffold.dart

+ 7 - 1
lib/src/webview_scaffold.dart

@@ -79,8 +79,14 @@ class _WebviewScaffoldState extends State<WebviewScaffold> {
     _onBack = webviewReference.onBack.listen((_) async {
       if (!mounted) return;
 
-      if (await Navigator.maybePop(context)) {
+      // 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();
+      if (pop == RoutePopDisposition.pop) {
         webviewReference.close();
+        Navigator.pop(context);
       }
     });