簡體   English   中英

無法聲明 UnsignedInt 數據類型以在 dart 中將數據模型發送到服務器

[英]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類型,您可以:

這是我想將模型發送到服務器的代碼:

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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM