我使用的是来自flutter_webview_plugin包的颤振flutter_webview_plugin的一个非常简单的实现。
当我弹出嵌入Webview Scaffold的屏幕时,屏幕首先弹出,然后Webview在屏幕上停留1/2秒,然后弹出。我做错什么了吗?
class _EYWebviewPageState extends State<EYWebviewPage> {
@override
void initState() {
super.initState();
}
@override
void dispose() {
super.dispose();
}
@override
Widget build(BuildContext context) {
return WebviewScaffold(
appBar: CupertinoNavigationBar(
leading: CupertinoButton(
padding: EdgeInsets.zero,
child: Image.asset('assets/img/navigation/common/close-icon.png'),
onPressed: () => Navigator.of(context).pop(true),
),
),
url: widget.url,
clearCache: true,
appCacheEnabled: true,
withJavascript: true,
withLocalStorage: true,
hidden: true,
);
}
}发布于 2020-07-13 18:44:50
解决方案是合并一个WillPopScope,以便在屏幕弹出时关闭插件。同时,使用maybePop() instead of pop()
以下是完整的构建:
Widget build(BuildContext context) {
return WillPopScope(
onWillPop: () async {
await FlutterWebviewPlugin().close(); // Close the plugin so that it doesn't overlay anymore
return true;
},
child: WebviewScaffold(
appBar: CupertinoNavigationBar(
leading: CupertinoButton(
padding: EdgeInsets.zero,
child: Image.asset('assets/img/navigation/common/close-icon.png'),
onPressed: () => Navigator.maybePop(context),
),
),
url: widget.url,
),
);
}
}发布于 2020-07-09 03:40:33
CupertinoNavigationBar需要CupertinoPageScaffold。但是WebviewScaffold使用Scaffold。这就是为什么你在观察这种行为。
您可以使用AppBar,而不是CupertinoNavigationBar。
https://stackoverflow.com/questions/62805703
复制相似问题