[
{
"id": 1,
"name": "Toshkent Viloyati",
"user_id": "998913646633",
"lat": 71.0043,
"lon": 71.0043,
"warehouse_childs": [
{
"id": 4,
"name": "Chilonzor",
"user_id": 1,
"lat": 71.0043,
"lon": 71.0043,
"warehouse_childs": []
},
{
"id": 6,
"name": "Darxan",
"user_id": 1,
"lat": 71.0043,
"lon": 71.0043,
"warehouse_childs": []
}
]
},
{
"id": 2,
"name": "Namangan Viloyati",
"user_id": "998913646633",
"lat": 71.0043,
"lon": 71.0043,
"warehouse_childs": [
{
"id": 3,
"name": "Sardoba",
"user_id": 1,
"lat": 71.0043,
"lon": 71.0043,
"warehouse_childs": [
{
"id": 7,
"name": "Apple",
"user_id": 4,
"lat": 71.0043,
"lon": 71.0043
}
]
},
{
"id": 5,
"name": "Yangi bozor",
"user_id": 1,
"lat": 71.0043,
"lon": 71.0043,
"warehouse_childs": []
}
]
}
]
привет мне надо делать динамично если есть child то надо добаить child
class CategoryModel {
int id;
int parentId;
String name;
String image;
List<CategoryModel> categoryChild;
CategoryModel(
{
this.id, this.parentId,
this.name, this.image, this.categoryChild});
CategoryModel.fromJson(Map<String, dynamic> json) {
id = json['id'];
parentId = json['parent_id'];
name = json['name'];
image = json['image'];
if (json['category_child'] != null) {
categoryChild = new List<CategoryModel>();
json['category_child'].forEach((v) {
categoryChild.add(new CategoryModel.fromJson(v));
});
}
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
data['id'] =
this.id;
data['parent_id'] = this.parentId;
data['name'] =
this.name;
data['image'] = this.image;
if (this.categoryChild != null) {
data['category_child'] =
this.categoryChild.map((v) => v.toJson()).toList();
}
return data;
}
}