connect method

Future connect({
  1. Duration? timeout = const Duration(seconds: 5),
})
override

connect let you connect to a bluetooth printer

Implementation

Future connect({Duration? timeout = const Duration(seconds: 5)}) async {
  try {
    if (Platform.isAndroid) {
      Map<String, dynamic> params = {
        "address": printer.address,
        "isBle": false,
        "autoConnect": true
      };
      await flutterPrinterChannel.invokeMethod('onStartConnection', params);
    } else if (Platform.isIOS) {
      Map<String, dynamic> params = {
        "name": printer.name,
        "address": printer.address
      };
      await iosChannel.invokeMethod('connect', params);
    }
  } catch (e) {
    if ((e as dynamic).message == "already connected") {
      await disconnect();
      await connect();
    } else
      return Future.error(e.toString());
  }
}