Skip to content

Commit 29f5536

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

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

lib/src/webview_scaffold.dart

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,14 @@ class _WebviewScaffoldState extends State<WebviewScaffold> {
7979
_onBack = webviewReference.onBack.listen((_) async {
8080
if (!mounted) return;
8181

82-
if (await Navigator.maybePop(context)) {
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();
87+
if (pop == RoutePopDisposition.pop) {
8388
webviewReference.close();
89+
Navigator.pop(context);
8490
}
8591
});
8692

0 commit comments

Comments
 (0)