即使在 Flutter 中弹出了父窗口小部件屏幕,如何呈现仍然 运行 的 webview?
How to render a webview that will still running even though the parent widget screen is popped out in Flutter?
所以在我的应用程序中,我创建了一个额外的页面。当该页面打开时,它将引导用户完成一系列步骤,最终打开一个指向后端 URL 的 webview,生成要保存到服务器的图像。用户不需要知道webview中正在绘制什么,因此可以将webview设置为不可见(opacity = 0.0)。
图片只能由该网页生成(这就是为什么我必须用webview打开它的原因)。这是一个客户端 javascript 和 HTML5 canvas 过程,不能仅由服务器端代码完成。实际上有一个网页必须打开。而 Flutter 代码需要做的就是打开 webview 组件足够长的时间,以便创建图像并自动保存到服务器。
问题是,这个过程可能需要几十秒。就我而言,它需要 7-12 秒。并且用户可能会在页面上按回,不幸的是也会关闭 webview 并取消图像生成和提交。我已经添加了一个无限循环的进度指示器,但显然,从早期的用户测试来看,一些用户没有足够的耐心等待那么久,并且在图像完成渲染之前就已经按下了。
我的问题是,如何创建一个与当前屏幕分离的webview,这样即使当前屏幕关闭后,webview仍会运行在后台?
目前,我为此使用 flutter_webview_plugin: ^0.3.11。它允许启动隐藏的 webview 弹出窗口。但是当我关闭页面时,不可见的 webview 弹出窗口也会关闭。
将 Offstage
小部件与自定义弹出逻辑相结合(不是弹出,只需通过将 bool offstage
设置为 true 来隐藏 webview)。
根据 Offstage
文档:
A widget that lays the child out as if it was in the tree, but without
painting anything, without making the child available for hit testing,
and without taking any room in the parent.
Offstage children are still active: they can receive focus and have
keyboard input directed to them.
Animations continue to run in offstage children, and therefore use
battery and CPU time, regardless of whether the animations end up
being visible.
所以在我的应用程序中,我创建了一个额外的页面。当该页面打开时,它将引导用户完成一系列步骤,最终打开一个指向后端 URL 的 webview,生成要保存到服务器的图像。用户不需要知道webview中正在绘制什么,因此可以将webview设置为不可见(opacity = 0.0)。
图片只能由该网页生成(这就是为什么我必须用webview打开它的原因)。这是一个客户端 javascript 和 HTML5 canvas 过程,不能仅由服务器端代码完成。实际上有一个网页必须打开。而 Flutter 代码需要做的就是打开 webview 组件足够长的时间,以便创建图像并自动保存到服务器。
问题是,这个过程可能需要几十秒。就我而言,它需要 7-12 秒。并且用户可能会在页面上按回,不幸的是也会关闭 webview 并取消图像生成和提交。我已经添加了一个无限循环的进度指示器,但显然,从早期的用户测试来看,一些用户没有足够的耐心等待那么久,并且在图像完成渲染之前就已经按下了。
我的问题是,如何创建一个与当前屏幕分离的webview,这样即使当前屏幕关闭后,webview仍会运行在后台?
目前,我为此使用 flutter_webview_plugin: ^0.3.11。它允许启动隐藏的 webview 弹出窗口。但是当我关闭页面时,不可见的 webview 弹出窗口也会关闭。
将 Offstage
小部件与自定义弹出逻辑相结合(不是弹出,只需通过将 bool offstage
设置为 true 来隐藏 webview)。
根据 Offstage
文档:
A widget that lays the child out as if it was in the tree, but without painting anything, without making the child available for hit testing, and without taking any room in the parent.
Offstage children are still active: they can receive focus and have keyboard input directed to them.
Animations continue to run in offstage children, and therefore use battery and CPU time, regardless of whether the animations end up being visible.