【发布时间】:2019-08-25 18:54:06
【问题描述】:
我收到错误消息:
Unhandled Exception: type '_InternalLinkedHashMap<String, dynamic>' is not a subtype of type 'Future <dynamic>`
_LocationScreenState.build.<anonymous closure>
(package:clima/screens/location_screen.dart:71:32)
<asynchronous suspension>
被精确定位的线在这个里面:
FlatButton(
onPressed: () async {
var weatherData = await weather.getLocationWeather();
updateUI(weatherData); //<==it's this line
},
weather.getLocationWeather() 返回一个 Future<dynamic>. 类型的变量,它是 JSON,并且在调试器中对其进行评估,它是预期的 JSON。 upDateUI() 方法开始
void updateUI(Future<dynamic> weatherDataFuture) async {
final weatherData = await weatherDataFuture;
然后继续解析生成的weatherData。它在程序的早期被调用并按预期工作。我确信这个问题与我永无止境但仍在继续努力理解异步编程有关:-)
【问题讨论】:
-
weather.getLocationWeather() 值是“_InternalLinkedHashMap
”,并且似乎“updateUI(Future)”返回的结果与“weather.getLocationWeather()”相同 -
@NorbertoMartínAfonso -- 感谢您的回复!我不确定我是否完全理解。我了解 weather.getLocationWeather() 显然返回类型“_InternalLinkedHashMap
”。但是 updateUI() 是无效的;它不返回任何东西(?)。 -
试试我的答案 我已编辑并返回地图值
标签: asynchronous flutter dart