mjafartp / flutter_esc_pos_utils

Flutter package of esc/pos utils
GNU General Public License v3.0
21 stars 46 forks source link

Generator Row is not working as expected #25

Open rahul-yr opened 1 year ago

rahul-yr commented 1 year ago

Below is the code I have used.

 bytes += generator.row([
    PosColumn(
      text: 'Some text 1 + Some text 2',
      width: 3,
      styles: const PosStyles(align: PosAlign.left),
    ),
    PosColumn(
      text: '100',
      width: 6,
      styles: const PosStyles(align: PosAlign.center),
    ),
    PosColumn(
      text: '10000',
      width: 3,
      styles: const PosStyles(align: PosAlign.right),
    ),
  ]);

And this is the exception

E/flutter (22676): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: Exception: Only one parameter - text or textEncoded - should be passed
E/flutter (22676): #0      new PosColumn (package:flutter_esc_pos_utils/src/pos_column.dart:19:7)
E/flutter (22676): #1      Generator.row (package:flutter_esc_pos_utils/src/generator.dart:502:25)
E/flutter (22676): #2      fetchPrintData (package:ble_ff/esc_pos.dart:43:22)
E/flutter (22676): <asynchronous suspension>
E/flutter (22676): #3      _MyHomePageState.build.<anonymous closure>.<anonymous closure> (package:ble_ff/my_home_page.dart:137:40)
E/flutter (22676): <asynchronous suspension>
E/flutter (22676): 

Please share your thoughts on this.

ionLuca23 commented 1 year ago

Hi. I want to confirm the issue. I think the issue is related to PosColumn() constructor. If textEncoded not null we always get an Exception.

E-MRE commented 1 year ago

I found this code inside of the PosColumn:

if (text.isEmpty && textEncoded != null && textEncoded!.isNotEmpty) {
      throw Exception(
          'Only one parameter - text or textEncoded - should be passed');
 }

And generator doesn't set text variable. For this reason pos column throws exception.

naingolan commented 11 months ago

The answer is to add multiline:false after writing the posColumn array ,

bytes += generator.row([ PosColumn( text: 'Some text 1 + Some text 2', width: 3, styles: const PosStyles(align: PosAlign.left), ), PosColumn( text: '100', width: 6, styles: const PosStyles(align: PosAlign.center), ), PosColumn( text: '10000', width: 3, styles: const PosStyles(align: PosAlign.right), ), ], multiLine:false);

chairulf commented 11 months ago

https://pub.dev/packages/esc_pos_utils

use this package

SidouAbr commented 7 months ago

The answer is to add multiline:false after writing the posColumn array ,

bytes += generator.row([ PosColumn( text: 'Some text 1 + Some text 2', width: 3, styles: const PosStyles(align: PosAlign.left), ), PosColumn( text: '100', width: 6, styles: const PosStyles(align: PosAlign.center), ), PosColumn( text: '10000', width: 3, styles: const PosStyles(align: PosAlign.right), ), ], multiLine:false);

Its work for me, but it need to limit the length String