tianbo_reader_plugin 0.0.4
tianbo_reader_plugin: ^0.0.4 copied to clipboard
天波台式终端D2身份证读卡插件
example/lib/main.dart
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:tianbo_reader_plugin/tianbo_plugin.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({super.key});
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
final _tianboPlugin = TianboPlugin();
String text = '读卡器未打开';
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Plugin example app'),
),
body: SingleChildScrollView(
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text('result: $text'),
ElevatedButton(
onPressed: () async {
var result = await _tianboPlugin.openReader();
if (result) {
text = '读卡器已打开';
} else {
text = '读卡器打开失败';
}
setState(() {});
},
child: const Text('打开读卡器'),
),
ElevatedButton(
onPressed: () async {
await _tianboPlugin.closeReader();
setState(() {
text = '读卡器已关闭';
});
},
child: const Text('关闭读卡器'),
),
ElevatedButton(
onPressed: () async {
var result = await _tianboPlugin.isOpen();
if (result) {
text = '当前状态:打开';
} else {
text = '当前状态:关闭';
}
setState(() {});
},
child: const Text('当前读卡器状态'),
),
ElevatedButton(
onPressed: () async {
var result = await _tianboPlugin.readCard();
if (result != null) {
text = jsonEncode(result);
} else {
text = '读卡失败';
}
setState(() {});
},
child: const Text('读卡'),
),
],
),
),
),
),
);
}
}