Flutter ESC-POS Utils Encode Turkish Characters(Invalid Character Problem)

727 Views Asked by At

I am developing a mobile app and that app prints invoices from bluetooth printer. So I imported "esc_pos_utils" and "bluetooth_thermal_printer" packages into pubspec.yaml file.

App can print invoices from printer with some Turkish characters like "çÇ" and "öÖ" but when I type other characters like "ıİ","ğĞ","şŞ" an exception thrown in the console like;

E/flutter (31974): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: Invalid argument (string): Contains invalid characters.: "FAALİYET RAPORU"
E/flutter (31974): #0      _UnicodeSubsetEncoder.convert (dart:convert/ascii.dart:85:9)
E/flutter (31974): #1      Latin1Codec.encode (dart:convert/latin1.dart:40:46)
E/flutter (31974): #2      Generator._encode (package:esc_pos_utils/src/generator.dart:77:21)
E/flutter (31974): #3      Generator.text (package:esc_pos_utils/src/generator.dart:354:9)

I have tried codeTable:"CP857" and codeTable:"CP1252" in PosStyles() widget but that didn't work.

Have you encountered this situation before?

If you encountered it before and solved,how did you solved this.

1

There are 1 best solutions below

1
BEKHRUZ KHOSHIMOV On
    bytes += generator.setGlobalCodeTable("CP866");
bytes.addAll(generator.row([
       PosColumn(
         textEncoded: await getEncoded('Автоматизация ресторанов'),
         width: 12,
         styles: const PosStyles(align: PosAlign.center),
       )
     ]));
Future<Uint8List> getEncoded(String text) async {
     final encoded = await CharsetConverter.encode("CP866", text);
     return encoded;
   }

charset_converter: ^2.1.2

Create your own code table using this package