显示从API提取的数据-在Flutter中制作应用

我正在尝试通过API提取数据,该API做得很好,但是没有显示出来。调试显示正确的结果,但结果只是不显示。

这是我对另一个屏幕的未来通话。

  String _cityEntered;
  Future _goToChangeCity(BuildContext context) async {
    Map results = await Navigator.of(context).push(
      MaterialPageRoute<Map>(
      builder: (BuildContext context) {
        return ChangeCity();
    }));

    if(results != null && results.containsKey('info')){
      _cityEntered = results['info'];
    }else{
      print('nothing');
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(

这就是用法。

          Container(
            alignment: Alignment.topRight,
            margin: const EdgeInsets.fromLTRB(0, 20, 30, 0),
            child: Text('${_cityEntered == null ? utils.defaultCity : _cityEntered}', style: TextStyle(color: Colors.white, fontSize: 22.9,),),),
          Container(
            margin: const EdgeInsets.fromLTRB(30, 350, 0, 0),
            child: updateTempWidget('${_cityEntered == null ? utils.defaultCity : _cityEntered}'),
          )

这是窗口小部件方法调用。

Widget updateTempWidget(String city) {
  return FutureBuilder(
      future: getWeather(city),
      builder: (BuildContext context, AsyncSnapshot<Map> snapshot){
        if(snapshot.hasData){
          Map content = snapshot.data;
          return Container(
            child: new ListView(
              children: <Widget>[
                ListTile(
                  title: Text(content['main']['temp'].toString(), style: TextStyle(color: Colors.white, fontSize: 49.9, fontWeight: FontWeight.bold),),
                ),
                ListTile(
                  title: Text(content['main']['humidity'].toString(), style: TextStyle(color: Colors.white, fontSize: 25.9, fontWeight: FontWeight.bold),),
                ),
                ListTile(
                  title: Text(content['main']['pressure'].toString(), style: TextStyle(color: Colors.white, fontSize: 25.9, fontWeight: FontWeight.bold),),
                ),
              ],
            ),
          );
        }else{
          return Container();
        }
  }
  );
}

这是我从API输出的json

{"coord":{"lon":67.08,"lat":24.91},"weather":[{"id":800,"main":"Clear","description":"clear sky","icon":"01d"}],"base":"stations","main":{"temp":34,"feels_like":35,"temp_min":34,"temp_max":34,"pressure":1006,"humidity":49},"visibility":7000,"wind":{"speed":5.1,"deg":270},"clouds":{"all":5},"dt":1589191993,"sys":{"type":1,"id":7576,"country":"PK","sunrise":1589158175,"sunset":1589205996},"timezone":18000,"id":1174872,"name":"Karachi","cod":200}
评论