pda_scan 0.1.0 pda_scan: ^0.1.0 copied to clipboard
A new Flutter plugin.
import 'package:flutter/material.dart';
import 'package:pda_scan/pda_scan.dart';
void main() => runApp(MyApp());
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
String result = " 没有显示内容";
PdaScan pdaScan;
@override
void initState() {
super.initState();
if(mounted){
initScan();
}
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Plugin example app'),
),
body: Center(
child: Column(
children: <Widget>[
FlatButton(
child: Text('扫描'),
onPressed: () async {
bool isPDA = await pdaScan.isPDA;
if(isPDA){
setState(() {
result = '是PDA';
});
}else{
setState(() {
result = '不是PDA';
});
}
},
),
Text(result)
],
)),
),
);
}
void initScan() {
pdaScan = PdaScan();
pdaScan.onScanResult.listen(_onEvent, onError: _onError);
}
void _onEvent(Object event) {
print("返回成功的数据" + event.toString());
print("PDA 结果是:" + event);
setState(() {
result = event.toString();
});
}
void _onError(Object error) {
print("扫描错误的信息" + error.toString());
setState(() {
result = error.toString();
});
}
}