Skip to main content

z92_pos_printer_flutter_sdk 1.0.1 copy "z92_pos_printer_flutter_sdk: ^1.0.1" to clipboard
z92_pos_printer_flutter_sdk: ^1.0.1 copied to clipboard

Android plugin for ZCS Z92 and Z91 built-in POS printers. Print text, columns, images, Code 128 barcodes, and QR codes.

example/lib/main.dart

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

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

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

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

class _MyAppState extends State<MyApp> {
  final _printer = PrinterPosSystem();
  bool _printing = false;
  String _status = 'Run on a ZCS Z92 or Z91 with paper loaded.';

  Future<void> _runPrint(Future<bool?> Function() operation) async {
    if (_printing) return;
    setState(() {
      _printing = true;
      _status = 'Printing…';
    });
    String status;
    try {
      status = await operation() == true
          ? 'SDK reported success. Check the printed output.'
          : 'Printing failed. Check paper, temperature, and device logs.';
    } on PlatformException catch (error) {
      status = 'Platform error: ${error.code}';
    } on MissingPluginException {
      status = 'This example requires the Android ZCS printer plugin.';
    }
    if (!mounted) return;
    setState(() {
      _printing = false;
      _status = status;
    });
  }

  Future<bool> _printReceipt() async {
    // Stop at the first failure. A retry could duplicate a partially printed sale.
    final operations = <Future<bool?> Function()>[
      () => _printer.printText(
            text: 'Z92 DEMO STORE',
            alignment: AlignmentPrint.center,
            isBold: true,
            fontSize: 24,
          ),
      () => _printer.printLine(fontSize: 16),
      () => _printer.print3Column(
            textLeft: 'Item',
            textCenter: 'Qty',
            textRight: 'Price',
            spaceLeft: 60,
            spaceCenter: 15,
            spaceRight: 25,
            isBold: true,
          ),
      () => _printer.print3Column(
            textLeft: 'Coffee',
            textCenter: '2',
            textRight: '6.00',
            spaceLeft: 60,
            spaceCenter: 15,
            spaceRight: 25,
          ),
      () => _printer.print2Column(
            textLeft: 'TOTAL',
            textRight: '6.00',
            isBold: true,
          ),
      () => _printer.printText(
            text: 'Thank you!',
            alignment: AlignmentPrint.center,
            fontSize: 18,
          ),
      () => _printer.printSpace(space: 3),
    ];
    for (final operation in operations) {
      if (await operation() != true) return false;
    }
    return true;
  }

  Future<bool?> _printImage() async {
    final asset = await rootBundle.load('asset/a4-print-test.png');
    return _printer.printImage(
      pathImage:
          asset.buffer.asUint8List(asset.offsetInBytes, asset.lengthInBytes),
    );
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(title: const Text('Z92 printer example')),
        body: ListView(
          padding: const EdgeInsets.all(16),
          children: [
            Text(_status),
            const SizedBox(height: 16),
            ElevatedButton(
              onPressed: _printing ? null : () => _runPrint(_printReceipt),
              child: const Text('Print sample receipt'),
            ),
            ElevatedButton(
              onPressed: _printing
                  ? null
                  : () => _runPrint(() => _printer.printQRCode(
                        text: 'Z92-DEMO-001',
                        width: 200,
                        height: 200,
                      )),
              child: const Text('Print QR code'),
            ),
            ElevatedButton(
              onPressed: _printing
                  ? null
                  : () => _runPrint(() => _printer.printBarCode128(
                        text: '1234567890',
                        width: 300,
                        height: 80,
                      )),
              child: const Text('Print Code 128'),
            ),
            ElevatedButton(
              onPressed: _printing ? null : () => _runPrint(_printImage),
              child: const Text('Print asset image'),
            ),
          ],
        ),
      ),
    );
  }
}
0
likes
0
points
160
downloads

Publisher

unverified uploader

Weekly Downloads

Android plugin for ZCS Z92 and Z91 built-in POS printers. Print text, columns, images, Code 128 barcodes, and QR codes.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on z92_pos_printer_flutter_sdk

Packages that implement z92_pos_printer_flutter_sdk