0

Here is the error I am getting,

[ERROR:flutter/lib/ui/ui_dart_state.cc(199)] 
Unhandled Exception: type '(dynamic) => Null' is not a 
          subtype of type '(String, dynamic) => void' of 'f'
The getter 'vendorDocList' was called on null.
Receiver: null
Tried calling: vendorDocList

Code:

class VendorsDocument {
  String lead_id;
  Future<getVendorsDoc> getVendorDocList(lead_id) async {
    final response  = await http.post(Uri.parse('example.com/vendor_doc'),
        headers:{
          'Accept': 'application/json',
          HttpHeaders.authorizationHeader: 'Bearer $accessToken}',
        },
        body: {'lead_id':'$lead_id'});
    if (response.statusCode == 200) {
      // print(response.body);
      return getVendorsDoc.fromJson( json.decode(response.body) );
    } else {
      throw Exception('No records found');
    }
  }

}
class getVendorsDoc {
  bool status;
  String msg;
  List<VendorDocList> vendorDocList;

  getVendorsDoc({this.status, this.msg, this.vendorDocList});

  getVendorsDoc.fromJson(Map<String, dynamic> json) {
    status = json['status'];
    msg = json['message'];
    vendorDocList = new List<VendorDocList>();
    json['data'].forEach((v) {
      vendorDocList.add(new VendorDocList.fromJson(v));
    });
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['status'] = this.status;
    data['message'] = this.msg;
    // if (this.vendorDocList != null) {
      data['data'] = this.vendorDocList.map((v) => v.toJson()).toList();
    // }
    return data;
  }
}

class VendorDocList {
  String logo;

  VendorDocList(
      {this.logo});

  VendorDocList.fromJson(Map<String, dynamic> json) {
    logo = json['logo'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['logo'] = this.logo;
  }
}
1
  • Hi. Welcome to SO. Please help me to resolve this issue is not a good title for a post. I changed it, please check if it ok to you. Commented Oct 8, 2021 at 8:48

1 Answer 1

1
Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['logo'] = this.logo;
  }

check this toJson method in the VendorDocList class, you are only assigning the logo to the data['logo'] without returning anything, which is why the mapping function returns null.

you should return the data like this:

Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['logo'] = this.logo;
return data;
  }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.