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

PlatformAndroid

flutter plugin to access UFH handler triger.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:sunmi_uhf/sunmi_uhf.dart';

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

class MyApp extends StatefulWidget {
  const MyApp({Key? key}) : super(key: key);

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

class _MyAppState extends State<MyApp> {
  String? _result = 'Unknown';
  bool _isConnected = false;
  init() async {
    _isConnected = await SunmiUhf.init();
    if(_isConnected){
      SunmiUhf.onUhfScanned().listen((event) {
        if(event != null) {
          _result = event;
          setState(() {});
        }

      });
    }

  }

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

  @override
  void dispose() {
    SunmiUhf.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Sunmi uhf'),
        ),
        body: Center(
          child: !_isConnected ?
          ElevatedButton(onPressed: () async {
            _isConnected = await SunmiUhf.init();
            if(_isConnected){
              SunmiUhf.onUhfScanned().listen((event) {
                if(event != null) {
                  _result = event;
                  setState(() {});
                }

              });
            }
            setState(() {});
            }, child: const Text('failed to connect handler')):
          Text('Scan result: $_result\n'),
        ),
        floatingActionButton: Visibility(
          visible: _isConnected,
          child: FloatingActionButton(
            child: const Icon(Icons.scanner),
            onPressed: () async {
              _isConnected = await SunmiUhf.isConnect();
              if(!_isConnected) return;
              SunmiUhf.scan();
            },
          ),
        ),
      ),
    );
  }
}
0
likes
135
points
13
downloads

Publisher

unverified uploader

Weekly Downloads

flutter plugin to access UFH handler triger.

Documentation

API reference

License

MIT (license)

Dependencies

flutter

More

Packages that depend on sunmi_uhf

Packages that implement sunmi_uhf