zebra123 1.0.8 zebra123: ^1.0.8 copied to clipboard
Zebra Technologies RFID and Barcode Scanner Plugin. Integrates both the Zebra RFID API3 and Datawedge into a single Flutter Plugin.
example/lib/main.dart
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:zebra123/zebra123.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({super.key});
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
Zebra123? zebra123;
ZebraConnectionStatus connectionStatus = ZebraConnectionStatus.disconnected;
List<Barcode> barcodes = [];
List<RfidTag> tags = [];
@override
void initState() {
zebra123 = Zebra123(callback: callback);
super.initState();
}
@override
Widget build(BuildContext context) {
List<Widget> children = [];
Widget connectBtn;
if (zebra123?.connectionStatus == ZebraConnectionStatus.connected) {
connectBtn = FloatingActionButton(backgroundColor: Colors.lightGreenAccent, onPressed: () => zebra123?.disconnect(), child: Text("Disconnect", style: TextStyle(color: Colors.black, fontSize: 20)));
} else {
connectBtn = FloatingActionButton(backgroundColor: Colors.redAccent.shade100, onPressed: () => zebra123?.connect(), child: Text("Connect", style: TextStyle(color: Colors.black, fontSize: 20)));
}
connectBtn = Row(mainAxisAlignment: MainAxisAlignment.children: [SizedBox(width: 200, height: 50, child: connectBtn)]);
children.add(connectBtn);
List<Widget> results = [];
for (var barcode in this.barcodes) {
Widget tile = ListTile(title: Text("Barcode: ${barcode.barcode}"), subtitle: Text("Format: ${barcode.format} Date: ${barcode.seen}"), leading: Icon(Icons.barcode_reader),);
results.add(tile);
}
for (var tag in this.tags) {
Widget tile = ListTile(title: Text("Tag: ${tag.id}"), subtitle: Text("Rssi: ${tag.rssi}"), leading: Icon(Icons.barcode_reader),);
results.add(tile);
}
children.addAll(results);
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Zebra123 Plugin Example'),
),
body: SingleChildScrollView(scrollDirection: Axis.vertical, child: Column(children: children, mainAxisSize: MainAxisSize.min)),
),
);
}
void callback(ZebraInterfaces source, ZebraEvents event, dynamic data) {
switch (event) {
case ZebraEvents.readBarcode:
barcodes.clear();
if (data is List<Barcode>) {
for (Barcode barcode in data) {
barcodes.add(barcode);
if (kDebugMode) print("Source: $source Barcode: ${barcode.barcode} Format: ${barcode.format} Date: ${barcode.seen}");
}
}
setState((){});
break;
case ZebraEvents.readRfid:
tags.clear();
if (data is List<RfidTag>) {
for (RfidTag tag in data) {
tags.add(tag);
if (kDebugMode) print("Source: $source Tag: ${tag.id} Rssi: ${tag.rssi}");
}
}
setState((){});
break;
case ZebraEvents.error:
if (data is Error) {
if (kDebugMode) print("Source: $source Error: ${data.message}");
}
break;
case ZebraEvents.connectionStatus:
if (data is ConnectionStatus) {
if (kDebugMode) print("Source: $source ConnectionStatus: ${data.status}");
}
if (data.status != connectionStatus) {
setState(() {
connectionStatus = data.status;
});
}
break;
default:
if (kDebugMode) {
if (kDebugMode) print("Source: $source Unknown Event: $event");
}
}
}
}