Code Monkey home page Code Monkey logo

esc-pos-printer-flutter's Introduction

ESC POS Printer for Flutter

Flutter plugin to connect and print on ESC POS Printers.

Installation

Use this package as a library

  1. Depend on it Add this to your package's pubspec.yaml file:
dependencies:
  escposprinter:
    git:
        url: https://github.com/marcusfelix/esc-pos-printer-flutter.git
        ref: master
  1. Install it You can install packages from the command line:

with Flutter:

$ flutter packages get

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

  1. Import it Now in your Dart code, you can use:
import 'package:flutter_webview_plugin/flutter_webview_plugin.dart';

Example

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

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

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

class _MyAppState extends State<MyApp> {
  List devices = [];
  bool connected = false;

  @override
  initState() {
    super.initState();
    _list();
  }

  _list() async {
    List returned;
    try {
      returned = await Escposprinter.getUSBDeviceList;
    } on PlatformException {
      //response = 'Failed to get platform version.';
    }
    setState((){
      devices = returned;
    });
  }

  _connect(int vendor, int product) async {
    bool returned;
    try {
      returned = await Escposprinter.connectPrinter(vendor, product);
    } on PlatformException {
      //response = 'Failed to get platform version.';
    }
    if(returned){
      setState((){
        connected = true;
      });
    }
  }

  _print() async {
    try {
      await Escposprinter.printText("Testing ESC POS printer...");
    } on PlatformException {
      //response = 'Failed to get platform version.';
    }
  }

  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      home: new Scaffold(
        appBar: new AppBar(
          title: new Text('ESC POS'),
          actions: <Widget>[
            new IconButton(
              icon: new Icon(Icons.refresh), 
              onPressed: () {
                _list();
              }
            ),
            connected == true ? new IconButton(
              icon: new Icon(Icons.print), 
              onPressed: () {
                _print();
              }
            ) : new Container(),
          ],
        ),
        body: devices.length > 0 ? new ListView(
          scrollDirection: Axis.vertical,
          children: _buildList(devices),
        ) : null,
      ),
    );
  }

  List<Widget> _buildList(List devices){
    return devices.map((device) => new ListTile(
      onTap: () {
        _connect(int.parse(device['vendorid']), int.parse(device['productid']));
      },
      leading: new Icon(Icons.usb),
      title: new Text(device['manufacturer'] + " " + device['product']),
      subtitle: new Text(device['vendorid'] + " " + device['productid']),
    )).toList();
  }
}

esc-pos-printer-flutter's People

Contributors

dewmal avatar kechankrisna avatar marcusfelix avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

esc-pos-printer-flutter's Issues

Bluetooth Pairing Request

