my getting json response as
{
"cities": [
{
"CTID": "5",
"City": "Hatkanangle",
"Status": "1"
},
{
"CTID": "6",
"City": "Sangli",
"Status": "1"
},
{
"CTID": "7",
"City": "Ichalkaranji",
"Status": "1"
},
{
"CTID": "8",
"City": "Shirol",
"Status": "1"
}
],
"status": 200,
"message": "data found!"
}
how can i use this data in listview builder,
i want to display list of cities after selecting city onpressed i want to save id of the perticular city in a variable,
4
Answers
Firstly, create a class model file
city_model.dart
Use this to decode json data and implement in listview.builder
First of all you should parse the list into a list variable then use this variable in the ListView builder.
you can define a model like that
and use it in your widget
First you need to create a model:
Then your page like this:
We can show city names using this way
First create empty list
Then decode jsondata using json.decode. Simply add this two line code in initState
Then after you can use cities list in ListView.builder