flutter_aclas_scale_plus 1.0.0
flutter_aclas_scale_plus: ^1.0.0 copied to clipboard
Flutter plugin for ACLAS weight scales over Serial, USB, and BLE. Connect, read weight (live or one-shot), zero, tare, and handle USB attach/detach.
flutter_aclas_scale_plus #
Flutter plugin for ACLAS weight scales over Serial, USB, and BLE.
Android setup (ACLAS SDK) #
The plugin uses the ACLAS scale SDK. You must add the SDK artifacts to the plugin's Android module:
-
Copy AclasScaleSdk.jar from the ACLAS demo app (e.g.
aclas/app/libs/AclasScaleSdk.jar) into:flutter_aclas_scale_plus/android/libs/Create the
libsfolder if it doesn't exist. -
Copy the jniLibs folder (native
.solibraries) from the ACLAS demo (e.g.aclas/app/src/main/jniLibs/) into:flutter_aclas_scale_plus/android/src/main/jniLibs/So you have
android/src/main/jniLibs/arm64-v8a/,armeabi-v7a/,x86/,x86_64/withlibAclasScaleLib.soin each. -
Verify native libs in the built APK (if the app crashes with
UnsatisfiedLinkErroror scale connect fails): after building (e.g.flutter build apk), check that the .so are included:unzip -l build/app/outputs/flutter-apk/app-release.apk | grep -E "lib/.*\.so"You should see entries like
lib/arm64-v8a/libAclasScaleLib.so. If missing, runflutter clean && flutter pub get && flutter build apkand check again.
Permissions #
The plugin's Android manifest declares Bluetooth and location permissions for BLE. For USB, the app may need to request USB permission when connecting (result -4 from openScale).
Usage #
import 'package:flutter_aclas_scale_plus/flutter_aclas_scale_plus.dart';
final scale = FlutterAclasScalePlus();
// 1) Init for connection type: serial, usb, or ble
await scale.initDevice(AclasConnectionType.serial);
// 2) Optional: get device list to choose path / index / address
final devices = await scale.getDeviceList();
// 3) Connect (path for serial, index for USB, address for BLE)
int result = await scale.openScale(path: '/dev/ttyUSB0');
// result: 0 = success, -4 = USB permission needed
// 4) Listen to events (connected, disconnected, usb_attached, usb_detached, weight, error)
scale.eventStream.listen((event) {
switch (event.type) {
case AclasScaleEventType.connected:
// connected
break;
case AclasScaleEventType.disconnected:
// disconnected
break;
case AclasScaleEventType.weight:
print(event.weightInfo?.weight);
break;
// ...
}
});
// 5) Live weight: start to receive continuous weight events; stop to disable
await scale.startLiveWeight();
// ... weight events arrive on eventStream ...
await scale.stopLiveWeight();
// 6) One-shot and commands
final connected = await scale.isConnected();
await scale.zero(); // zero the scale (weight must be stable)
await scale.tare(); // tare (weight must be stable)
final w = await scale.getWeight();
await scale.setTarePre(3); // preset tare value
await scale.setFrequency(0); // frequency index
// 7) Close when done
await scale.closeScale();
API summary #
| Method | Description |
|---|---|
initDevice(type) |
Initialize for serial, usb, or ble. |
getDeviceList() |
List of paths (serial), or addresses (BLE), etc. |
getConnectionType() |
Current connection type (serial / usb / ble) set by initDevice. |
openScale({path?, index?, address?}) |
Open connection. Returns 0 or -4 (USB permission). |
closeScale() |
Close connection. |
isConnected() |
Whether scale is connected. |
startLiveWeight() |
Start streaming weight on eventStream. |
startLiveWeightEnsuringConnection() |
If not connected, refresh device list and connect to first device, then start live weight. |
stopLiveWeight() |
Stop streaming weight. |
zero() |
Zero the scale. |
tare() |
Tare the scale. |
getWeight() |
Read current weight once. |
getWeightEnsuringConnection() |
If not connected, refresh device list and connect to first device, then read weight. |
setTarePre(value) |
Set preset tare (integer). |
setFrequency(index) |
Set frequency index. |
eventStream |
Stream of AclasScaleEvent (connected, disconnected, usb_attached, usb_detached, weight, error, crash). |
Events #
- connected – Scale connected.
- disconnected – Scale disconnected.
- usb_attached – USB device attached.
- usb_detached – USB device detached.
- weight – New weight (only when live weight is started); payload in
event.weightInfo. - error – Error;
errorCodeanderrorMessageset. - crash – Native plugin exception;
errorMessage,stackTrace,exceptionTypefor reporting (e.g. Crashlytics).
Reference #
Based on the ACLAS demo: InitDevice, OpenScale/CloseScale, live weight via onRcvData, zero/tare, readWeight, tare pre, frequency, and connection/USB events.
Publishing #
Before publishing to pub.dev (or a private registry):
- Set
versioninpubspec.yaml(e.g.1.0.0). - Update
CHANGELOG.mdfor the release. - Replace
homepageandrepositoryinpubspec.yamlwith your actual URLs. - Ensure ACLAS SDK artifacts are not shipped in the published package (they are optional; apps add them locally per README).
- Run
flutter pub publish --dry-runto check for issues, thenflutter pub publishwhen ready.