zywell_printer 0.0.1 copy "zywell_printer: ^0.0.1" to clipboard
zywell_printer: ^0.0.1 copied to clipboard

A Flutter plugin project to support Zywell Printer

zywell_printer #

A new Flutter plugin project for connect to zywell printer.

Getting Started #

    import 'package:zywell_printer/zywell_printer.dart';

Methods #

Define the plugin in your class #

  final _zywellPrinterPlugin = ZywellPrinter();
  List<NetworkAddress> devices = [];

Get the list of available devices #

  Future<void> getDevices() async {
    /// 192.168.0.207 is the default ip of the printer
    /// You can change it to your local network ip, 
    /// SDK will scan the network and return the available devices
    _zywellPrinterPlugin.scanWifi((NetworkAddress addr) {
        print('Found device: ${addr.ip}');
        setState(() {
        devices.add(addr);
        });
    }, '192.168.0.207');
  }

Connect to the printer #

    bool isSuccess = await _zywellPrinterPlugin
        .connectIp(devices[index].ip);

Use this library to capture widget and convert it to image

    widgets_to_image: ^1.0.0

Define invoice with Flutter view #

  WidgetsToImage(
    controller: controller,
    child: const DemoInvoice(),
  ),

DemoInvoice is the widget that you want to print, demo code here. The widget must have background color/

  try{
    final d = await controller.capture();
    setState(() {
      bytes = d;
    });
    _zywellPrinterPlugin.printImage(
      image: d!,

      /// Độ rộng của hoá đơn
      invoiceWidth: 80,

      /// Độ dài của hoá đơn
      invoiceHeight: 160,

      /// Padding trái phải của ảnh
      gapWidth: 10,

      /// Padding trên dưới của ảnh
      gapHeight: 10,

      /// Độ rộng của ảnh dùng để in
      imageTargetWidth: 600);

  } catch (e) {
    print(e);
    print('Zywell Printer Plugin Error');
    print('Failed to print picture.');
  }
    List<PrintRowData> printData = [
    PrintRowData(content: 'Hello World', paddingToTopOfInvoice: 10),
    PrintRowData(content: 'Hello World', paddingToTopOfInvoice: 50),
    PrintRowData(content: 'Hello World', paddingToTopOfInvoice: 90),
    PrintRowData(content: 'Hello World', paddingToTopOfInvoice: 130),
    PrintRowData(content: 'Hello World', paddingToTopOfInvoice: 170), 
    PrintRowData(content: 'Hello World', paddingToTopOfInvoice: 170),
    ];
    // 50 and 80 is invoiceWidth and invoiceHeight
    await _zywellPrinterPlugin.printText(printData, 50, 80);
0
likes
130
points
25
downloads

Publisher

verified publisherthanhdt.dev

Weekly Downloads

A Flutter plugin project to support Zywell Printer

Homepage

Documentation

API reference

License

BSD-3-Clause (license)

Dependencies

all_bluetooth, flutter, ping_discover_network_plus, plugin_platform_interface

More

Packages that depend on zywell_printer