brasizza / sunmi_printer

BSD 3-Clause "New" or "Revised" License
39 stars 46 forks source link

Using SunmiStyle doesn't work as expected #38

Closed FrenkyDema closed 2 years ago

FrenkyDema commented 2 years ago
SunmiPrinter.printText(
        'Payment receipt',
        style: SunmiStyle(
                fontSize: SunmiFontSize.XS,
                bold: true,
                align: SunmiPrintAlign.CENTER
        )
)},

This code dosn't print the expected styled string but print only bold string

FrenkyDema commented 2 years ago

Example:

void printText() {
    SunmiPrinter.startTransactionPrint(true);
    SunmiPrinter.printText("Test",
        style: SunmiStyle(
            fontSize: SunmiFontSize.XS,
            bold: true,
            align: SunmiPrintAlign.CENTER));
    SunmiPrinter.exitTransactionPrint(true);

    SunmiPrinter.line();
    SunmiPrinter.lineWrap(2);
  }

Print result is :

---------------------------------

Test

Test is not bold, not align, not XS; and is printed after the line and lineWrap

brasizza commented 2 years ago

Are you using the V2s ? my other device was working very good

FrenkyDema commented 2 years ago

Are you using the V2s ? my other device was working very good

Yes, i'm on V2s

FrenkyDema commented 2 years ago

I tried with the new package update but obviously it didn't change the result. It appears as if styled printText calls are executed last, as if they were put on hold and executed last

FrenkyDema commented 2 years ago

ok I found the problem, that is, the lack of await in front of the function, so the code after calling printText() continued and did not wait for it to finish so that the printText function was apparently executed last

Code solution:

void printText() {
    SunmiPrinter.startTransactionPrint(true);
    await SunmiPrinter.printText("Test",  // there is the missing await
        style: SunmiStyle(
            fontSize: SunmiFontSize.XS,
            bold: true,
            align: SunmiPrintAlign.CENTER));
    SunmiPrinter.exitTransactionPrint(true);

    SunmiPrinter.line();
    SunmiPrinter.lineWrap(2);
}

Print result is :

Test  

  ---------------------------------