when I accept PAIR from notification.it disconnect automatically and show below error.
E/flutter (31836): [ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: PlatformException(not connect, state not right, null, null)
E/flutter (31836): #0 StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:582:7)
E/flutter (31836): #1 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:159:18)
E/flutter (31836):
E/flutter (31836): #2 MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:332:12)
E/flutter (31836): #3 BluetoothPrint.printReceipt (package:bluetooth_print/bluetooth_print.dart:141:14)
E/flutter (31836): #4 _MyAppState.build. (package:test_another_library/main.dart:157:48)
E/flutter (31836):
E/flutter (31836): #5 _MyAppState.build. (package:test_another_library/main.dart)
E/flutter (31836): #6 _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:993:19)
E/flutter (31836): #7 _InkResponseState.build. (package:flutter/src/material/ink_well.dart:1111:38)
E/flutter (31836): #8 GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:183:24)
E/flutter (31836): #9 TapGestureRecognizer.handleTapUp (package:flutter/src/gestures/tap.dart:598:11)
E/flutter (31836): #10 BaseTapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:287:5)
E/flutter (31836): #11 BaseTapGestureRecognizer.handlePrimaryPointer (package:flutter/src/gestures/tap.dart:222:7)
E/flutter (31836): #12 PrimaryPointerGestureRecognizer.handleEvent (package:flutter/src/gestures/recognizer.dart:476:9)
E/flutter (31836): #13 PointerRouter._dispatch (package:flutter/src/gestures/pointer_router.dart:77:12)
E/flutter (31836): #14 PointerRouter._dispatchEventToRoutes. (package:flutter/src/gestures/pointer_router.dart:122:9)
E/flutter (31836): #15 _LinkedHashMapMixin.forEach (dart:collection-patch/compact_hash.dart:377:8)
E/flutter (31836): #16 PointerRouter._dispatchEventToRoutes (package:flutter/src/gestures/pointer_router.dart:120:18)
E/flutter (31836): #17 PointerRouter.route (package:flutter/src/gestures/pointer_router.dart:106:7)
E/flutter (31836): #18 GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:358:19)
E/flutter (31836): #19 GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:338:22)
E/flutter (31836): #20 RendererBinding.dispatchEvent (package:flutter/src/rendering/binding.dart:267:11)
E/flutter (31836): #21 GestureBinding._handlePointerEvent (package:flutter/src/gestures/binding.dart:295:7)
E/flutter (31836): #22 GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:240:7)
E/flutter (31836): #23 GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:213:7)
E/flutter (31836): #24 _rootRunUnary (dart:async/zone.dart:1206:13)
E/flutter (31836): #25 _CustomZone.runUnary (dart:async/zone.dart:1100:19)
E/flutter (31836): #26 _CustomZone.runUnaryGuarded (dart:async/zone.dart:1005:7)
E/flutter (31836): #27 _invoke1 (dart:ui/hooks.dart:265:10)

How print qr code with this library?

Hi, you have done very good job with this library. But i can't understand how i can print a qr code.
I have Epson TM-T29II and your library works fine! Can you help me?

Compatibility with "esc_pos_printer" package

So this plugin works really well for usb connections but i want to use the Ticket structure in esc_pos_utils package (https://github.com/andrey-ushakov/esc_pos_utils).
I used the testTicket that is in the readme of the plugin and i did the following:

final ticket = await testTicket(); await Escposprinter.printRawData(base64Encode(ticket.bytes));

which threw the exception:

E/AndroidRuntime(27173): FATAL EXCEPTION: Thread-8 E/AndroidRuntime(27173): Process: <Flutter project name>, PID: 27173 E/AndroidRuntime(27173): java.lang.NullPointerException: Attempt to invoke virtual method 'byte[] java.lang.String.getBytes()' on a null object reference E/AndroidRuntime(27173): at android.util.Base64.decode(Base64.java:119) E/AndroidRuntime(27173): at br.com.samhaus.escposprinter.adapter.USBPrinterAdapter$3.run(USBPrinterAdapter.java:192)

Plugin works for simple .printText() operations so i assume it is configured correctly.

Am I doing something wrong or is there a bug here?
Thanks.

Throws error [uses a deprecated version of the Android embedding]

The plugin escposprinter uses a deprecated version of the Android embedding.
To avoid unexpected runtime failures, or future build failures, try to see if this plugin supports the Android V2 embedding. Otherwise, consider removing it since a future release of Flutter will remove these deprecated APIs.
If you are plugin author, take a look at the docs for migrating the plugin to the V2 embedding: https://flutter.dev/go/android-plugin-migration.

Fail to pass parameter to printRawData

There is a bug at escposprinter.dart when cause printRawData error. The parameter name doesn't match.

static Future printRawData(String text) async {
Map<String, dynamic> params = {"raw": text};
final bool returned = await _channel.invokeMethod('printRawData', params);
return returned;
}

Auto Cut

hello sir, i would like to know is there any code for auto cut print?

Build issue after flutter upgrade

Hello everyone and thank you for keeping this package up to date.

I recently upgraded flutter in one of my projects that uses this package but the build is now breaking with the following message.

E/GeneratedPluginRegistrant(17354): 	at io.flutter.embedding.engine.plugins.util.GeneratedPluginRegister.registerGeneratedPlugins(GeneratedPluginRegister.java:80)
E/GeneratedPluginRegistrant(17354): 	at io.flutter.embedding.engine.FlutterEngine.<init>(FlutterEngine.java:355)
E/GeneratedPluginRegistrant(17354): 	at io.flutter.embedding.engine.FlutterEngine.<init>(FlutterEngine.java:263)
E/GeneratedPluginRegistrant(17354): 	at io.flutter.embedding.engine.FlutterEngine.<init>(FlutterEngine.java:243)
E/GeneratedPluginRegistrant(17354): 	at io.flutter.embedding.engine.FlutterEngine.<init>(FlutterEngine.java:163)
E/GeneratedPluginRegistrant(17354): 	at io.flutter.plugins.firebase.messaging.FlutterFirebaseMessagingBackgroundExecutor.lambda$startBackgroundIsolate$0$FlutterFirebaseMessagingBackgroundExecutor(FlutterFirebaseMessagingBackgroundExecutor.java:167)
E/GeneratedPluginRegistrant(17354): 	at io.flutter.plugins.firebase.messaging.-$$Lambda$FlutterFirebaseMessagingBackgroundExecutor$XbAhdPvj3YfytSw4YC4mSEzUFHw.run(Unknown Source:8)
E/GeneratedPluginRegistrant(17354): 	at android.os.Handler.handleCallback(Handler.java:883)
E/GeneratedPluginRegistrant(17354): 	at android.os.Handler.dispatchMessage(Handler.java:100)
E/GeneratedPluginRegistrant(17354): 	at android.os.Looper.loop(Looper.java:214)
E/GeneratedPluginRegistrant(17354): 	at android.app.ActivityThread.main(ActivityThread.java:7356)
E/GeneratedPluginRegistrant(17354): 	at java.lang.reflect.Method.invoke(Native Method)
E/GeneratedPluginRegistrant(17354): 	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
E/GeneratedPluginRegistrant(17354): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)

The issue may be arising because the PluginRegistry.Registrar is deprecated. We might want to upgrade it it support the new Android APIs. I have seen the upgrade steps here https://docs.flutter.dev/development/packages-and-plugins/plugin-api-migration but I have no experience working with plugins.

Any help fixing this issue will be much appreciated. Thank you again

issue with release build

Execution failed for task ':escposprinter:verifyReleaseResources'.

A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
Android resource linking failed
C:\Users\coder.gradle\caches\transforms-2\files-2.1\a528b13ac93e64cafa3d0480e2c93207\core-1.1.0\res\values\values.xml:142:5-173:25: AAPT: error: resource android:attr/fontVariationSettings not found.

 C:\Users\coder\.gradle\caches\transforms-2\files-2.1\a528b13ac93e64cafa3d0480e2c93207\core-1.1.0\res\values\values.xml:142:5-173:25: AAPT: error: resource android:attr/ttcIndex not found.

Could you please add installation instruction for flutter?

For example:
Use this package as a library

  1. Depend on it
    Add this to your package's pubspec.yaml file:

dependencies:
flutter_webview_plugin: ^0.3.0+2

  1. Install it
    You can install packages from the command line:

with Flutter:

$ flutter packages get

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

  1. Import it
    Now in your Dart code, you can use:

import 'package:flutter_webview_plugin/flutter_webview_plugin.dart';

Please provide an example for printing RAW data

Would you be so kind to give an example how to use ths printRawData() function or provide an example of how to markup the to be printend text or graphics, ideally with ESC POS commands.

Thank you!

Build issue

Pls migrate to android x, this library not able to build now.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.