[英]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.