print_usb 0.0.3 copy "print_usb: ^0.0.3" to clipboard
print_usb: ^0.0.3 copied to clipboard

PlatformWindows

Print bytes in usb windows

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:print_usb/model/usb_device.dart';
import 'package:print_usb/print_usb.dart';

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

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

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

class _MyAppState extends State<MyApp> {
  List<UsbDevice> devices = [];
  UsbDevice? _connectedDevice;

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('PrintUsb Plugin example app'),
        ),
        body: Center(
          child: Container(
            constraints: const BoxConstraints(maxWidth: 500),
            child: Column(
              children: [
                ElevatedButton(
                  onPressed: () async {
                    devices = await PrintUsb.getList();
                    setState(() {});
                  },
                  child: const Text('Get List'),
                ),
                Expanded(
                  child: ListView.builder(
                    itemCount: devices.length,
                    itemBuilder: (context, index) {
                      UsbDevice device = devices[index];
                      return ListTile(
                        onTap: () async {
                          bool result = await PrintUsb.connect(name: device.name);
                          if (result) {
                            _connectedDevice = device;
                            setState(() {});
                          }
                        },
                        title: Text(device.name),
                        subtitle: Text(device.model),
                        leading: Text(device.available.toString()),
                        trailing: _connectedDevice != null && _connectedDevice!.name == device.name
                            ? IconButton(
                                onPressed: () async {
                                  String paperFeed = '\x1B\x64\x04'; // x04 lines feed
                                  String cutPaper = '\x1D\x56\x00';
                                  if (device.available) {
                                    List<int> bytes = "Hello developer flutter $paperFeed $cutPaper".codeUnits;
                                    bool result = await PrintUsb.printBytes(bytes: bytes, device: device);
                                    if (result) {
                                      print("Printed");
                                    }
                                  } else {
                                    print("Device not available");
                                  }
                                },
                                icon: const Icon(Icons.print),
                              )
                            : const SizedBox(),
                      );
                    },
                  ),
                ),
              ],
            ),
          ),
        ),
      ),
    );
  }
}
1
likes
120
points
354
downloads

Publisher

unverified uploader

Weekly Downloads

Print bytes in usb windows

Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD-3-Clause (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on print_usb