drago_usb_printer 0.0.8 copy "drago_usb_printer: ^0.0.8" to clipboard
drago_usb_printer: ^0.0.8 copied to clipboard

PlatformAndroid

This plugin will allow develop send data and work with usb printer on android

example/lib/main.dart

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

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

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

class _MyAppState extends State<MyApp> {
  List<Map<String, dynamic>> devices = [];
  DragoUsbPrinter dragoUsbPrinter = DragoUsbPrinter();

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

  _getDevicelist() async {
    List<Map<String, dynamic>> results = [];
    results = await DragoUsbPrinter.getUSBDeviceList();

    print(" length: ${results.length}");
    setState(() {
      devices = results;
    });
  }

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

  List<Widget> _buildList(List<Map<String, dynamic>> devices) {
    return devices
        .map((device) => new ListTile(
              leading: new Icon(Icons.usb),
              title: new Text(
                  device['manufacturer'] + " " + device['productName']),
              subtitle:
                  new Text(device['vendorId'] + " " + device['productId']),
              trailing: new IconButton(
                  icon: new Icon(Icons.print),
                  onPressed: () async {
                    int vendorId = int.parse(device['vendorId']);
                    int productId = int.parse(device['productId']);
                    bool? isConnected =
                        await dragoUsbPrinter.connect(vendorId, productId);
                    if (isConnected ?? false) {
                      var data = Uint8List.fromList(utf8
                          .encode(" Hello world Testing ESC POS printer..."));
                      await dragoUsbPrinter.write(data);
                      await dragoUsbPrinter.close();
                    }
                  }),
            ))
        .toList();
  }
}
0
likes
140
pub points
67%
popularity

Publisher

unverified uploader

This plugin will allow develop send data and work with usb printer on android

Repository (GitHub)
View/report issues

Documentation

API reference

License

GPL-3.0 (LICENSE)

Dependencies

flutter

More

Packages that depend on drago_usb_printer