Future使用FutureBuilder返回null

时间:2018-10-07 12:10:43

标签: dart flutter android-webview future dart-pub

FlutterWebViewPlugin对象用于启动URL并通过FutureBuilder显示网页。

FlutterWebviewPlugin plugin = new FlutterWebviewPlugin();

urlSelector()是一个返回字符串url的函数

static String urlSelector(){
  String url;
  //code to initialize url
  return url;
}

launcher()函数返回Future

Future launcher() async{
  var result = await plugin.launch(
    urlSelector(),
    rect: new Rect.fromLTRB(0.0, 100.0, 0.0, 0.0),
    withLocalStorage: true,
  );
  return result;
}

build()函数紧随launcher()

 @override
  Widget build(BuildContext context) {

final appbar =  new AppBar(//code );
FutureBuilder launchPad = new FutureBuilder(builder: (context,snapshot){
  switch(snapshot.connectionState){
    case ConnectionState.none:
      {
        return new Text('no connection');
      }
    case ConnectionState.active:
    case ConnectionState.waiting:
      return new LinearProgressIndicator();
    case ConnectionState.done:
      {
        if(snapshot.hasError)
          return new Text('error: ${snapshot.error}');
        return new Text('${snapshot.data}');
      }
  }
}
  ,future: launcher(),);
// TODO: implement build
Scaffold scaffold = new Scaffold(
  appBar: appbar,
  body: launchPad ,
  );
return scaffold;

}

app在应该显示网页的地方显示“ null”。 如何更改代码以获得预期的结果?

0 个答案:

没有答案