sunmi_printer_v2 0.0.1+2 copy "sunmi_printer_v2: ^0.0.1+2" to clipboard
sunmi_printer_v2: ^0.0.1+2 copied to clipboard

unlistedoutdated

Printer Plugin for Sunmi V2.

example/lib/main.dart

import 'dart:async';

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

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

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

class _MyAppState extends State<MyApp> {
  String _serialNo = 'Unknown';

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

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initPlatformState() async {
    String serialNo;
    // Platform messages may fail, so we use a try/catch PlatformException.
    try {
      serialNo = await SunmiPrinterV2.getPrinterSerialNo;
    } on PlatformException {
      serialNo = 'Failed to get serial no.';
    }

    // If the widget was removed from the tree while the asynchronous platform
    // message was in flight, we want to discard the reply rather than calling
    // setState to update our non-existent appearance.
    if (!mounted) return;

    setState(() {
      _serialNo = serialNo;
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      theme: ThemeData(
        primarySwatch: Colors.orange,
      ),
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Sunmi Test app'),
        ),
        body: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Center(
              child: Text('Printer SN: $_serialNo\n'),
            ),
            ElevatedButton(
                onPressed: () async {
                  await SunmiPrinterV2.printSample();
                },
                child: Text("Print")),
            ElevatedButton(
                onPressed: () async {
                  await SunmiPrinterV2.feedPaper();
                },
                child: Text("Feed Paper")),
            ElevatedButton(
                onPressed: () async {
                  await SunmiPrinterV2.printBarcode(
                    barcode: "123456789012",
                    type: BarcodeType.ean_13,
                    textPosition: BarcodeTextPosition.noText,
                  );
                  await SunmiPrinterV2.feedPaper();
                },
                child: Text("Print Barcode"))
          ],
        ),
      ),
    );
  }
}
0
likes
0
pub points
0%
popularity

Publisher

verified publisherchathu.me

Printer Plugin for Sunmi V2.

Homepage

License

unknown (LICENSE)

Dependencies

flutter

More

Packages that depend on sunmi_printer_v2