Hi I've a question to create a json response to model class in flutter.
My response from API is like this :
{
"status": 200,
"message": "data fetch successfull",
"data": [{
"view_type": 1,
"heading_title": "Trending Now",
"trend_list": [{
"title": "",
"subtitle": "",
"price": 1500,
"display_image": "",
"size": [6, 7, 8, 9, 10],
"rating": 4,
"isFavourite": false,
"container_color": ["0xFF559BE2", "0xFF2F53CB"],
"image_shoe": [{
"shoe_image": "",
"color": "0xFF559BE2",
"container_color": ["0xFF559BE2", "0xFF559BE2"]
}, {
"shoe_image": "",
"color": "0xFF559BE2",
"container_color": ["0xFF559BE2", "0xFF559BE2"]
}, {
"shoe_image": "",
"color": "0xFF559BE2",
"container_color": ["0xFF559BE2", "0xFF559BE2"]
}, {
"shoe_image": "",
"color": "0xFF559BE2",
"container_color": ["0xFF559BE2", "0xFF559BE2"]
}, {
"shoe_image": "",
"color": "0xFF559BE2",
"container_color": ["0xFF559BE2", "0xFF559BE2"]
}]
}]
}
]
}
So My Problem is in Container Box Decoration gradient Color accept Color not in String.
So what will be Data type should I add in Model class.?
CodePudding user response:
You model class can have a color.
You can get a color from your string in JSON by first parsing it as an integer and then creating a color from that integer:
yourModelPropertyOfTypeColor = Color(int.parse("0xFF559BE2"))
CodePudding user response:
Use this site to create model.dart from json online