flutter_zebra_scale 1.0.13
flutter_zebra_scale: ^1.0.13 copied to clipboard
Flutter plugin for Zebra Scale SDK
flutter_zebra_scale #
A Flutter plugin for integrating Zebra Scanner SDK (v2.6.25.0) to connect, control, and interact with Zebra barcode scanners and scales on Android.
Features #
-
Scanner Connection Management
- Connect/disconnect to scanners by ID
- Get list of available scanners
- Get list of active (connected) scanners
- Enable/disable scanner detection
- Enable/disable Bluetooth scanner discovery
-
Scale Operations
- Enable/disable scale
- Read weight (single reading)
- Live weight reading (continuous updates)
- Zero scale
- Reset scale
-
Barcode Scanning
- Real-time barcode scanning events
- Barcode data and type information
- Scanner ID tracking
-
Event Streaming
- Scanner appeared/disappeared events
- Connection/disconnection events
- Barcode scan events
- Firmware update events
- Configuration update events
- Image/video/binary data events
Requirements #
- Flutter SDK:
>=3.3.0 - Dart SDK:
^3.9.2 - Android:
minSdk 24(Android 7.0+) - Zebra Scanner SDK:
v2.6.25.0(included as AAR)
Installation #
Add this to your package's pubspec.yaml file:
dependencies:
flutter_zebra_scale:
path: ../flutter_zebra_scale # or use git/pub.dev URL
Android Setup #
- Place the AAR file in your app's libs directory:
Copy the barcode_scanner_library_v2.6.25.0-release.aar file to your app's android/app/libs/ directory.
- Add the AAR dependency to your app's
build.gradle:
The plugin uses compileOnly for the AAR to avoid AGP 8+ restrictions. You MUST add the AAR dependency explicitly in your app's android/app/build.gradle file.
Add this to your android/app/build.gradle:
repositories {
flatDir {
dirs 'libs' // Your app's libs directory where the AAR is located
}
}
dependencies {
// Zebra Scanner SDK - required for the plugin
implementation(name: 'barcode_scanner_library_v2.6.25.0-release', ext: 'aar')
// ... your other dependencies
}
Important Notes:
- The AAR file must be in your app's
android/app/libs/directory - The plugin uses
compileOnlyfor the AAR, so it won't be bundled with the plugin - You must add the AAR dependency in your app's
build.gradleas shown above - For the example project, the AAR should be in
example/android/app/libs/directory
- Add required permissions to your
AndroidManifest.xml:
<uses-permission android:name="android.permission.BLUETOOTH"
android:maxSdkVersion="30" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"
android:maxSdkVersion="30" />
<uses-permission android:name="android.permission.BLUETOOTH_SCAN"
android:usesPermissionFlags="neverForLocation" />
<uses-permission android:name="android.permission.BLUETOOTH_ADVERTISE" />
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.VIBRATE" />
- For Android 12+ (API 31+), you may need to request runtime permissions for Bluetooth.
Usage #
Initialize the SDK #
import 'package:flutter_zebra_scale/flutter_zebra_scale.dart';
final flutterZebraScale = FlutterZebraScale();
// Initialize the SDK (optional - auto-initializes on plugin attach)
await flutterZebraScale.initialize();
Connect to a Scanner #
// Connect to scanner with ID 123
bool success = await flutterZebraScale.connect(123);
if (success) {
print('Connected successfully');
}
Get Available Scanners #
final result = await flutterZebraScale.getAvailableScanners();
final scanners = result['scanners'] as List;
print('Found ${result['count']} scanners');
for (var scanner in scanners) {
print('Scanner ID: ${scanner['scannerID']}');
print('Name: ${scanner['scannerName']}');
print('Type: ${scanner['connectionTypeName']}');
print('Active: ${scanner['isActive']}');
}
Listen to Events #
flutterZebraScale.getEventStream().listen((event) {
final eventType = event['eventType'];
final data = event['data'] as Map<String, dynamic>;
switch (eventType) {
case 'barcode':
print('Barcode scanned: ${data['barcodeData']}');
print('Type: ${data['barcodeType']}');
print('Scanner ID: ${data['scannerID']}');
break;
case 'sessionEstablished':
print('Connected to: ${data['scannerName']}');
break;
case 'sessionTerminated':
print('Disconnected from scanner: ${data['scannerID']}');
break;
case 'scannerAppeared':
print('Scanner appeared: ${data['scannerName']}');
break;
}
});
Scale Operations #
// Enable scale
await flutterZebraScale.enableScale(scannerId);
// Read weight once
final weightData = await flutterZebraScale.readWeight(scannerId);
print('Weight: ${weightData?['weight']} ${weightData?['weightMode']}');
print('Status: ${weightData?['statusText']}');
// Start live weight reading (updates every second)
await flutterZebraScale.startLiveWeight(scannerId);
// Zero the scale
await flutterZebraScale.zeroScale(scannerId);
// Reset the scale
await flutterZebraScale.resetScale(scannerId);
// Disable scale
await flutterZebraScale.disableScale(scannerId);
Disconnect from Scanner #
await flutterZebraScale.disconnect(scannerId);
API Reference #
Methods #
Connection Management
Future<bool> initialize()- Initialize the SDKFuture<bool> connect(int scannerId)- Connect to a scannerFuture<bool> disconnect(int scannerId)- Disconnect from a scannerFuture<Map<String, dynamic>> getAvailableScanners()- Get list of available scannersFuture<Map<String, dynamic>> getActiveScanners()- Get list of active scannersFuture<bool> enableScannersDetection(bool enable)- Enable/disable scanner detectionFuture<bool> enableBluetoothScannerDiscovery(bool enable)- Enable/disable Bluetooth discoveryFuture<Map<String, dynamic>> updateScannersList()- Refresh scanner list
Scale Operations
Future<bool> enableScale(int scannerId)- Enable scaleFuture<bool> disableScale(int scannerId)- Disable scaleFuture<Map<String, dynamic>?> readWeight(int scannerId)- Read weight onceFuture<bool> zeroScale(int scannerId)- Zero the scaleFuture<bool> resetScale(int scannerId)- Reset the scaleFuture<bool> startLiveWeight(int scannerId)- Start continuous weight readingFuture<bool> stopLiveWeight()- Stop continuous weight reading
Event Streaming
Stream<Map<String, dynamic>> getEventStream()- Get stream of SDK events
Event Types #
scannerAppeared- Scanner becomes availablescannerDisappeared- Scanner becomes unavailablesessionEstablished- Connection establishedsessionTerminated- Connection terminatedbarcode- Barcode scannedfirmwareUpdate- Firmware update eventauxScannerAppeared- Auxiliary scanner appearedconfigurationUpdate- Configuration updatedimage- Image receivedvideo- Video frame receivedbinaryData- Binary data received
Scanner Information #
Each scanner map contains:
scannerID(int) - Unique scanner identifierscannerName(String) - Scanner namescannerModel(String) - Scanner modelscannerSerialNumber(String) - Hardware serial numberconnectionType(int) - Connection type codeconnectionTypeName(String) - Human-readable connection typeisActive(bool) - Whether scanner is connectedisAutoReconnectionEnabled(bool) - Auto-reconnection status
Weight Data #
Weight reading returns:
weight(String) - Weight valueweightMode(String) - Unit (kg, lb, etc.)status(int) - Status code (0-6)statusText(String) - Human-readable status
Barcode Data #
Barcode event contains:
barcodeData(String) - Scanned barcode stringbarcodeType(int) - Barcode type codescannerID(int) - Scanner that scanned the barcode
Example #
See the example/ directory for a complete example app demonstrating all features.
Supported Connection Types #
- Bluetooth Classic (BT_NORMAL)
- Bluetooth Low Energy (BT_LE)
- USB SNAPI
- USB CDC
Troubleshooting #
AAR Dependency Not Found #
If you encounter errors like:
Could not find barcode_scanner_library_v2.6.25.0-release
Make sure you've added the code to find the plugin's libs directory and added the AAR dependency in your android/app/build.gradle file as shown in the Android Setup section.
Duplicate Class Errors #
If you encounter duplicate class errors like:
Duplicate class com.zebra.barcode.sdk.BarcodeScanner found in modules...
This usually means the AAR is being included multiple times. Make sure you only add it once in your app's build.gradle dependencies section.
Notes #
- The plugin automatically initializes the SDK when attached
- Scanner detection and Bluetooth discovery are enabled by default after initialization
- All operational modes (BT_NORMAL, SNAPI, BT_LE, USB_CDC) are enabled for maximum compatibility
- Events are streamed asynchronously via EventChannel
- Scale operations require the scanner to support scale functionality
License #
See LICENSE file for details.
Credits #
This plugin integrates the Zebra Scanner SDK v2.6.25.0 for Android.