t6_pos_printer_plugin 0.0.5 copy "t6_pos_printer_plugin: ^0.0.5" to clipboard
t6_pos_printer_plugin: ^0.0.5 copied to clipboard

A Flutter plugin to enable printing on the Topwise T6 POS device.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:t6_pos_printer_plugin/t6_pos_printer_plugin.dart';

void main() => runApp(MyApp());

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  // Function to initialize the printer
  Future<void> initializePrinter() async {
    try {
      await T6PosPrinterPlugin.printerInit();
    } catch (e) {
      throw Exception('Failed to initialize printer: $e');
    }
  }

  Future<void> _printImage(width, height) async {
    try {
      // Load the image as a byte array (replace with your image asset path)
      ByteData imageData = await rootBundle.load('assets/images/print_bitmap.png');
      Uint8List bytes = imageData.buffer.asUint8List();

      // Call the printBitmap method
      await T6PosPrinterPlugin.addBitmap(bytes, width, height);
    } catch (e) {
      throw Exception('Failed to print bitmap: $e');
    }
  }

  Future<void> addReceiptText() async {
    // initialize printer
    await initializePrinter();
    // add image to print template
    await _printImage(120, 120);
    // add text data to print template
    await T6PosPrinterPlugin.addText("\n\n", 24, "LEFT");
    await T6PosPrinterPlugin.addText("--------------------------------", 24, "CENTER");
    await T6PosPrinterPlugin.addText("Receipt", 30, "CENTER", bold: true, underline: false, letterSpacing: 2, lineSpacing: 2);
    await T6PosPrinterPlugin.addText("--------------------------------", 24, "CENTER");
    await T6PosPrinterPlugin.addText("\n\n", 24, "LEFT");
    await T6PosPrinterPlugin.addTwoTexts(
        "DATE:", 22, "LEFT", false, false, false, 5, 2,   // First text
        "${DateTime.now().day}/${DateTime.now().month}/${DateTime.now().year}", 22, "RIGHT", false, false, false, 5, 2,
      1, 1// Second text
    );
    await T6PosPrinterPlugin.addTwoTexts(
        "TIME:", 22, "LEFT", false, false, false, 5, 2,   // First text
        "${DateTime.now().hour}:${DateTime.now().minute}:${DateTime.now().second}", 22, "RIGHT", false, false, false, 5, 2,
        1, 1//// Second text
    );
    await T6PosPrinterPlugin.addTwoTexts(
        "AMOUNT:", 22, "LEFT", false, false, false, 5, 2,   // First text
        "K200.00", 22, "RIGHT", false, false, false, 5, 2,
        1, 1//// Second text
    );
    await T6PosPrinterPlugin.addTwoTexts(
        "CUSTOMER:", 22, "LEFT", false, false, false, 5, 2,   // First text
        "John Banda", 22, "RIGHT", false, false, false, 5, 2,
        1, 1//// Second text
    );
    await T6PosPrinterPlugin.addTwoTexts(
        "CITY:", 22, "LEFT", false, false, false, 5, 2,   // First text
        "LUSAKA", 22, "RIGHT", false, false, false, 5, 2,
        1, 1//// Second text
    );
    await T6PosPrinterPlugin.addTwoTexts(
        "DISTRICT:", 22, "LEFT", false, false, false, 5, 2,  // First text
        "LUSAKA", 22, "RIGHT", false, false, false, 5, 2,
        1, 1//// Second text
    );
    await T6PosPrinterPlugin.addTwoTexts(
        "TRANSACTION ID:", 22, "LEFT", false, false, false, 5, 2,  // First text
        "TXN1234567890", 22, "RIGHT", false, false, true, 5, 2,
        2, 1//// Second text
    );
    await T6PosPrinterPlugin.addText("\n\n", 24, "LEFT");
    await T6PosPrinterPlugin.addText("--------------------------------", 24, "CENTER");
    await T6PosPrinterPlugin.addText("THANK YOU.", 24, "CENTER");
    await T6PosPrinterPlugin.addText("--------------------------------", 24, "CENTER");
    await T6PosPrinterPlugin.addText("", 24, "LEFT");
    await T6PosPrinterPlugin.addText("", 24, "LEFT");
    await T6PosPrinterPlugin.addText("", 24, "LEFT");
    await T6PosPrinterPlugin.addText("\n\n", 24, "LEFT");
    // Print the receipt after all text has been added
    await T6PosPrinterPlugin.printReceipt();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(title: const Text('POS Printer Plugin')),
        body: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              ElevatedButton(
                onPressed: addReceiptText,
                child: const Text("Print Receipt"),
              ),
            ],
          ),
        ),
      ),
    );
  }
}
1
likes
0
points
0
downloads

Publisher

unverified uploader

Weekly Downloads

A Flutter plugin to enable printing on the Topwise T6 POS device.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on t6_pos_printer_plugin

Packages that implement t6_pos_printer_plugin