writeBytes method

  1. @override
Future writeBytes(
  1. List<int> bytes, {
  2. Duration? timeout = const Duration(milliseconds: 20),
})
override

writeBytes let you write raw list int data into socket

Implementation

@override
Future writeBytes(
  List<int> bytes, {
  Duration? timeout = const Duration(milliseconds: 20),
}) async {
  try {
    if (Platform.isAndroid) {
      final bluetooth = DragoBluePrinter.instance;
      // DragoBluePrinter likely has writeBytes. If not, this will fail at runtime or analysis.
      // Based on typical structure of such plugins.
      await bluetooth.writeBytes(Uint8List.fromList(bytes));
    } else if (Platform.isIOS) {
      Map<String, Object> args = Map();
      args['bytes'] = bytes;
      args['length'] = bytes.length;
      iosChannel.invokeMethod('writeData', args);
    }
  } catch (e) {
    return Future.error(e.toString());
  }
}