Skip to content

Instantly share code, notes, and snippets.

@KammererTob
Created January 23, 2024 10:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KammererTob/13a838b91266f292a961b5d185c4d6fc to your computer and use it in GitHub Desktop.
Save KammererTob/13a838b91266f292a961b5d185c4d6fc to your computer and use it in GitHub Desktop.
Shortened map sytnax
class SubCatModal {
late int id;
late String name;
late String img;
late String color;
SubCatModal.fromjson(Map<String, dynamic> json) {
id = json['id'];
name = json['name'];
img = json['img'];
color = json['color'];
}
}
void main() {
Map<String, dynamic> test = {
"success": true,
"status": 200,
"message": "Category is ready to show",
"data": [
{
"id": 5,
"name": "Pharmacy",
"img": "sub_cat1705749441.png",
"color": "#e5edfa"
},
{
"id": 6,
"name": "Seafood",
"img": "sub_cat1705749543.png",
"color": "#ffeddd"
}
]
};
List<SubCatModal> responseJson =
test['data'].map(SubCatModal.fromjson).toList();
print(responseJson.runtimeType);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment