createExternalDataSource static method

DataSource? createExternalDataSource(
  1. List<DataType> dataTypes
)

Create a new external data source.

Creates a DataSource that obtains data from an external source. The caller must provide the list of data types that the external source will produce.

Parameters

  • dataTypes: The list of data types the external source provides. Must include DataType.position.

Returns

  • DataSource?: The created data source, or null if creation failed.

Implementation

static DataSource? createExternalDataSource(final List<DataType> dataTypes) {
  final List<int> intList = dataTypes
      .map((final DataType dataType) => dataType.id)
      .toList();
  final String resultString = GemKitPlatform.instance.callCreateObject(
    jsonEncode(<String, Object>{
      'class': 'DataSourceContainer',
      'args': <String, Object>{
        'availableDataType': intList,
        'type': 'external',
      },
    }),
  );
  final dynamic decodedVal = jsonDecode(resultString);

  final int gemApiError = decodedVal['gemApiError'];

  if (GemErrorExtension.isErrorCode(gemApiError)) {
    return null;
  }

  final DataSource retVal = DataSource.init(decodedVal['result']);
  return retVal;
}