startBackground static method
Implementation
static Future<void> startBackground(Map<String, dynamic> data) async {
final sendPort = data['send'] as SendPort;
try {
final rootToken = data['instance'] as RootIsolateToken?;
if (rootToken == null) {
sendPort.send({"res": false, "info": "RootIsolateToken is null"});
return;
}
BackgroundIsolateBinaryMessenger.ensureInitialized(rootToken);
const backgroundChannel = MethodChannel('turn_bartender');
final transferInfo = <String, dynamic>{
"btwPath": data['path'],
"info": data['info'],
"copyNum": data['copyNum'] as int,
"toPdf": data['toPdf'] as bool,
};
if (data['printerName'] != null &&
data['printerName'].toString().isNotEmpty) {
transferInfo['printerName'] = data['printerName'];
}
final result = await backgroundChannel.invokeMethod<Map>(
"printLabel",
transferInfo,
);
sendPort.send(_normalizeRawPrintResult(result));
} on PlatformException catch (e) {
sendPort.send({
"res": false,
"info": "PlatformException(${e.code}): ${e.message ?? 'unknown'}",
});
} catch (e) {
sendPort.send({"res": false, "info": "Background isolate exception: $e"});
}
}