instance property

Future<AudioSession> instance

The singleton instance across all Flutter engines.

Implementation

static Future<AudioSession> get instance async {
  if (_instance == null) {
    _instance = AudioSession._();
    try {
      // TODO: Use this code without the '?' once a Dart bug is fixed.
      // (similar instances occur elsewhere)
      //Map? data = await _channel.invokeMethod<Map>('getConfiguration');
      final data =
          await _channel.invokeMapMethod<String, dynamic>('getConfiguration');
      if (data != null) {
        _instance!._configuration = AudioSessionConfiguration.fromJson(data);
      }
    } catch (e) {
      // Unsupported platform, so default to null.
      // TODO: We should at least try share the config between isolates on the
      // Dart side.
    }
  }
  return _instance!;
}