skip to Main Content

When working with Nested json object or Complex json using Dio. Give me this error

type ‘Null’ is not a subtype of type ‘String’

My question is Null Safety is the first thing thats i am doing but if have any unconsciously required field with null from server in that time only give me this error, But Nested or Complex Json which Model variable is getting null it’ s hard to find manually. But when working with native Android and call API with Retrofit . Retrofit gives me specific point (Model variable) getting null.But flutter Dio does not give.

Have any solution for this problem like When Network Data and local Model type will be mismatch, Show me error with which data Model variable has got null. Please help me I am facing major issue with this problem.

getting Error with Network call flutter Dio

2

Answers


  1. first of all, I’m sorry for the error you encountered. It’s an annoying issue; ‘as far as I know,’ there is no way other than finding it manually. Maybe using breakpoints could be helpful. Or, if your models are not too complex, you could try resolving the issue by making the fields that might be null nullable (String?).

    (edited)

    Or:

    void logNullValues(Map<String, dynamic> data) {
      data.forEach((key, value) {
        if (value == null) {
          debugPrint('The value for "$key" is null.');
        }
      });
    }
    
    Login or Signup to reply.
  2. Its oke to have errors while playing with json structures . use this package to generate model just refer any video or documentation of json
    serializable before using it . https://pub.dev/packages/json_serializable try to also learn about null operators that can help. refer https://dart.dev/null-safety/understanding-null-safety for null safety. As code is not provided i can’t directly find where is the problem.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search