I am using a api endpoint where I am getting following type of List in:
`[
[
{ "productName": "Chicken Biryani Half" },
{ "productName": " Chicken Momos" }
],
[
{ "productName": "Chicken Biryani Half" },
{ "productName": "Chicken Biryani Half" },
{ "productName": " Chicken Momos" }
]]`
How do I implement this with Listview.builder
2
Answers
Try this!
OUTPUT:
CODE:
In this cause you should make model class for manage our API response data, and you should keep your mind we cannot access dynamic data with listView builder we want use Future builder with random data like API call,
1.First we should make our model class like bellow,
2.Look at bellow API data fetch part,
you should learn asynchronous programming know about async and wait keywords, read flutter documentation get more details you can read it using this
3.Now we can pass our data into list, like bellow.
fetchProducts()
makes an HTTP GET request to your API endpoint.Replace
'YOUR_API_ENDPOINT'
with the actual URL of your APIendpoint.
If the request is successful (status code 200), it parses the JSON
response and creates a list of
Product
objects.If an error occurs during the request or parsing, it throws an exception which is caught by the
FutureBuilder
and displayed as anerror message.
in this implementation will be help fix your issue, and I attach new link for learn fetch data from internet, use this link for read it.