gpt4 book ai didi

redux - 参数列表不能分配给参数类型列表

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

我遇到了一个我不太明白的错误。我正在从操作中调用服务并使用响应设置新的 redux 状态。但是,我收到以下错误:

错误:

The argument type 'List<Chat> (C:\flutter\bin\cache\pkg\sky_engine\lib\core\list.dart)' can't be assigned to the parameter type 'List<Chat> (C:\flutter\bin\cache\pkg\sky_engine\lib\core\list.dart)'.

行动:

class GetChatRequest {}

class GetChatSuccess {
final List<Chat> history;

GetChatSuccess(this.history);
}

class GetChatFailure {
final String error;

GetChatFailure(this.error);
}

final Function getLastChatMessages = () {
return (Store<AppState> store) {
var chatService = new ChatService(store);

store.dispatch(new GetChatRequest());
chatService.getLast50Messages().then((history) {
store.dispatch(new GetChatSuccess(history));
});
};
};

服务:

Future<List<Chat>> getLast50Messages() async {
final response = await webClient.get('xxxx');
return response['data'].map<Chat>((e) => new Chat.fromJSON(e)).toList();
}

最佳答案

改变

store.dispatch(new GetChatSuccess(history));

store.dispatch(new GetChatSuccess(List<Chat>.from(history)));

获取正确键入的列表。

historyList<dynamic>仅包含 Chat元素,但列表仍然是通用类型 dynamic .创建正确类型的 List<Chat>使用该类型创建一个新列表并用 history 中的元素填充它.

另见 https://api.dartlang.org/stable/2.1.0/dart-core/List/List.from.html

关于redux - 参数列表不能分配给参数类型列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54065269/

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