scan static method

Provide list of bluetooth device, return as list of BlueDevice

Implementation

static Future<List<BlueDevice>> scan() async {
  List<BlueDevice> devices = <BlueDevice>[];
  if (Platform.isAndroid) {
    final blue_thermal.BlueThermalPrinter bluetoothAndroid =
        blue_thermal.BlueThermalPrinter.instance;
    final List<blue_thermal.BluetoothDevice> resultDevices =
        await bluetoothAndroid.getBondedDevices();
    devices = resultDevices
        .map(
          (blue_thermal.BluetoothDevice bluetoothDevice) => BlueDevice(
            name: bluetoothDevice.name ?? '',
            address: bluetoothDevice.address ?? '',
            type: bluetoothDevice.type,
          ),
        )
        .toList();
  }
  return devices;
}