flutter - 在 webview 中颤动水平滑动手势
问题描述
我现在正在构建一个 Flutter 应用程序,它有一个登录名,它路由到一个新屏幕,其中包含一个脚手架,其中包含一个 webView 作为主体。对于我使用的导航
Navigator.pushNamed(
context,
webshopRoute,
arguments: WebshopArguments(initialUrl: shopUrl),
);
当我在 webView 中浏览时,我想返回 - 在 webView 中 - 使用从右到左的滑动手势(对于没有像我的 Pixel 4 这样的后退按钮的手机)。但是现在滑动所做的是它跳回登录屏幕。
我在这里找到的唯一帖子如何禁用它,这是我不想要的。
非常感谢!
解决方案
好的,所以诀窍是用 WillPopScope 包装脚手架并在 onWillPop 内部的控制器上调用 goBack()。
late WebViewController _webViewController;
@override
Widget build(BuildContext context) {
return WillPopScope(
onWillPop: () async {
_webViewController.goBack();
return false;
},
child: Scaffold(
body: SafeArea(
child: WebView(javascriptMode: JavascriptMode.unrestricted,
onWebViewCreated: (WebViewController webViewController) {
_webViewController = webViewController;
},
.....
推荐阅读
- python - 如何使 validate_data 字段可选?
- r - 在R中的数据表的列中插入一个字符
- actions-on-google - Google Home Hub 会有 API 吗?
- wordpress - 忽略 url .htaccess 中的字符串
- android - Android Firebase - 如何使用查询从内部子级访问数据?
- python - 有没有更简单的方法检查列表的长度并输出正确的 if 语句?
- r - 分隔单词中的每个字符
- c# - 网络核心线程未在 IIS 中执行
- flutter - 如何禁用 Flutter 滑块类以防止用户移动它?
- c++ - 如何并行运行 Cuda 内核调用和 CPU 函数?