Explorar el Código

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

Clinton Volzke hace 6 años
padre
commit
c61cff223a
Se han modificado 1 ficheros con 3 adiciones y 12 borrados
  1. 3 12
      lib/src/webview_scaffold.dart

+ 3 - 12
lib/src/webview_scaffold.dart

@@ -76,20 +76,11 @@ class _WebviewScaffoldState extends State<WebviewScaffold> {
     super.initState();
     webviewReference.close();
 
-    _onBack = webviewReference.onBack.listen((_) {
+    _onBack = webviewReference.onBack.listen((_) async {
       if (!mounted) return;
 
-      final route = ModalRoute.of(context);
-
-      // Close the native widget only if the back operation was not veto'd
-      // by the [WillPopScope] widget or similar.
-      final handler = () => webviewReference.close();
-      route?.addScopedWillPopCallback(handler);
-      try {
-        // Perform the 'back' operation.
-        Navigator.of(context).pop();
-      } finally {
-        route?.removeScopedWillPopCallback(handler);
+      if (await Navigator.maybePop(context)) {
+        webviewReference.close();
       }
     });