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).

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 the fromMap constructor of AirlineStruct and adds the resulting object to the listOfStruct.

    • 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) {
  return listOfStruct;

Last updated