Flutter version:
macbookpro@macbookpros-MacBook-Pro myproject2-flutter-app % flutter --version
Flutter 3.35.6 • channel stable • https://github.com/flutter/flutter.git
Tools • Dart 3.9.2 • DevTools 2.48.0
pubspec.yaml
dependencies:
sunmi_printer_plus: ^4.1.1
Tried:
await SunmiPrinter.initPrinter(); // deprecated
// and
final bool printerAvailable = await SunmiPrinter.bindingPrinter(); // deprecated,
// both deprecated
i have this solution working, but want to find a way without using deprecated methods?
Future<void> printListImages(List<Uint8List> listImages) async {
if (listImages.isEmpty) {
Notify.showWarn(
title: 'Printing Status',
message: 'No receipt found to print.',
);
return;
}
try {
// Try initializing printer — will fail gracefully if not a Sunmi device
await SunmiPrinter.initPrinter();
// If initialization succeeds, print images
for (Uint8List image in listImages) {
await SunmiPrinter.printImage(
image,
align: SunmiPrintAlign.CENTER,
);
}
await SunmiPrinter.cutPaper();
} on PlatformException catch (e) {
// Handle non-Sunmi devices or uninitialized printer service
if (e.message?.contains('sunmiPrinter has not been initialized') ?? false) {
Notify.showWarn(
title: 'Printing Status',
message: 'No Sunmi printer detected on this device.',
);
} else {
Notify.showError(
title: 'Printing Error',
message: 'Unable to print: ${e.message}',
);
}
} catch (e) {
// Catch-all for other unexpected errors
Notify.showError(
title: 'Printing Error',
message: 'Unexpected error: $e',
);
}
}
Flutter version:
pubspec.yaml
Tried:
i have this solution working, but want to find a way without using deprecated methods?