enable method

Enables the Bluetooth adapter on Android or opens the Bluetooth settings screen on iOS / macOS.

On iOS and macOS the returned value is always ActionResponse.openedIOSSettings because toggling the adapter programmatically is not allowed by the OS.

Implementation

Future<ActionResponse> enable() async {
  try {
    if (Platform.isAndroid) {
      return await bmAndroid.enable();
    } else if (Platform.isIOS) {
      await bmIOS.openBluetoothSettings();
      return ActionResponse.openedIOSSettings;
    } else if (Platform.isMacOS) {
      await bmMacOS.openBluetoothSettings();
      return ActionResponse.openedIOSSettings;
    } else {
      throw '[enable_bluetooth] platform_not_supported - only Android, iOS and macOS are supported';
    }
  } catch (e) {
    rethrow;
  }
}