[英]Flutter Api call Unhandled Exception
i have a problem with api call, in the project i have another call and it work, this call doesn't work in any way我对 api 调用有疑问,在项目中我有另一个调用并且它工作,这个调用无论如何都不起作用
// file meteo.dart
class Meteo {
int id;
double temperatura;
String name;
Meteo(this.id, this.temperatura, this.name);
Meteo.fromMap(Map<String, dynamic> mappa){
this.id = mappa['id'];
this.temperatura = mappa['main']['temp'];
this.name = mappa['name'].toString();
}
}
This is the model of the response这是响应的 model
Future ferentinoGet() async {
var dio = Dio();
Response response = await
dio.get('https://api.openweathermap.org/data/2.5/weather?q=ferentino&appid=****************');
final resJson = response.data;
datiFerentino = resJson
.map<Meteo>((mappa) => Meteo.fromMap(mappa))
.toList();
print(response.data);
}
This is the api call这是 api 电话
[VERBOSE-2:ui_dart_state.cc(177)] Unhandled Exception: NoSuchMethodError: Class '_InternalLinkedHashMap<String, dynamic>' has no instance method 'map' with matching arguments.
Receiver: _LinkedHashMap len:13
Tried calling: map<Meteo>(Closure: (dynamic) => Meteo)
Found: map<K2, V2>((K, V) => MapEntry<K2, V2>) => Map<K2, V2>
#0 Object.noSuchMethod (dart:core-patch/object_patch.dart:51:5)
#1 _HomeScreenState.ferentinoGet (package:ferentino/main.dart:223:10)
<asynchronous suspension>
#2 _HomeScreenState.initState (package:ferentino/main.dart:43:5)
#3 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4765:58)
#4 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4601:5)
#5 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3569:14)
#6 Element.updateChild (package:flutter/src/widgets/framework.dart:3327:18)
#7 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:6118:14)
#8 Element.<…>
this is the error.这是错误。
Can you help me?你能帮助我吗?
Thank you谢谢
I think you process your JSON response as a List
but it looks resJson
is a Map
.我认为您将 JSON 响应作为List
处理,但看起来resJson
是Map
。 But map
method for Map
has different prototype.但是map
的Map
方法有不同的原型。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.