Flutter 我怎样才能说出这个词?(颤振)

Flutter 我怎样才能说出这个词?(颤振),flutter,dart,Flutter,Dart,我学习OpenWeatherMapAPI 想把天气带到openweathermap中 API: 我认为阴霾是一种天气 但我带来的是失败。 我的应用程序说,'type'String'不是'index'的'int'类型的子类型 帮助plz 我的代码: class TodayWide extends StatelessWidget { final Map weatherData; const TodayWide({Key key, this.weatherData}) : super

我学习OpenWeatherMapAPI

想把天气带到openweathermap中

API:

我认为阴霾是一种天气

但我带来的是失败。 我的应用程序说,'type'String'不是'index'的'int'类型的子类型 帮助plz

我的代码:

    class TodayWide extends StatelessWidget {
  final Map weatherData;

  const TodayWide({Key key, this.weatherData}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      child: GridView(
        shrinkWrap: true,
        physics: NeverScrollableScrollPhysics(),
        gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
            crossAxisCount: 2, childAspectRatio: 2),
        children: <Widget>[
          Todayweatherpanel(
            textColor: coyellow,
            title: '현재 온도',
            count: weatherData['main']['temp'].toString(),
          ),
          Todayweatherpanel(
            textColor: coyellow,
            title: '체감 온도',
            count: weatherData['main']['feels_like'].toString(),
          ),
          Todayweatherpanel(
            textColor: coyellow,
            title: '습도',
            count: weatherData['main']['humidity'].toString(),
          ),
          Todayweatherpanel(
            textColor: coyellow,
            title: '날씨',
            count: weatherData['weather']['main'].toString(),
          ),
        ],
      ),
    );
  }
}
class TodayWide扩展了无状态小部件{
最终地图气象数据;
const TodayWide({Key-Key,this.weatherData}):super(Key:Key);
@凌驾
小部件构建(构建上下文){
返回容器(
子:GridView(
收缩膜:对,
物理学:NeverscrollableScroll物理学(),
gridDelegate:SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount:2,childAspectRatio:2),
儿童:[
今日天气预报(
textColor:coyellow,
标题:'현재 온도',
计数:weatherData['main']['temp'].toString(),
),
今日天气预报(
textColor:coyellow,
标题:'체감 온도',
计数:weatherData['main']['feels_like'].toString(),
),
今日天气预报(
textColor:coyellow,
标题:'습도',
计数:weatherData['main']['湿度'].toString(),
),
今日天气预报(
textColor:coyellow,
标题:'날씨',
计数:weatherData['weather']['main'].toString(),
),
],
),
);
}
}
使用以下方法:

final type=weatherData['weather'][0]['main'];//印花“薄雾”

天气
在api响应中是一个数组。如果要访问其中的第一个元素,请使用

final weatherMain = weatherData['weather'][0]['main'];

但最好使用类似于的工具将json直接转换为Dart类。这可以防止你的应用程序在api返回不同响应时中断。

很抱歉再次询问你,你能在温度后加上°C吗?你可以将
天气的值存储在一个变量中,就像我发布的示例一样。然后您就可以创建带有摄氏度符号的格式化变量。类似于
final weatherMain=weatherData['weather'][0]['main'];最终格式化主管道=“$weatherMain°C”
final weatherMain = weatherData['weather'][0]['main'];