Home > Back-end >  Unable to declare UnsignedInt data type for sending data model to server in dart
Unable to declare UnsignedInt data type for sending data model to server in dart

Time:07-17

I'm trying to define UnsignedInt? id in my data model. But it keeps giving me this error when I am trying to send the model to the server.

[SEVERE] json_serializable:json_serializable on lib/src/model/otp.dart (cached):

Could not generate fromJson code for countryID. To support the type UnsignedInt you can:

Here is my code where I want to send the model to server:

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;
  }

CodePudding user response:

UnsignedInt is not supported.

Out of the box, json_serializable supports many common types in the dart:core library: BigInt, bool, DateTime, double, Duration, Enum, int, Iterable, List, Map, num, Object, Set, String, Uri

See json_serializable for details.

  • Related