Comment on page
Custom Data Type in Custom Code
You can also use custom data type in custom code using the Custom Function, Custom Widget, and Custom Action.
Below is an example of converting the JSON array into a list of a custom data type using a custom action (used here).

Custom action to convert JSON array to list of 'airline' data type
Here's the rundown of what's happening in the code:
- 1.The return value is set to List of Data Type of 'airline.'
- 2.Defined an argument with name 'jsonArray', which is a list of dynamic types representing a JSON array.
- 3.Inside the body of the code:
- For each item in the
jsonArray
, it calls thefromMap
constructor ofAirlineStruct
and adds the resulting object to thelistOfStruct
. - After iterating through all the items, the function returns the populated
listOfStruct
, which is a list of 'airline' data types.
Here's the custom action code:
Future<List<AirlineStruct>> convertJSONArrayToListOfStruct(
List<dynamic> jsonArray) async {
// convert json array into list of objects
List<AirlineStruct> listOfStruct = [];
for (var item in jsonArray) {
listOfStruct.add(AirlineStruct.fromMap(item));
}
return listOfStruct;
}
Last modified 5mo ago