startLiveWeightEnsuringConnection method

  1. @override
Future<void> startLiveWeightEnsuringConnection()
override

If not connected, refreshes device list and opens scale with first device, then starts live weight.

Implementation

@override
Future<void> startLiveWeightEnsuringConnection() async {
  if (!(await isConnected())) {
    final list = await getDeviceList();
    final type = await getConnectionType();
    if (list.isNotEmpty) {
      if (type == AclasConnectionType.Serial) {
        await openScale(path: list.first);
      } else if (type == AclasConnectionType.USB) {
        await openScale(index: 0);
      } else {
        await openScale(address: list.first);
      }
    }
  }
  await startLiveWeight();
}