I am working on an app where i am getting json response from api. I want to store all the objects coming from api into a list and then i want to show that list in a listview builder wrapped with future builder.
Here is my model `// To parse this JSON data, do
//
// final viewCategoryModel = viewCategoryModelFromJson(jsonString);
import 'dart:convert';
ViewCategoryModel viewCategoryModelFromJson(String str) =>
ViewCategoryModel.fromJson(json.decode(str));
String viewCategoryModelToJson(ViewCategoryModel data) =>
json.encode(data.toJson());
class ViewCategoryModel {
ViewCategoryModel({
this.status,
this.data,
});
bool? status;
List<Datum>? data;
factory ViewCategoryModel.fromJson(Map<String, dynamic> json) =>
ViewCategoryModel(
status: json["status"],
data: List<Datum>.from(json["data"].map((x) => Datum.fromJson(x))),
);
Map<String, dynamic> toJson() => {
"status": status,
"data": List<dynamic>.from(data!.map((x) => x.toJson())),
};
}
class Datum {
Datum({
this.categoryName,
this.categoryCode,
this.categoryType,
});
String? categoryName;
String? categoryCode;
String? categoryType;
factory Datum.fromJson(Map<String, dynamic> json) => Datum(
categoryName: json["category_name"],
categoryCode: json["category_code"],
categoryType: json["category_type"],
);
Map<String, dynamic> toJson() => {
"category_name": categoryName,
"category_code": categoryCode,
"category_type": categoryType,
};
}
` here is json response fromapi
{"status":true,"data":[{"category_name":"new category","category_code":"50","category_type":"Clothing"},{"category_name":"new category","category_code":"51","category_type":"Clothing"},{"category_name":"new category","category_code":"52","category_type":"Clothing"},{"category_name":"new category","category_code":"53","category_type":"Clothing"}]}
Please help