嗨,我的WebView Flutter应用程序有问题,我有一个浮动操作按钮,但点击时它不会刷新
我的晶圆厂所在的代码是:
import 'dart:async';
import 'dart:math';
import 'package:flutter/material.dart';
import 'package:webview_flutter/webview_flutter.dart';
class HomePage extends StatefulWidget {
HomePage({Key key}) : super(key: key);
@override
_HomePageState createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
WebViewController _myController;
final Completer<WebViewController> _controller =
Completer<WebViewController>();
@override
Widget build(BuildContext context) {
return SafeArea(
child: Scaffold(
body: WebView(
initialUrl: 'https://syncshop.online/en/',
javascriptMode: JavascriptMode.unrestricted,
onWebViewCreated: (controller) {
_myController = controller;
},
onPageFinished: (initialUrl) {
_myController.evaluateJavascript("document.getElementsByClassName('footer-container')[0].style.display='none';");
},
),
floatingActionButton: FloatingActionButton(
onPressed: () {
_myController?.reload();
},
child: Icon(Icons.refresh),
),
),
);
}
}
FAB存在,但在按下时不会刷新Webview网址
答案 0 :(得分:1)
您有两个Web View Controller实例。
--- --- --- --- Total 22941313
Building TensorFlow graph... Setting up snapshot image grid... Setting up run dir... Training...
tick 1 kimg 140.3 lod 4.00 minibatch 128 time 11m 48s sec/tick 661.6 sec/kimg 4.72 maintenance 46.3 gpumem 3.1 Downloading https://drive.google.com/uc?id=1MzTY44rLToO5APn8TZmfR7_ENSe5aZUn ............ failed Traceback (most recent call last): File "train.py", line 191, in <module>
main() File "train.py", line 186, in main
dnnlib.submit_run(**kwargs) File "D:\Personal\Neural Net\stylegan-master\dnnlib\submission\submit.py", line 290, in submit_run
run_wrapper(submit_config) File "D:\Personal\Neural Net\stylegan-master\dnnlib\submission\submit.py", line 242, in run_wrapper
util.call_func_by_name(func_name=submit_config.run_func_name, submit_config=submit_config, **submit_config.run_func_kwargs) File "D:\Personal\Neural Net\stylegan-master\dnnlib\util.py", line 257, in call_func_by_name
return func_obj(*args, **kwargs) File "D:\Personal\Neural Net\stylegan-master\training\training_loop.py", line 264, in training_loop
metrics.run(pkl, run_dir=submit_config.run_dir, num_gpus=submit_config.num_gpus, tf_config=tf_config) File "D:\Personal\Neural Net\stylegan-master\metrics\metric_base.py", line 125, in run
metric.run(*args, **kwargs) File "D:\Personal\Neural Net\stylegan-master\metrics\metric_base.py", line 60, in run
self._evaluate(Gs, num_gpus=num_gpus) File "D:\Personal\Neural Net\stylegan-master\metrics\frechet_inception_distance.py", line 29, in _evaluate
inception = misc.load_pkl('https://drive.google.com/uc?id=1MzTY44rLToO5APn8TZmfR7_ENSe5aZUn')
# inception_v3_features.pkl File "D:\Personal\Neural Net\stylegan-master\training\misc.py", line 32, in load_pkl
with open_file_or_url(file_or_url) as file: File "D:\Personal\Neural Net\stylegan-master\training\misc.py", line 28, in open_file_or_url
return dnnlib.util.open_url(file_or_url, cache_dir=config.cache_dir) File "D:\Personal\Neural Net\stylegan-master\dnnlib\util.py", line 366, in open_url
res.raise_for_status() File "D:\Users\bas11\Miniconda3\envs\tfgpu-old\lib\site-packages\requests\models.py", line 940, in raise_for_status
raise HTTPError(http_error_msg, response=self) requests.exceptions.HTTPError: 403 Client Error: Forbidden for url: https://doc-08-10-docs.googleusercontent.com/docs/securesc/ha0ro937gcuc7l7deffksulhg5h7mbp1/8fm1944ik1stbbau4d65a96qqe56ta94/1576202400000/06831416635760916404/*/1MzTY44rLToO5APn8TZmfR7_ENSe5aZUn
WebViewController _myController
正在发生的事是_myController被分配了一个值,但是还没有任何数据。
我建议将Completer<WebViewController> _controller
实例与以下代码一起使用:
_controller
,FAB按钮为:
onWebViewCreated: (controller) {
_controller.complete(controller);
}
以上对 floatingActionButton: FutureBuilder<WebViewController>(
future: _controller.future,
builder: (BuildContext context, AsyncSnapshot<WebViewController> controller) {
if (controller.hasData) {
return FloatingActionButton(
onPressed: () {
controller.data.reload();
},
child: Icon(Icons.refresh),
);
}
return Container();
}),
的使用允许您仅在Completer
有一些数据要重新加载后才显示FAB。
有关更多详细信息,请参见以下示例代码:https://github.com/flutter/plugins/blob/master/packages/webview_flutter/example/lib/main.dart