我正在尝试在我的应用程序中使用一个颤振的网页视图。它正在工作,然而,我试图启动的页面需要一些时间来加载。因此,用户在显示内容之前会看到一个空白页。
我想继续显示旋转器,直到显示页面内容为止。
这里有一个我尝试过的代码片段
body: Stack(
children: <Widget>[
WebView(
key: _key,
initialUrl: widget.selectedUrl,
javascriptMode: JavascriptMode.unrestricted,
onPageFinished: (finish) {
setState(() {
isLoading = false;
});
},
),
isLoading
? Center(
child: CircularProgressIndicator(),
)
: Stack(),
],
),我看到了旋转器,但在显示内容之前,它就消失了。因此,大约有5-8秒的时间,用户可以看到一个空画布,而没有旋转器。
在屏幕上显示所有内容之前,我如何保持旋转器?
谢谢
医生摘要(查看所有细节,运行颤振医生-v):✓颤振(频道稳定,1.22.0,Mac 10.15.6 19G2021,locale en-US)
安卓工具链-用于安卓设备的开发(Android 28.0.3版) macOS和macOS (Xcode 12.0)✓Android (版本3.6)✓VS代码(1.49.2版)✓连接设备(1可用)
没有发现任何问题!
我调用的URL在显示页面之前会进行一些额外的验证。我在代码中添加了一个计时器。
不确定这是否是正确的方法
Future.delayed(const Duration(milliseconds: 9000), () {
setState(() {
isLoading = false;
});
});发布于 2020-10-06 18:55:47
// before build method
bool isLoading = true;
// somewhere in stateful calss
Stack(
children: [
WebView(
navigationDelegate: (NavigationRequest request) {
if (request.url
.startsWith('https://books-by-weight.herokuapp.com')) {
Navigator.pop(context);
// print('blocking navigation to $request}');
return NavigationDecision.prevent;
}
// print('allowing navigation to $request');
return NavigationDecision.navigate;
},
initialUrl: url
javascriptMode: JavascriptMode.unrestricted,
onWebViewCreated: (WebViewController webViewController) {
_controller.complete(webViewController);
},
onPageFinished: (finish) {
setState(() {
isLoading = false;
});
},
),
isLoading
? Center(
child: Container(
height: 30,
width: 30,
child: CircularProgressIndicator(
backgroundColor: Colors.primaries[0],
strokeWidth: 3,
),
),
)
: Stack(),
],
),https://stackoverflow.com/questions/64231985
复制相似问题