rfid 0.0.8 copy "rfid: ^0.0.8" to clipboard
rfid: ^0.0.8 copied to clipboard

outdated

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(
      initialRoute: "first",
      routes: {
        "first": (context) => Scaffold(
              appBar: AppBar(
                title: const Text('Plugin example app'),
              ),
              body: const MyHomePage(title: 'Test'),
            ),
        "second": (context) => Scaffold(
              appBar: AppBar(
                title: const Text('Plugin example app'),
                actions: [
                  IconButton(
                      onPressed: () {
                        Navigator.popAndPushNamed(context, "first");
                      },
                      icon: const Icon(Icons.back_hand))
                ],
              ),
              body: const SizedBox(),
            )
      },
    );
  }
}

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;
  String? _serialNumber;
  final _rfidpluginPlugin = RfidPlugin();
  String? _batteryHealth;

  @override
  void initState() {
    _getBatteryLevel();
    _rfidpluginPlugin.deviceConnectionChangeStream.listen((event) {
      _getBatteryLevel();
    });
    super.initState();
  }

  void scanBarCode() async {
    await _rfidpluginPlugin.scanBarCode();
  }

  void _getBatteryLevel() async {
    try {
      final connectedDevices = await _rfidpluginPlugin.getAvailableDevices();

      String? serialNumber = "";

      if (connectedDevices.isNotEmpty) {
        serialNumber = connectedDevices.first.serialNumber;
      }

      final RfidConnectionResult connectionResult =
          await _rfidpluginPlugin.connectDevice(serialNumber: serialNumber);

      final status = await _rfidpluginPlugin.getDeviceConnectionStatus(
          serialNumber: serialNumber);

      debugPrint(status.toString());

      final batteryHealth = await _rfidpluginPlugin.getBatteryHealth();

      setState(() {
        _connectionResult = connectionResult;
        _serialNumber = serialNumber;
        _connectedDevices = connectedDevices.length.toString();
        _batteryHealth = batteryHealth.battery.toString();
      });
    } on PlatformException catch (_) {
      setState(() {});
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: <Widget>[
          Text(
            'Active Device ${_serialNumber ?? 'No Active Device'}',
          ),
          Text(
            'Connection Status ${_connectionResult?.connectionResult.toString()}',
          ),
          Text(
            'Connected Devices count ${_connectedDevices ?? 'No Devices Connected'}',
          ),
          Text(
            'Connected Device battery health ${_batteryHealth ?? 'No Devices Connected'}',
          ),
          ElevatedButton(
            onPressed: () {
              Navigator.popAndPushNamed(context, "second");
            },
            child: const Text('Navigate to second screen'),
          ),
          ElevatedButton(
            onPressed: scanBarCode,
            child: const Text('Scan BarCode'),
          ),
          ElevatedButton(
            onPressed: () async {
              final status = await _rfidpluginPlugin.getDeviceConnectionStatus(
                  serialNumber: "1128-IN-001022");

              debugPrint(status.toString());
            },
            child: const Text('Get device connection status'),
          ),
          ElevatedButton(
            onPressed: () async {
              final result = await _rfidpluginPlugin.getBatteryHealth();

              debugPrint(result.toString());
            },
            child: const Text('Get device battery status'),
          ),
          IconButton(
              onPressed: () async {
                await _rfidpluginPlugin.disconnect();
              },
              icon: const Icon(Icons.error)),
        ],
      ),
    );
  }
}
6
likes
0
points
45
downloads

Publisher

unverified uploader

Weekly Downloads

RFID scanner plugin for integration in flutter applications. Package currently supports IOS platforms

License

unknown (license)

Dependencies

flutter, json_annotation, plugin_platform_interface

More

Packages that depend on rfid

Packages that implement rfid