I am trying to display individual elements of a JSON data on a dynamic listview. However, I keep getting "type 'int' is not a subtype of type 'String'" error and I have no idea why.
The code works if I include just the left() function in the widget located under the Row in the buildFlightsColumn function. But once I include the middle() and right() functions, I get the error.
Widget buildListView() {
print(data);
return ListView.builder(
itemCount: data == null ? 0 : data.length,
itemBuilder: (context, index) {
return buildFlightsColumn(data[index]);
}
);
}
Widget buildFlightsColumn(dynamic item) => Container(
height: 150.0,
decoration: BoxDecoration(
),
child: new Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
left(item['PlaceId']),
middle(item['IataCode']),
right()
],
),
);
Container left(dynamic item) {
return new Container (
child: Text(
item,
textAlign: TextAlign.left,
style: TextStyle(
fontSize: 25.0,
color: Colors.red,
)
),
);
}
Container middle(dynamic item) {
return new Container(
child: Text(
item,
textAlign: TextAlign.left,
style: TextStyle(
fontSize: 25.0,
color: Colors.red,
)
),
);
}
Container right() {
return new Container(
child: RaisedButton(
onPressed: () {
},
child: Text('Book Flights'),
)
);
}
The data passed into the buildFlightsColumn function is JSON data returned by the API request:
[{PlaceId: 65368, IataCode: LAX, Name: Los Angeles International, Type: Station, SkyscannerCode: LAX, CityName: Los Angeles, CityId: LAXA, CountryName: United States}, {PlaceId: 81727, IataCode: SFO, Name: San Francisco International, Type: Station, SkyscannerCode: SFO, CityName: San Francisco, CityId: SFOA, CountryName: United States}]