I am trying to parse a complex json file into my application I am getting an error: The getter 'name' isn't defined for the type 'List'. I can't get the name of the route at my List of routes, but can get everything else. I don't understand where this is happening and how to fix it.
My code:
void openBottomSheet() {
showModalBottomSheet(
context: context,
builder: (context) {
return FutureBuilder<DriverDataModel>(
future: mongoApi.getMongoData(),
builder: (context, snapshot) {
if (snapshot.hasData) {
final driver = snapshot.data;
return Container(
child: ListView.builder(
itemCount: driver.data.routes.length,
itemBuilder: (BuildContext context, snapshot) {
return ListTile(
title: Text('${driver.data.routes.name}'),
leading: Icon(Icons.directions),
onTap: () {
drawPolyLine.cleanPolyline();
getCurrentLocation();
routesCoordinates.isInCourse(driver.data.routes);
Navigator.pop(context);
},
);
},
),
);
}
return Container();
},
);
});
Json reponse:
{
"success": true,
"data": {
"_id": "600773ac1bde5d10e89511d1",
"name": "Joselito",
"truck": "5f640232ab8f032d18ce0137",
"phone": "*************",
"routes": [
{
"name": "Tere city",
"week": [
{
"short_name": "mon"
}
],
"coordinates": [
{
"lat": -22.446938,
"lng": -42.982084
},
{
"lat": -22.434384,
"lng": -42.978511
}
]
}
],
"createdAt": "2021-01-20T00:05:00.717Z",
"updatedAt": "2021-01-20T00:05:00.717Z",
"__v": 0
}
I used https://app.quicktype.io/ to create my model and successfully parsed. How ever, when I tried to print the name of my route inside of my routes's list a get that getter error.