Я пытаюсь получить список значений, где они являются логическими значениями в моем JSON API. У меня проблема в том, что я получаю эту ошибку
flutter: Null
flutter: Exception: NoSuchMethodError: The method 'map' was called on null.
Receiver: null
Tried calling: map<Provider>(Closure: (dynamic) => Provider)
JSON
{"name":"EB Games","providers":{"afterpay":true,"zippay":true}}
Дарт
class Merchant {
final String merchantUid;
final String logoUrl;
final String name;
final String categories;
final String slug;
final String backgroundImageUrl;
final String url;
final String afterpay;
final String zippay;
final List<Provider> providers;
Merchant({
this.merchantUid,
this.logoUrl,
this.name,
this.categories,
this.slug,
this.backgroundImageUrl,
this.url,
this.afterpay,
this.zippay,
this.providers
});
factory Merchant.fromJson(Map<String, dynamic> json) {
var list = json['providers'] as List;
print(list.runtimeType);
List<Provider> providersList = list.map((i) => Provider.fromJson(i)).toList();
return Merchant(
merchantUid: json['merchant_uid'],
name: json['name'],
logoUrl: json['assets']['logo_url'],
categories: json['categories'],
slug: json['slug'],
backgroundImageUrl: json['assets']['backgroundimage_url'],
url: json['url'],
afterpay: json['providers']['afterpay'],
zippay: json['providers']['zippay'],
providers: providersList
);
}
}
class Provider {
bool afterpay;
bool zippay;
Provider({
this.afterpay,
this.zippay
});
factory Provider.fromJson(Map<String, dynamic> json){
return Provider(
afterpay: json['afterpay'],
zippay: json['zippay']
);
}
}