Skip to content

Intermittent lateinit property sunmiPrinter has not been initialized error + inconsistency with rebindPrinter() #105

@EbubekirGuldal

Description

@EbubekirGuldal

Hello,

I sometimes encounter an error when printing with sunmi_printer_plus, but not every time.

❌ Observed error
PlatformException(error, lateinit property sunmiPrinter has not been initialized, null, ...)

This happens when I try to print an image on a Sunmi printer.

🧾 Code used

Future<void> printTicket(Uint8List imageBytes) async {
  await SunmiPrinter.bindingPrinter();
  await SunmiPrinter.initPrinter();

  final processed = _prepareForThermal(imageBytes);

  await SunmiPrinter.printImage(
    processed,
    align: SunmiPrintAlign.CENTER,
  );

  await SunmiPrinter.cutPaper();
}

⚠️ Behavior

The issue is intermittent:

  • sometimes printing works correctly
  • sometimes I get the exception saying that sunmiPrinter has not been initialized

This looks like a timing or service binding issue.

📦 Version used

From my package_config.json:

{
  "name": "sunmi_printer_plus",
  "rootUri": ".../sunmi_printer_plus-4.1.1"
}

So I am definitely using version 4.1.1.

❓ Issue with rebindPrinter()

The 4.1.1 changelog mentions the addition of rebindPrinter().

However:
SunmiPrinter.rebindPrinter() does not exist in the Dart API

Dart reports:
The method 'rebindPrinter' isn't defined for the type 'SunmiPrinter'

I confirmed that my project is using version 4.1.1
👉 So there seems to be an inconsistency between the changelog and the actual published code.

❓ Questions

  1. What is now the recommended way to properly initialize the printer?
  2. Since bindingPrinter() and initPrinter() are deprecated, what should be used instead?
  3. Is rebindPrinter() actually available? If yes, how should it be used?
  4. Should we wait for an explicit “ready” state before printing?
  5. Do you have an up-to-date example of the recommended initialization flow?

📌 Context

  • Sunmi device (Sunmi V3H)
  • image printing
  • intermittent issue

Thanks in advance.

Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions