createLiveDataSource static method

DataSource? createLiveDataSource()

Create a new live data source.

Creates a DataSource backed by live sensors. Use this when you need real-time sensor updates from the device.

Requires appropriate permissions to access device sensors.

Returns

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

Implementation

static DataSource? createLiveDataSource() {
  final String resultString = GemKitPlatform.instance.callCreateObject(
    jsonEncode(<String, Object>{
      'class': 'DataSourceContainer',
      'args': <String, String>{'type': 'live'},
    }),
  );
  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;
}