bluetooth_scanner_gun

蓝牙连接扫描枪获取数据

关于

此插件主要解决flutter蓝牙外接物理输入设备,获取数据时弹出软键盘的问题

开始使用

添加此插件到你的 pubspec.yaml 文件中

dependencies:
  bluetooth_scanner_gun: ^0.0.2

如何使用

混入ScanGunMixin,实现onScanCode(dynamic code)方法,code就是扫码获得的数据

import 'package:bluetooth_scanner_gun/mixin.dart';
import 'package:flutter/material.dart';

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

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

class _MyAppState extends State<MyApp> with ScanGunMixin<MyApp> {
  String _code = "";// 扫码数据

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Container(
          decoration: BoxDecoration(border: Border.all(color: Colors.grey)),
          child: Center(
            child: Text("扫码结果:$_code"),
          ),
        ),
      ),
    );
  }

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

  @override
  void onScanCode(dynamic code) {
    // TODO: implement onScanCode
    print("扫码到数据:$code");
    setState(() {
      _code = code;
    });
  }
}

Libraries

bluetooth_scanner_gun
mixin