Currently I am rewriting my supabase backend to laravel app with custom API's.
In the rewrite I am using data types from flutterflow and so far it has been great.
Problem:
I have a typical api like so:
/api/locations/[id]/tournaments <-- this returns a set of tournaments for the queried location.
If there is a tournament then this will be mapped to the data type.
Code below is a typical api return which has tournaments to return.
{
"data": [
{
"id": "5SbXAehBY5V8",
"title": "Nam est quia quod velit sunt asperiores.",
"sex": "Man",
"date": "2005-10-26T00:00:00.000000Z",
"game_type": "701",
"game_mode": "Single",
"address": {
"id": "j4hLRF6i5CHZ",
"street_address": "90649 Lind Ridges",
"house_number": "3492",
"postalcode": "03038",
"city": "Aydenview",
"province": "Georgia",
"country": "Japan",
"maps_url": "https://kuhic.com/sunt-ipsam-quia-ut-et-nisi-id.html",
"longitude": "80.9826970",
"latitude": "86.1809210",
"country_code": "NL"
},
"tournament_type": {
"id": 2,
"name": "701"
},
"tournament_mode": {
"id": 1,
"name": "Single"
},
"tournament_status": {
"id": 5,
"name": "Afgelast"
}
}
],
"links": {
"first": "https://example.com/api/locations/nzDup1Ib6V3J/tournaments?page=1",
"last": "https://example.com/api/locations/nzDup1Ib6V3J/tournaments?page=1",
"prev": null,
"next": null
},
"meta": {
"current_page": 1,
"from": 1,
"last_page": 1,
"links": [
{
"url": null,
"label": "« Previous",
"active": false
},
{
"url": "https://example.com/api/locations/nzDup1Ib6V3J/tournaments?page=1",
"label": "1",
"active": true
},
{
"url": null,
"label": "Next »",
"active": false
}
],
"path": "https://example.com/api/locations/nzDup1Ib6V3J/tournaments",
"per_page": 15,
"to": 1,
"total": 1
}
}
The listview i have gets populated correctly with the datatype tournament I have created.
But when the api request has no values i return a empty data array like so:
{
"data": [], <--- Issue is here because of datatype iterating
"links": {
"first": "https://example.com/api/locations/C1HZKXaPr5eA/tournaments?page=1",
"last": "https://example.com/api/locations/C1HZKXaPr5eA/tournaments?page=1",
"prev": null,
"next": null
},
"meta": {
"current_page": 1,
"from": null,
"last_page": 1,
"links": [
{
"url": null,
"label": "« Previous",
"active": false
},
{
"url": "https://example.com/api/locations/C1HZKXaPr5eA/tournaments?page=1",
"label": "1",
"active": true
},
{
"url": null,
"label": "Next »",
"active": false
}
],
"path": "https://example.com/api/locations/C1HZKXaPr5eA/tournaments",
"per_page": 15,
"to": null,
"total": 0
}
}
Now i get the error:
'type Null' is not a subtype of type 'iterable<TournamentStruct?>' in type cast.
The error is i think caused because there is no tournament data type to iterate over since the data:[] array is empty.
What would the typical way of handling this issue be in flutterflow? Looking at a solution that would not involve in alot of extra code on all the listviews that might have this issue.
Or would predefined json paths be better here?