gpt4 book ai didi

dart - WebView 进入 SizedBox Flutter

转载 作者:IT王子 更新时间:2023-10-29 07:06:45 28 4
gpt4 key购买 nike

我想在 flutter 中将自定义 webview 添加到 sizedBox 中......我已经尝试这样做但是出现错误:

代码:

@override
Widget build(BuildContext context) {
SystemChrome.setEnabledSystemUIOverlays([SystemUiOverlay.bottom]);
return new Scaffold(
key: _scaffoldKey,
floatingActionButton: new Row(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
new GestureDetector(
child: new Image.network("http://modernworfare.altervista.org/pause.png", width: 80.0,),
onTap: (){stop(); _showSnackBar();},
),
new GestureDetector(
child: new Image.network("http://modernworfare.altervista.org/bg.png",width: 80.0,),
onTap: (){play(); _showSnackBar2();},
),
],
),
backgroundColor: Colors.black,
body: new ListView(
children: <Widget>[
new Column(
children: <Widget>[
new Image.network("https://scontent-mxp1-1.xx.fbcdn.net/v/t1.0-9/16864236_1836092593321492_1828236030296093399_n.jpg?_nc_cat=0&oh=817190c0ef6ac6e3076582905997f3e9&oe=5B81BFF9"),
new Divider(),
new Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
new Container(
padding: new EdgeInsets.all(8.0),
child: new Text("  WEBSITE  ", style: new TextStyle(color: Colors.white,)),
decoration: new BoxDecoration(
borderRadius: new BorderRadius.circular(10.0),
border: new Border.all(
width: 4.0,
color: Colors.white,
),
),
),
new Container(
padding: new EdgeInsets.all(8.0),
child: new Text("  SOCIAL  ", style: new TextStyle(color: Colors.white,)),
decoration: new BoxDecoration(
borderRadius: new BorderRadius.circular(10.0),
border: new Border.all(
width: 4.0,
color: Colors.white,
),
),
),
new Container(
padding: new EdgeInsets.all(8.0),
child: new Text("  SHOP  ", style: new TextStyle(color: Colors.white,)),
decoration: new BoxDecoration(
borderRadius: new BorderRadius.circular(10.0),
border: new Border.all(
width: 4.0,
color: Colors.white,
),
),
),
new Container(
padding: new EdgeInsets.all(8.0),
child: new Text("  CONTACT  ", style: new TextStyle(color: Colors.white,)),
decoration: new BoxDecoration(
borderRadius: new BorderRadius.circular(10.0),
border: new Border.all(
width: 4.0,
color: Colors.white,
),
),
)],
),
new Text("hi",style: new TextStyle(color: Colors.white), ),
new SizedBox(
height: 50.0,
width: 600.0,
child: webview.launch("url",
)
),
],
)],
),
);
}

错误:

The argument type 'Future' can't be assigned to the parameter type 'Widget'.

有什么建议或想法吗?有可能这样做吗?也许添加一个 FutureBuilder 或类似的东西?

最佳答案

问题:Webview 没有为您提供完整的高度来计算其高度,您需要在页面完成时找到总内容高度。

这是我从 here 中找到的解决方案

StreamBuilder<double>(
initialData: 100,
stream: streamController.stream,
builder: (context, snapshot) {
return Container(
height: snapshot.data,
child: WebView(
initialUrl:
'data:text/html;base64,${base64Encode(const Utf8Encoder().convert(contentText))}',
onPageFinished: (some) async {
double height = double.parse(
await _webViewController.evaluateJavascript(
"document.documentElement.scrollHeight;"));
streamController.add(height);

},
onWebViewCreated: (_controller) {
_webViewController = _controller;
},
javascriptMode: JavascriptMode.unrestricted,
),
);
}
);

Note: I have used here streambuilder to avoid unnecessary "setstate" while building widget.

请告诉我此解决方案是否有效。

关于dart - WebView 进入 SizedBox Flutter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50355360/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com