I have this json file and I want to display in a ListView Widget only the key of this data. Something like in photo . I'm new in flutter.
{
"cards": [
{
"name": {
"Title Card 1": 3,
"Title Card 2": 1,
"Title Card 3": 1,
"Title Card 4": 2,
"Title Card 5": 1
},
"authors": {
"Author John": 2,
"Author Carl": 1,
"Author Ben": 5
},
"language": {
"en": 74,
"fr": 11
}
}
]
}
try in this way...
// Fetch content from the json file
Future<void> readJson() async {
final String response = await rootBundle.loadString('assets/sample.json');
final data = await json.decode(response);
setState(() {
_items = data["items"];
});
}
And Display in this way
_items.isNotEmpty
? Expanded(
child: ListView.builder(
itemCount: _items.length,
itemBuilder: (context, index) {
return Card(
margin: const EdgeInsets.all(10),
child: ListTile(
leading: Text(_items[index]["id"]),
title: Text(_items[index]["name"]),
subtitle: Text(_items[index]["description"]),
),
);
},
),
)
: Container()
for more info check out this link: Json Data Display
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.