"data": [
{
"sno": 74,
"userid": "[email protected]",
"postUrl": "[https://uat-marc.s3.ap-south-1.amazonaws.com/news-feed/74_0.jpg@ https://uat-marc.s3.ap-south-1.amazonaws.com/news-feed/74_1.jpg@ https://uat-marc.s3.ap-south-1.amazonaws.com/news-feed/74_2.jpg]",
"contentType": "img"
}
]
This is the response. I have to display the "postUrl" images as network image in UI. I am getting only one image in that list. How to display all the images in an slider. Please help. I have done by creating model and everything works fine. but cannot able to display on the UI.
CodePudding user response:
Hi please do follow the below blog for your reference. https://protocoderspoint.com/read-json-file-assets-flutter-display-data-listview/ Steps to be followed:
- Creation of PODO class to deserialize the json data to dart object and data type.
- And use the extracted data to build a UI using the ListView.Builder widget or any widget builder of your choice.
CodePudding user response:
You can get postUrl
as String. Hope you have done that stuff by getting this response.
First of all, you have to remove the brackets from [
& ]
from a whole string.
Now you can split that String by '@ '
so you will get 3 URLs and you can show them one by one.
Here how to split the string:
final postUrls = 'yourURLs';
final split = tagName.split('@ ');
final Map<int, String> values = {
for (int i = 0; i < split.length; i )
i: split[i]
};
print(values); // {0: url1, 1: url2, 2: url3}
final url1 = values[0];
final url2 = values[1];
final url3 = values[2];
print(url1); // URL1
print(url2); // URL2
print(url3); // URL3
Try it out and do let me know if you get any problems.