dart_esc_pos_driver 0.0.2 copy "dart_esc_pos_driver: ^0.0.2" to clipboard
dart_esc_pos_driver: ^0.0.2 copied to clipboard

Connect the thermal printer and print data

dart_esc_pos_driver #

Connect the thermal printer and print data

example #

import 'package:dart_esc_pos_driver/api/printer.dart';
import 'package:dart_esc_pos_driver/dart_esc_pos_driver.dart';
import 'package:flutter/material.dart';

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

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

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

class _MyAppState extends State<MyApp> {
  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Native Packages'),
        ),
        body: ListView(
          children: [
            TextButton(
                onPressed: _getConsolePrinter, child: const Text("连接控制台打印机"))
          ],
        ),
      ),
    );
  }

  Future<void> _getConsolePrinter() async {
    try {
      print('开始连接打印机.');
      final consolePrinter = await LddNetworkDriver.open(host: "", port: 0);
      print(consolePrinter);
      final printer = await consolePrinter.openPrinter();
      print(printer);
      await printer.init();
      await printer.align(alignment: LddAlignment.center);
      await printer.qr(
        funCall: () {
          return const DartQrBuilder(size: 200, text: "hello");
        },
      );
      await printer.text(text: "hello 梁典典");
      await printer.feed(n: 4);
      await printer.cut();
      await printer.flush();
      print('结束');
    } catch (e, s) {
      print(e);
      print(s);
    }
  }
}

1
likes
130
points
28
downloads

Publisher

verified publisheritbug.shop

Weekly Downloads

Connect the thermal printer and print data

Repository (GitHub)

Documentation

API reference

License

BSD-3-Clause (license)

Dependencies

flutter, flutter_rust_bridge, plugin_platform_interface

More

Packages that depend on dart_esc_pos_driver