rfid 0.0.4
rfid: ^0.0.4 copied to clipboard
RFID scanner plugin for integration in flutter applications. Package currently supports IOS platforms
example/lib/main.dart
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:rfid/model/rifd_connection_result/rifd_connection_result.dart';
import 'package:rfid/rfid.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({super.key});
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
@override
void initState() {
super.initState();
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Plugin example app'),
),
body: const MyHomePage(title: 'Test'),
),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key, required this.title});
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
RfidConnectionResult? _connectionResult;
String? _connectedDevices;
final _rfidpluginPlugin = RfidPlugin();
@override
void initState() {
_getBatteryLevel();
super.initState();
}
void scanBarCode() async {
await _rfidpluginPlugin.scanBarCode();
}
void _getBatteryLevel() async {
try {
final connectedDevices = await _rfidpluginPlugin.getAvailableDevices();
final RfidConnectionResult connectionResult = await _rfidpluginPlugin
.connectDevice(serialNumber: connectedDevices[0].serialNumber);
setState(() {
_connectionResult = connectionResult;
_connectedDevices = connectedDevices.length.toString();
});
} on PlatformException catch (_) {
setState(() {});
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'Connection Status ${_connectionResult?.connectionResult.toString()}',
),
Text(
'Connected Devices ${_connectedDevices ?? 'No Devices Connected'}',
),
IconButton(onPressed: scanBarCode, icon: const Icon(Icons.scanner)),
],
),
),
);
}
}