I am trying to parse json response data, in this response there are nested array list and i want to display table_id : 39 and on next line or under table_id : 39 i want to display table_id : 40. Now problem is when it completes on table_id : 39 then it should go to table_id : 40 and display but instead it shows 0floor is null. Can anyone help me in which step i am doing wrong.
JSON RESPONSE
{
"message": "floors returned",
"floorData": [
{
"0floor": [
{
"table_id": "39"
}
]
},
{
"1floor": [
{
"table_id": "40"
}
]
}
]
}
Model
class TablesFloorData0floor {
String? tableId;
TablesFloorData0floor({
this.tableId,
});
TablesFloorData0floor.fromJson(Map<String, dynamic> json) {
tableId = json['table_id']?.toString();
}
Map<String, dynamic> toJson() {
final data = <String, dynamic>{};
data['table_id'] = tableId;
return data;
}
}
class TablesFloorData {
List<TablesFloorData0floor?>? the0floor;
TablesFloorData({
this.the0floor,
});
TablesFloorData.fromJson(Map<String, dynamic> json) {
if (json['0floor'] != null) {
final v = json['0floor'];
final arr0 = <TablesFloorData0floor>[];
v.forEach((v) {
arr0.add(TablesFloorData0floor.fromJson(v));
});
the0floor = arr0;
}
}
Map<String, dynamic> toJson() {
final data = <String, dynamic>{};
if (the0floor != null) {
final v = the0floor;
final arr0 = [];
v!.forEach((v) {
arr0.add(v!.toJson());
});
data['0floor'] = arr0;
}
return data;
}
}
class Tables {
String? message;
List<TablesFloorData?>? floorData;
Tables({
this.message,
this.floorData,
});
Tables.fromJson(Map<String, dynamic> json) {
message = json['message']?.toString();
if (json['floorData'] != null) {
final v = json['floorData'];
final arr0 = <TablesFloorData>[];
v.forEach((v) {
arr0.add(TablesFloorData.fromJson(v));
});
floorData = arr0;
}
}
Map<String, dynamic> toJson() {
final data = <String, dynamic>{};
data['message'] = message;
if (floorData != null) {
final v = floorData;
final arr0 = [];
v!.forEach((v) {
arr0.add(v!.toJson());
});
data['floorData'] = arr0;
}
return data;
}
}
home.dart
Widget showTable(
List<TablesFloorData> data, StateSetter setStateBT, String lang) {
return Container(
child: ListView.builder(
shrinkWrap: true,
itemCount: data.length,
itemBuilder: (BuildContext context, int index) {
return Column(
children: [
Text('test'),
ListView.builder(
shrinkWrap: true,
itemCount: data[index].the0floor!.length,
itemBuilder: (BuildContext context, int ind) {
return Text(data[index].the0floor![index]!.tableId!);
})
],
);
}));
}