【发布时间】:2021-04-10 05:42:46
【问题描述】:
我有这个错误的问题:
“bool”类型不是“Map
class LoginUserModel {
final id;
LoginUserModel({@required this.id});
factory LoginUserModel.fromJson(Map<String, dynamic> json) {
return LoginUserModel(
id: json['id'],
);
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
data['id'] = this.id;
return data;
}
}
我的 id 也得到字符串和响应布尔值。 我的洞错误:
Performing hot restart...
Syncing files to device iPhone 12 mini...
Restarted application in 4,667ms.
[VERBOSE-2:ui_dart_state.cc(186)] Unhandled Exception: type 'bool' is not a subtype of type 'Map<String, dynamic>'
#0 LoginPage.build.<anonymous closure>.fetchLogin (package:amlake_shaar_main1/loginUser.dart:103:74)
<asynchronous suspension>
【问题讨论】:
-
错误信息很清楚。
LoginUserModel.fromJson需要Map<String,dynamic>的输入类型,但您已为其提供了boolean值。 -
你能帮我举个例子或提供细节吗?谢谢爸爸。
-
这不是导致问题的代码部分,当您调用 toJson 或 fromJson 时,代码中有其他内容。发布那部分
-
这可以是您的构造函数的有效输入。
Map<String, dynamic> userData = {'id': 1};。将其传递给您的构造函数。LoginUserModel myModel = LoginUserModel.fromJson(userData); -
还是不明白!我做了你的代码,仍然有问题