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

Plugin for communicate with network thermal printer

example/lib/main.dart

import 'package:esc_pos_utils/esc_pos_utils.dart';
import 'package:flutter/material.dart';
import 'dart:async';

import 'package:flutter/services.dart';
import 'package:network_printer_plugin/network_printer_plugin.dart';

void main() {
  runApp(const MyApp());
}

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

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

class _MyAppState extends State<MyApp> {

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Center(
          child: Text('Click Test Print Below'),
        ),
        bottomNavigationBar: Padding(
          padding: const EdgeInsets.all(16),
          child: ElevatedButton(
            onPressed: () async {
              final profile = await CapabilityProfile.load();
              var generator = Generator(PaperSize.mm80, profile);
              List<int> bytes = [];

              bytes += generator.text(
                  'Regular: aA bB cC dD eE fF gG hH iI jJ kK lL mM nN oO pP qQ rR sS tT uU vV wW xX yY zZ');
              bytes += generator.text('Special 1: àÀ èÈ éÉ ûÛ üÜ çÇ ôÔ',
                  styles: PosStyles(codeTable: 'CP1252'));
              bytes += generator.text('Special 2: blåbærgrød',
                  styles: PosStyles(codeTable: 'CP1252'));

              bytes += generator.text('Bold text', styles: PosStyles(bold: true));
              bytes += generator.text('Reverse text', styles: PosStyles(reverse: true));
              bytes += generator.text('Underlined text',
                  styles: PosStyles(underline: true), linesAfter: 1);
              bytes +=
                  generator.text('Align left', styles: PosStyles(align: PosAlign.left));
              bytes +=
                  generator.text('Align center', styles: PosStyles(align: PosAlign.center));
              bytes += generator.text('Align right',
                  styles: PosStyles(align: PosAlign.right), linesAfter: 1);

              bytes += generator.row([
                PosColumn(
                  text: 'col3',
                  width: 3,
                  styles: PosStyles(align: PosAlign.center, underline: true),
                ),
                PosColumn(
                  text: 'col6',
                  width: 6,
                  styles: PosStyles(align: PosAlign.center, underline: true),
                ),
                PosColumn(
                  text: 'col3',
                  width: 3,
                  styles: PosStyles(align: PosAlign.center, underline: true),
                ),
              ]);

              bytes += generator.text('Text size 200%',
                  styles: PosStyles(
                    height: PosTextSize.size2,
                    width: PosTextSize.size2,
                  ));

              // Print image:
              // final ByteData data = await rootBundle.load('assets/logo.png');
              // final Uint8List imgBytes = data.buffer.asUint8List();
              // final Image image = decodeImage(imgBytes)!;
              // bytes += generator.image(image);
              // Print image using an alternative (obsolette) command
              // bytes += generator.imageRaster(image);

              // Print barcode
              final List<int> barData = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 4];
              bytes += generator.barcode(Barcode.upcA(barData));

              // Print mixed (chinese + latin) text. Only for printers supporting Kanji mode
              // ticket.text(
              //   'hello ! 中文字 # world @ éphémère &',
              //   styles: PosStyles(codeTable: PosCodeTable.westEur),
              //   containsChinese: true,
              // );

              bytes += generator.feed(2);
              bytes += generator.cut();

              var printer = NetworkPrinter();
              await printer.connect("192.168.0.101", 9100);
              await printer.write(bytes);
              await printer.disconnect();
            }, 
            child: Text("Test Print")
          ),
        ),
      ),
    );
  }
}
0
likes
130
points
118
downloads

Publisher

unverified uploader

Weekly Downloads

Plugin for communicate with network thermal printer

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on network_printer_plugin

Packages that implement network_printer_plugin