skip to Main Content

this is sampele of my json response

always show error like this

2

Answers


  1. Instead of adding null keep them as empty string
    ex-

    {
     'class':''
    }
    
    Login or Signup to reply.
  2. You need to use null safety in your model class.

    class Profile{
      String? photo;
    
      Profile({
        this.photo,
      });
    
      Map<String, dynamic> toMap() {
        return {
          'photo': photo,
        };
      }
    
      factory Profile.fromMap(Map<String, dynamic> map) {
        return Profile(
          photo: map["profile"]['photo'] ?? "",
        );
      }
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search