gpt4 book ai didi

android - Flutter: InternalLinkedHashMap' has no instance method ' cast' with matching arguments

转载 作者:IT王子 更新时间:2023-10-29 06:54:04 24 4
gpt4 key购买 nike

我无法从之前的问题中找到解决方案,我已将 json 字符串转换为 map

下面是我的API调用方法。

Future<EventResponse> fetchEvent( ) async { // here i change Future type

String url='http://xxxxxxxxxxxx.tk/api/userapp/event/lists';

var headers = new Map<String, String>();//here i defined Map type
headers['Auth-Key'] = 'OCDOC@2018';
headers['End-Client'] = 'OCDOC';

var body = new Map<String, String>();//here i defined Map type
headers['schedule'] = 'present';

http.Response res = await http.post(url,headers: headers, body: body);

final parsed=json.decode(res.body);
var myMap = Map<String, dynamic>.from(parsed);
EventResponse eventResponse = EventResponse.convertEventResponse(myMap);
return eventResponse;


}

这是我的convertEventResponse方法

factory EventResponse.convertEventResponse(Map<String, dynamic> json) {
List<dynamic> events = json['eventList'];
List<Event> eventList = events.map((e) => Event.convertEvent(e)).toList(); //here i changed by @Richard Heap answer
return EventResponse(
error: json['error'],
status: json['status'],
deliveryCharges: json['deliveryCharge'],
imageBaseUrl: json['image_base_url'],
imageLogoUrl: json['image_logo_url'],
eventList: eventList,
);
}

我遇到的错误。

InternalLinkedHashMap<String, dynamic>' has no instance method 'cast' with matching arguments.

最佳答案

改用

.cast<String,dynamic>();

另见 https://api.dartlang.org/stable/2.0.0/dart-core/Map/cast.html

通常最好使用Map<String,String>.from(oldMap)而不是 cast<...>(...)

关于android - Flutter: InternalLinkedHashMap<String, dynamic >' has no instance method ' cast' with matching arguments,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54344420/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com