Created
January 23, 2024 10:27
-
-
Save KammererTob/13a838b91266f292a961b5d185c4d6fc to your computer and use it in GitHub Desktop.
Shortened map sytnax
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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