sunmi_flutter_helper 0.0.9 copy "sunmi_flutter_helper: ^0.0.9" to clipboard
sunmi_flutter_helper: ^0.0.9 copied to clipboard

PlatformAndroid

Flutter plugin for printing and scanning on Sunmi POS devices using PrinterX SDK.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:flutter/services.dart' show ByteData, Uint8List, rootBundle;
import 'package:sunmi_flutter_helper/sunmi_flutter_helper.dart';

void main() {
  runApp(const MaterialApp(home: MyHomePage()));
}

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

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  @override
  void initState() {
    super.initState();
    startListening();
  }

  void startListening() {
    SunmiFlutterHelper.nfcStream.listen((data) {
      print('📡 NFC Data: $data');
    });
    SunmiFlutterHelper.scanStream.listen((scannedCode) {
      print('🔍 Scanned: $scannedCode');
    });
  }

  Future<Uint8List> loadImageAsset(String path) async {
    final ByteData data = await rootBundle.load(path);
    return data.buffer.asUint8List();
  }

  void _printDemo() async {
    final isConnected = await SunmiFlutterHelper.isPrinterConnected();
    if (!isConnected) {
      print('❌ Printer not connected');
      return;
    }

    await SunmiFlutterHelper.printText(
      text: 'Welcome to Sunmi\n4Brains Technologies Pvt Ltd',
      align: 'center',
      size: 12,
    );

    await SunmiFlutterHelper.printLine(type: 'empty', height: 70);

    // Example: QR code
    await SunmiFlutterHelper.printQrCode(
      qrText: 'https://www.example.com',
      align: 'center',
      width: 100,
      height: 100,
      dot: 10,
    );

    //Example: Barcode
    await SunmiFlutterHelper.printBarcode(
      data: '987654321012',
      width: 300,
      height: 100,
      align: 'center',
      readable: "ONE",
    );

    //Example: Image
    final Uint8List logoBytes = await loadImageAsset('assets/images/logo.jpg');
    await SunmiFlutterHelper.printImage(
      image: logoBytes,
      align: 'center',
      width: 384,
    );

    //Example: Lines
    await SunmiFlutterHelper.printLine(type: 'dotted', height: 2);
    await SunmiFlutterHelper.printLine(type: 'solid', height: 4);

    // Example: Columns
    await SunmiFlutterHelper.printColumns(
      texts: ['Item', 'Qty', 'Price'],
      weights: [3, 1, 2],
      align: 'right',
    );

    await SunmiFlutterHelper.printColumns(
      texts: ['Bluetooth Speaker', '2', '₹4,000'],
      weights: [3, 1, 2],
      align: 'right',
    );

    await SunmiFlutterHelper.printLine(type: 'empty', height: 10);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('Sunmi Printer Demo')),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            ElevatedButton(
              onPressed: _printDemo,
              child: const Text('Print Demo'),
            ),
          ],
        ),
      ),
    );
  }
}
0
likes
140
points
5
downloads

Publisher

verified publisher4brains.in

Weekly Downloads

Flutter plugin for printing and scanning on Sunmi POS devices using PrinterX SDK.

Repository (GitHub)
View/report issues

Documentation

API reference

License

unknown (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on sunmi_flutter_helper

Packages that implement sunmi_flutter_helper