zebra123 1.0.6 zebra123: ^1.0.6 copied to clipboard
Zebra Technologies RFID and Barcode Scanner Plugin. Integrates both the Zebra RFID API3 and Datawedge into a single Flutter Plugin.
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;
@override
void initState() {
zebra123 = Zebra123(callback: callback);
super.initState();
}
@override
Widget build(BuildContext context) {
var connectBtn = OutlinedButton(onPressed: () => zebra123?.connect(), child: const Text("Connect"));
var disconnectBtn = OutlinedButton(onPressed: () => zebra123?.disconnect(), child: const Text("Disconnect"));
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Zebra123 Plugin Example'),
),
body: Center(
child: Column(mainAxisSize: MainAxisSize.min, children: [connectBtn, disconnectBtn]),
),
),
);
}
void callback(ZebraInterfaces source, ZebraEvents event, dynamic data) {
switch (event) {
case ZebraEvents.readBarcode:
if (data is List<Barcode>) {
for (Barcode barcode in data) {
print("Source: $source Barcode: ${barcode.barcode} Format: ${barcode.format} Date: ${barcode.seen}");
}
}
break;
case ZebraEvents.readRfid:
if (data is List<RfidTag>) {
for (RfidTag tag in data) {
print("Source: $source Tag: ${tag.id} Rssi: ${tag.rssi}");
}
}
break;
case ZebraEvents.error:
if (data is Error) {
print("Source: $source Error: ${data.message}");
}
break;
case ZebraEvents.connectionStatus:
if (data is ConnectionStatus) {
print("Source: $source ConnectionStatus: ${data.status}");
}
break;
default:
if (kDebugMode) {
print("Source: $source Unknown Event: $event");
}
}
}
}