discoveryLoop method

Future<List> discoveryLoop(
  1. String type,
  2. int timeout
)

Implementation

Future<List> discoveryLoop(String type, int timeout) async {
  try {
    List version = await methodChannel.invokeMethod('discovery', {
      'type': type,
      'timeout': timeout,
    });
    if (version.isEmpty && rety < 5) {
      await Future.delayed(const Duration(seconds: 2));
      rety++;
      return await discoveryLoop(type, timeout);
    } else if (version.isEmpty && rety >= 5) {
      rety = 0;
      return await methodChannel.invokeMethod('openBluetoothSettings');
    } else {
      rety = 0;
      return version;
    }
  } catch (e) {
    rety = 0;
    return [];
  }
}