[英]Unable to declare UnsignedInt data type for sending data model to server in dart
我正在尝试定义UnsignedInt? id
UnsignedInt? id
在我的数据模型中。 但是当我尝试将模型发送到服务器时,它一直给我这个错误。
[严重] json_serializable:json_serializable 在 lib/src/model/otp.dart 上(缓存):
无法为
countryID
生成fromJson
代码。 要支持UnsignedInt
类型,您可以:
- 使用
JsonConverter
https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonConverter-class.html- 使用
JsonKey
字段fromJson
和toJson
https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/fromJson.html https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/toJson.html包: myapp/src/model/otp.dart:18:16 ╷ 18 │ UnsignedInt? 国家标识; │ ^^^^^^^^^ ╵ [严重] pub 在 103 毫秒后失败,退出代码为 1
这是我想将模型发送到服务器的代码:
Future<OTP?> getCode(String countryCode, String phone) async {
const url = HttpUtils.baseUrl + HttpUtils.getcode;
_myOtp = null;
try {
final response = await http.post(
Uri.parse(url),
headers: {"Content-Type": "application/json"},
body: json.encode(OTP(phoneNo: phone,).toJson()),
);
_myOtp = OTP.fromJson(json.decode(response.body)["otp"]);
} catch (error) {
if (kDebugMode) {
print(error.toString());
}
}
return _myOtp;
}
不支持UnsignedInt
。
开箱即用,json_serializable 支持 dart:core 库中的许多常见类型:BigInt、bool、DateTime、double、Duration、Enum、int、Iterable、List、Map、num、Object、Set、String、Uri
有关详细信息,请参阅json_serializable 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.