fluttercommunity / fluttercommunity/flutter_webview_plugin

Webview can't show anything and infinity loop

未关闭
#265 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
Java
星标
1.5k
派生
936
PR 合并指标
30 天内没有已合并 PR

描述

```dart
import 'package:flutter/material.dart';
// import 'package:flutter_html_view/flutter_html_view.dart';
import 'package:flutter_webview_plugin/flutter_webview_plugin.dart';
import 'package:cat_dog/modules/dashboard/actions.dart';

class ViewComponent extends StatefulWidget {
final dynamic news;
const ViewComponent({
Key key,
this.news
}) : super(key: key);

@override
_ViewComponentState createState() => new _ViewComponentState();
}
class _ViewComponentState extends State {
String html = '';
final flutterWebviewPlugin = new FlutterWebviewPlugin();
@override
void initState() {
super.initState();
getDefailNews(widget.news['url']).then((result) {
print(result);
// setState(() {
// html = result;
// });
flutterWebviewPlugin.launch(new Uri.dataFromString('', mimeType: 'text/html', parameters: { 'charset': 'utf-8' }).toString(), hidden: false);
});
}
@override
Widget build(BuildContext context) {
return new Center(
// child: new SingleChildScrollView(
// child: new Center(
// child: new HtmlView(
// data: html,
// baseURL: "", // optional, type String
// onLaunchFail: (url) { // optional, type Function
// print("launch $url failed");
// }
// )
// ),
// )
child: new WebviewScaffold(
url: new Uri.dataFromString('', mimeType: 'text/html', parameters: { 'charset': 'utf-8' }).toString(),
appBar: new AppBar(
title: Text(widget.news['heading']),
),
withZoom: true,
withLocalStorage: true,
hidden: false,
initialChild: Container(
child: const Center(
child: Text('Waiting.....'),
),
),
),
);
}

}
```

Navigation

```
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => ViewPage(news: item),
),
);
```
Result:
Function initState inifinity loop => webview can't show anything

Can you guy explain what wrong with my code ?

贡献指南

这个仓库没有索引到贡献指南

调研方向

从提供的 ViewComponent 开始,重点查看 initState 和 WebviewScaffold 配置。阅读 flutter_webview_plugin 的生命周期和导航文档,然后使用提供的导航代码复现该行为。完成的标准是确定重复初始化的原因,并获得可正常工作的 WebView 显示。

由索引模型根据 Issue 内容生成。

评估

技术栈
dart
领域
mobile
Issue 类型
缺陷
难度
3/5
预计耗时
1-2 天
活跃度
停滞
描述清晰度
需要澄清
新手友好度
25/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。