flutter_sunmi_printer 0.2.1

  • Readme
  • Changelog
  • Example
  • Installing
  • new73

flutter_sunmi_printer #

Plugin allows to print thermal receipts using Sunmi device with a built-in printer. Tested on Sunmi V2.

Features #

  • text: print text with styles (bold, underline, align, font size)
  • row: print a row containing up to 12 columns (total columns width must be equal to 12)
  • image: print an image with alignment
  • hr: print full width separator
  • emptyLines: feed n lines
  • boldOn, boldOff
  • underlineOn, underlineOff

TODO #

  • Print QR codes
  • Print Barcodes

Getting Started #

import 'package:flutter_sunmi_printer/flutter_sunmi_printer.dart';

// Test regular text
SunmiPrinter.hr(); // prints a full width separator
SunmiPrinter.text(
    'Test Sunmi Printer',
    styles: SunmiStyles(align: SunmiAlign.center),
);
SunmiPrinter.hr();

// Test align
SunmiPrinter.text(
    'left',
    styles: SunmiStyles(bold: true, underline: true),
);
SunmiPrinter.text(
    'center',
    styles:
        SunmiStyles(bold: true, underline: true, align: SunmiAlign.center),
);
SunmiPrinter.text(
    'right',
    styles: SunmiStyles(bold: true, underline: true, align: SunmiAlign.right),
);

// Test text size
SunmiPrinter.text('Extra small text',
    styles: SunmiStyles(size: SunmiSize.xs));
SunmiPrinter.text('Medium text', styles: SunmiStyles(size: SunmiSize.md));
SunmiPrinter.text('Large text', styles: SunmiStyles(size: SunmiSize.lg));
SunmiPrinter.text('Extra large text',
    styles: SunmiStyles(size: SunmiSize.xl));

// Test row
SunmiPrinter.row(
    cols: [
        SunmiCol(text: 'col1', width: 4),
        SunmiCol(text: 'col2', width: 4, align: SunmiAlign.center),
        SunmiCol(text: 'col3', width: 4, align: SunmiAlign.right),
    ],
);

// Test image
ByteData bytes = await rootBundle.load('assets/rabbit_black.jpg');
final buffer = bytes.buffer;
final imgData = base64.encode(Uint8List.view(buffer));
SunmiPrinter.image(imgData);

SunmiPrinter.emptyLines(3);

0.2.1 #

  • Update README and example

0.2.0 #

  • New functions: boldOn/boldOff
  • New functions: underlineOn/underlineOff
  • New funtion: image
  • iOS doesn't throw an exception anymore

0.1.1 #

  • Using registerWith() to support the old pre-Flutter-1.12 Android projects

0.1.0 #

  • Initial release

example/lib/main.dart

import 'dart:typed_data';
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_sunmi_printer/flutter_sunmi_printer.dart';

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

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  void _print() async {
    // Test regular text
    SunmiPrinter.hr();
    SunmiPrinter.text(
      'Test Sunmi Printer',
      styles: SunmiStyles(align: SunmiAlign.center),
    );
    SunmiPrinter.hr();

    // Test align
    SunmiPrinter.text(
      'left',
      styles: SunmiStyles(bold: true, underline: true),
    );
    SunmiPrinter.text(
      'center',
      styles:
          SunmiStyles(bold: true, underline: true, align: SunmiAlign.center),
    );
    SunmiPrinter.text(
      'right',
      styles: SunmiStyles(bold: true, underline: true, align: SunmiAlign.right),
    );

    // Test text size
    SunmiPrinter.text('Extra small text',
        styles: SunmiStyles(size: SunmiSize.xs));
    SunmiPrinter.text('Medium text', styles: SunmiStyles(size: SunmiSize.md));
    SunmiPrinter.text('Large text', styles: SunmiStyles(size: SunmiSize.lg));
    SunmiPrinter.text('Extra large text',
        styles: SunmiStyles(size: SunmiSize.xl));

    // Test row
    SunmiPrinter.row(
      cols: [
        SunmiCol(text: 'col1', width: 4),
        SunmiCol(text: 'col2', width: 4, align: SunmiAlign.center),
        SunmiCol(text: 'col3', width: 4, align: SunmiAlign.right),
      ],
    );

    // Test image
    ByteData bytes = await rootBundle.load('assets/rabbit_black.jpg');
    final buffer = bytes.buffer;
    final imgData = base64.encode(Uint8List.view(buffer));
    SunmiPrinter.image(imgData);

    SunmiPrinter.emptyLines(3);
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Test Sunmi Printer'),
        ),
        body: Column(
          children: <Widget>[
            SizedBox(height: 50),
            Center(
              child: RaisedButton(
                onPressed: _print,
                child: const Text('Print demo', style: TextStyle(fontSize: 20)),
              ),
            ),
          ],
        ),
      ),
    );
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  flutter_sunmi_printer: ^0.2.1

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:flutter_sunmi_printer/flutter_sunmi_printer.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
47
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]
73
Learn more about scoring.

We analyzed this package on Jul 9, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.14
  • Flutter: 1.17.5

Analysis suggestions

Package does not support Flutter platform linux

Because:

  • package:flutter_sunmi_printer/flutter_sunmi_printer.dart that declares support for platforms: android, ios

Package does not support Flutter platform macos

Because:

  • package:flutter_sunmi_printer/flutter_sunmi_printer.dart that declares support for platforms: android, ios

Package does not support Flutter platform web

Because:

  • package:flutter_sunmi_printer/flutter_sunmi_printer.dart that declares support for platforms: android, ios

Package does not support Flutter platform windows

Because:

  • package:flutter_sunmi_printer/flutter_sunmi_printer.dart that declares support for platforms: android, ios

Package not compatible with SDK dart

Because:

  • flutter_sunmi_printer that is a package requiring null.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.7.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.12 1.14.13
meta 1.1.8 1.2.1
sky_engine 0.0.99
typed_data 1.1.6 1.2.0
vector_math 2.0.8 2.1.0-nullsafety
Dev dependencies
flutter_test