I Have Nested JSON List I want to add this list in flutter Widget, I have try it before few days but not found proper solution.
Am sharing with you json Data like below. You can found full json file here
[{
"month": "July",
"services": [{
"name": "Opening Balance",
"amount": 5566.12
},
{
"name": "Property Rates",
"amount": 0
}
]
},
{
"month": "August",
"services": [{
"name": "Waste Disposal",
"amount": 0
},
{
"name": "Water Basic",
"amount": 0
},
{
"name": "Water Metered",
"amount": 0
},
{
"name": "Interest",
"amount": 81.63
},
{
"name": "Closing Balance",
"amount": 6145.05
}
]
},
{
"month": "September",
"services": [{
"name": "Opening Balance",
"amount": 6145.05
},
{
"name": "Property Rates",
"amount": 107.4
}
]
},
{
"month": "October",
"services": [{
"name": "Opening Balance",
"amount": 6319.27
},
{
"name": "Property Rates",
"amount": 107.4
},
{
"name": "Sanitation Basic",
"amount": 0
},
{
"name": "Waste Disposal",
"amount": 0
},
{
"name": "Water Basic",
"amount": 0
},
{
"name": "Water Metered",
"amount": 33.65
},
{
"name": "Interest",
"amount": 83.04
},
{
"name": "Journal Credit",
"amount": 0
},
{
"name": "Total",
"amount": 224.09
},
{
"name": "Closing Balance",
"amount": 6543.36
}
]
}
]
I have above string json to dart -> model file here
Expected Result of all list ->
Expected result after search by month name ->
Listview Code:
ListView.builder(
shrinkWrap: true,
itemCount: userList.length,
itemBuilder: (context, index) {
return ListTile(
title: Text(userList[index]['month']),
leading:
Text(userList[index]['services'][index]['name']),
trailing: Text(userList[index]['services'][index]
['amount']
.toString()),
);
},
),
2
Answers
I have try it Following Way
Create Lists:
Search Filter:
Widget:
You Can Found Full Widget Code here
First iteration is ok, but you have to iterate again for every month in order to display services…
Try something like this:
Regarding the search, you have an example here:
Listview filter search in Flutter
Anyway depending on the context of your application I’d suggest you to work with objects and not with maps, and to do the search from the provider and not with a stateful widget.