There are two steps in this process. Preferably you'll start by mapping this json to a data structure. Then you can display the objects. There's a working example you can try out in your browser at the bottom of the answer
Mapping to a data structure
Let's say you'll have the following class:
class TimeSlot {
final String date;
final String available;
TimeSlot(this.date, this.available);
}
You can manually implement a fromJson method, or use the json_serializable package and simply annotate the class. I'll do it manually in this example.
TimeSlot.fromJson(Map<String, dynamic> json)
: date = json['date'],
available = json['available'];
Now that you have this set up, you can map your json string to this structure. Having a structure of nested arrays makes this quite complex.
import 'dart:convert';
final json = jsonDecode(myJson);
final timeJson = (json['time'] as List<dynamic>).cast<List<dynamic>>();
final List<List<TimeSlot>> time = timeJson.map((timeGroup) {
return timeGroup.map((item) {
return TimeSlot.fromJson(item as Map<String, dynamic>);
}).toList();
}).toList();
Displaying the data
Having nested ListView widgets might cause issues because of nesting their scrolling behavior. Here's an example how you can use both ListView and Column for this.
return ListView.separated(
itemCount: time.length,
separatorBuilder: (_, index) => Divider(),
itemBuilder: (_, outerIndex) {
final group = time[outerIndex];
return Column(
children:
group.map((slot) => ListTile(
title: Text("date: ${slot.date}"),
subtitle: Text("available: ${slot.available}"),
)).toList(),
);
}
);
Working example
I've made a working example here on DartPad: https://dartpad.dev/?id=b8d6d72a1359c6b9f638480d667f5cf9&null_safety=true
Additional resources
Check out the section on JSON and serialization on the Flutter dev site.