network_pos_printer 1.1.7

network_pos_printer #

A dart/flutter package to send texts silently (with simple styles like underline, bold, justification, etc.) to a network ESC/POS printer.



It lets you send the data to the printer without previewing a document (usually thermal printers), with the ESC/POS script.

Here an example on how to send texts and cut the ticket:

  NetworkPOSPrinter.connect('192.168.81.80', 9100).then((printer) {

    printer.writeLineWithStyle('Test with style'.toUpperCase(),
        style: NetworkPOSPrinterStyle(
          justification: NetworkPOSPrinterJustification.center,
          width: NetworkPOSPrinterTextSize.size2,
          height: NetworkPOSPrinterTextSize.size2,
          font: NetworkPOSPrinterFont.fontB,
        ),
        linesAfter: 1);

    // total width of columns must be equal to 12
    printer.writeRow(<NetworkPOSColumn>[
      NetworkPOSColumn(
        text: 'left align',
        width: 6,
        style: NetworkPOSPrinterStyle(
            bold: true, justification: NetworkPOSPrinterJustification.left),
      ),
      NetworkPOSColumn(
        text: 'right align',
        width: 6,
        style: NetworkPOSPrinterStyle(
            bold: true, justification: NetworkPOSPrinterJustification.right),
      ),
    ]);

    printer.setBold(true);
    printer.writeLine('Test bold');

    printer.resetToDefault();

    printer.setInverse(true);
    printer.writeLine('Test inverse');

    printer.resetToDefault();

    printer.setUnderline(NetworkPOSPrinterUnderline.single);
    printer.writeLine('Test underline');

    printer.resetToDefault();

    printer.setJustification(NetworkPOSPrinterJustification.center);
    printer.writeLine('Test justification');

    printer.resetToDefault();

    printer.setFont(NetworkPOSPrinterFont.fontB);
    printer.writeLine('Test font');

    // space blanks before cut
    printer.writeLines(List.filled(5, ''));

    printer.cut();

    printer.close().then((v) {
      printer.destroy();
    });
  }).catchError((error) {
    print('error : $error');
  });

Some printers will not accept NetworkPOSPrinterUnderline.double, only a single weight will be printed.

TODO #

  • method documentation

Support #

If this package was helpful to you in delivering on your project or you just wanna to support this project, a cup of tea would be highly appreciated ;-)

Buy me a tea

[1.1.5] - [1.1.7] - 14th August 2019

  • writeRow(List of NetworkPOSColumn) method added
  • renaming, cleaning and refactoring of internal code
  • example and README updated

[1.1.4] - 19th June 2019

  • BREAKING CHANGE : setTextSize signature (from int to NetworkPOSTextSize)
  • BREAKING CHANGE : writeLine signature (now without default value)
  • writeLineWithStyle() method added to handle styles more easily
  • setFont method added
  • Update README
  • Update example
  • import dart:math removed

[0.1.5] - [0.1.6] - 18th June 2019

  • Upgrade version of Dart
  • Update README

[0.1.4] - 22th May 2019

  • README updated

[0.1.3] - 29th April 2019

  • License added

[0.1.2] - 29th April 2019

  • Update README.md
  • writeLines added

[0.1.1] - 29th April 2019

  • setTextSize added
  • writeAll added
  • Breaking change : NetworkPOSPrinterUnderline.single_weight => NetworkPOSPrinterUnderline.single
  • Breaking change : NetworkPOSPrinterUnderline.double_weight => NetworkPOSPrinterUnderline.double

[0.1.0] - 26th April 2019

Final version and example

[0.0.1] - [0.0.3] - 26th April 2019

  • Initial release with cut and simple styles
  • Refactor names and cleaning code
  • Documentation

example/main.dart

import 'package:network_pos_printer/network_pos_printer.dart';

main(List<String> arguments) {
  NetworkPOSPrinter.connect('192.168.81.80', 9100).then((printer) {
    printer.writeLineWithStyle('Test with style'.toUpperCase(),
        style: NetworkPOSPrinterStyle(
          justification: NetworkPOSPrinterJustification.center,
          width: NetworkPOSPrinterTextSize.size2,
          height: NetworkPOSPrinterTextSize.size2,
          font: NetworkPOSPrinterFont.fontB,
        ),
        linesAfter: 1);

    // total width of columns must be equal to 12
    printer.writeRow(<NetworkPOSColumn>[
      NetworkPOSColumn(
        text: 'left align',
        width: 6,
        style: NetworkPOSPrinterStyle(
            bold: true, justification: NetworkPOSPrinterJustification.left),
      ),
      NetworkPOSColumn(
        text: 'right align',
        width: 6,
        style: NetworkPOSPrinterStyle(
            bold: true, justification: NetworkPOSPrinterJustification.right),
      ),
    ]);

    printer.setBold(true);
    printer.writeLine('Test bold');

    printer.resetToDefault();

    printer.setInverse(true);
    printer.writeLine('Test inverse');

    printer.resetToDefault();

    printer.setUnderline(NetworkPOSPrinterUnderline.single);
    printer.writeLine('Test underline');

    printer.resetToDefault();

    printer.setJustification(NetworkPOSPrinterJustification.center);
    printer.writeLine('Test justification');

    printer.resetToDefault();

    printer.setFont(NetworkPOSPrinterFont.fontB);
    printer.writeLine('Test font');

    // space blanks before cut
    printer.writeLines(List.filled(5, ''));

    printer.cut();

    printer.close().then((v) {
      printer.destroy();
    });
  }).catchError((error) {
    print('error : $error');
  });
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  network_pos_printer: ^1.1.7

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:network_pos_printer/network_pos_printer.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
70
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
85
Learn more about scoring.

We analyzed this package on Sep 19, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.5.0
  • pana: 0.12.21
  • Flutter: 1.9.1+hotfix.2

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Health suggestions

Format lib/generated/i18n.dart.

Run flutter format to format lib/generated/i18n.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.2.0 <3.0.0
flutter 0.0.0
hex ^0.1.2 0.1.2
Transitive dependencies
collection 1.14.11 1.14.12
meta 1.1.7
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test