Skip to content

Commit 38e315b

Browse files
committed
Fix back button handler to be compatible with the WillPopScope widget.
1 parent 05def7f commit 38e315b

File tree

1 file changed

+3
-12
lines changed

1 file changed

+3
-12
lines changed

lib/src/webview_scaffold.dart

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -76,20 +76,11 @@ class _WebviewScaffoldState extends State<WebviewScaffold> {
7676
super.initState();
7777
webviewReference.close();
7878

79-
_onBack = webviewReference.onBack.listen((_) {
79+
_onBack = webviewReference.onBack.listen((_) async {
8080
if (!mounted) return;
8181

82-
final route = ModalRoute.of(context);
83-
84-
// Close the native widget only if the back operation was not veto'd
85-
// by the [WillPopScope] widget or similar.
86-
final handler = () => webviewReference.close();
87-
route?.addScopedWillPopCallback(handler);
88-
try {
89-
// Perform the 'back' operation.
90-
Navigator.of(context).pop();
91-
} finally {
92-
route?.removeScopedWillPopCallback(handler);
82+
if (await Navigator.maybePop(context)) {
83+
webviewReference.close();
9384
}
9485
});
9586

0 commit comments

Comments
 (0)