1.使用WillPopScope包裹Scaffold
2.加上onWillPop方法
return WillPopScope(
onWillPop: () {
Future<bool> canGoBack = _webViewController.canGoBack();
canGoBack.then((str) {
if(str){
_webViewController.goBack();
}else{
Navigator.of(context).pop();
}
});
},
child: Scaffold( ...
webview使用的是
flutter_inappbrowser
本文介绍如何在Flutter中使用WillPopScope组件和onWillPop方法控制WebView的后退操作。通过监听pop事件并检查WebView是否可以返回上一页,实现WebView页面的正确导航。
2792

被折叠的 条评论
为什么被折叠?



