(Исключение при получении данных) тип '(dynamic) => Null' не является подтипом типа '(String, dynamic) => void' из 'f'
class Product {
int? id;
String? title;
String? price;
String? description;
Category? category;
bool? favorites;
Product(
{
this.id,
this.title,
this.price,
this.description,
this.category,
this.favorites});
Product.fromJson(Map<String, dynamic> json) {
id = json['id'];
title = json['title'];
price = json['price'];
description = json['description'];
category = json['category'];
favorites = json['favorites'];
category = json['category'] != null
? new Category.fromJson(json['category'])
: null;
favorites = json['favorites'];
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
data['id'] = this.id;
data['title'] = this.title;
data['price'] = this.price;
data['description'] = this.description;
if (this.category != null) {
data['category'] = this.category!.toJson();
}
data['favorites'] = this.favorites;
return data;
}
}
class Category {
int? id;
String? categoryName;
String? createDate;
Category({this.id, this.categoryName, this.createDate});
Category.fromJson(Map<String, dynamic> json) {
id = json['id'];
categoryName = json['category_name'];
createDate = json['create_date'];
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
data['id'] = this.id;
data['category_name'] = this.categoryName;
data['create_date'] = this.createDate;
return data;
}
}
Flutter выдает исключение, не связанное с руками, при получении данных Вот вывод консоли:
I/flutter ( 5234): {banners: [{name: New Sale for Diwali, image: /media/banners/b1_1Xc9YP7.jpg, link: /product/24, first: true}, {name: Sale, image: /media/banners/os2.jpg, link: /products?category=Topwear, first: true}], products: [{id: 22, title: Nike Air Force 1, image: https://minimals.cc/static/mock-images/products/product_1.jpg, description: dfmkdgfdkmgnfdgn, price: 2564.31, discount: 521.03, finalprice: 2043.28, exclusive: true, favourites: [], category: {name: Shoes, category: {id: 2, name: Footwear, image: /media/categories/ft_JRpDRUr.jpg}}}, {id: 24, title: Nike Space Hippie, image: https://minimals.cc/static/mock-images/products/product_2.jpg, description: Nike Hippie Shoes of Color Brown, price: 2000.0, discount: 1.2, finalprice: 2070.8, exclusive: true, favourites: [{id: 1, username: vivek, photo: /media/profiles/vivek-profile_Tb7fLi2}], category: {name: Other shoes, category: {id: 1, name: Topwear, image: /media/categories/lmsh000658_1.jpg}}}], categories: [{name: Topwear, image: /media/categories/lmsh000658_1.jp
I/flutter ( 5234): e getProducts
I/flutter ( 5234): type '(dynamic) => Null' is not a subtype of type '(String, dynamic) => void' of 'f'