pda_barcode_scan 0.0.1 copy "pda_barcode_scan: ^0.0.1" to clipboard
pda_barcode_scan: ^0.0.1 copied to clipboard

监听pda广播

example/lib/main.dart

import 'package:pda_barcode_scan/barcode_scan_util.dart';
import 'package:flutter/material.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 barcodeContent = "";

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

    /// 初始化时监听广播
    _onListen();
  }

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

    /// 离开时销毁
    _onCancel();
  }

  void _onListen() {
    BarcodeScanUtil.instance.listen((value) {
      setBarcodeContent(value);
    });
  }

  void _onCancel() {
    BarcodeScanUtil.instance.cancel();
  }

  void setBarcodeContent(String value) {
    setState(() {
      barcodeContent = value;
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('监听PDA广播模式'),
        ),
        body: Center(
          child: Column(
            children: [
              const SizedBox(
                height: 30,
              ),
              Text('条码内容$barcodeContent'),
              const SizedBox(
                height: 30,
              ),
              ElevatedButton(
                onPressed: () {
                  _onListen();
                },
                child: const Text('开始监听'),
              ),
              ElevatedButton(
                onPressed: () {
                  _onCancel();
                },
                child: const Text('停止监听'),
              ),
            ],
          ),
        ),
      ),
    );
  }
}
1
likes
110
pub points
44%
popularity

Publisher

unverified uploader

监听pda广播

Repository (GitHub)
View/report issues

Documentation

API reference

License

Apache-2.0 (LICENSE)

Dependencies

flutter

More

Packages that depend on pda_barcode_scan