Electronic scale integration for iMin POS devices (Android 13+).
Add to your pubspec.yaml:
dependencies:
imin_hardware_plugin: ^1.0.0Then run:
flutter pub getimport 'package:imin_hardware_plugin/imin_hardware_plugin.dart';The plugin exports IminScaleNew class for electronic scale operations (Android 13+).
- Connect to scale service
- Real-time weight data streaming
- Zero and tare operations
- Price calculation
- Unit conversion
- Device information and diagnostics
bool success = await IminScaleNew.connectService();String version = await IminScaleNew.getServiceVersion();String version = await IminScaleNew.getFirmwareVersion();bool success = await IminScaleNew.getData();bool success = await IminScaleNew.cancelGetData();StreamSubscription<ScaleEvent> subscription = IminScaleNew.eventStream.listen((event) {
if (event.isWeight) {
final data = event.data as ScaleWeightData;
print('Net: ${data.net} kg');
print('Tare: ${data.tare} kg');
print('Stable: ${data.isStable}');
} else if (event.isStatus) {
final status = event.data as ScaleStatusData;
print('Overload: ${status.overload}');
print('Light weight: ${status.isLightWeight}');
} else if (event.isPrice) {
final price = event.data as ScalePriceData;
print('Unit price: ${price.unitPrice}');
print('Total price: ${price.totalPrice}');
} else if (event.isError) {
print('Error code: ${event.data}');
} else if (event.isConnection) {
final conn = event.data as ScaleConnectionData;
print('Connected: ${conn.connected}');
}
});await IminScaleNew.zero();await IminScaleNew.tare();await IminScaleNew.digitalTare(100); // Tare 100gawait IminScaleNew.setUnitPrice('9.99');await IminScaleNew.setUnit(ScaleUnit.kg);Available units:
ScaleUnit.g- GramsScaleUnit.g100- 100 gramsScaleUnit.g500- 500 gramsScaleUnit.kg- Kilograms
// Read accelerometer data
List<int> accelData = await IminScaleNew.readAcceleData();
// Read seal state
int sealState = await IminScaleNew.readSealState();
// Get calibration status
int calStatus = await IminScaleNew.getCalStatus();
// Get calibration info
List<List<int>> calInfo = await IminScaleNew.getCalInfo();
// Restart scale
await IminScaleNew.restart();class ScaleWeightData {
final double net; // Net weight in kg
final double tare; // Tare weight in kg
final bool isStable; // Weight is stable
}class ScaleStatusData {
final bool overload; // Scale overloaded
final bool isLightWeight; // Weight too light
final bool clearZeroErr; // Zero error
final bool calibrationErr; // Calibration error
}class ScalePriceData {
final String unitPrice; // Unit price
final String totalPrice; // Total price
final String unitName; // Unit name
}import 'package:imin_hardware_plugin/imin_hardware_plugin.dart';
class ScaleExample extends StatefulWidget {
@override
_ScaleExampleState createState() => _ScaleExampleState();
}
class _ScaleExampleState extends State<ScaleExample> {
bool _isConnected = false;
bool _isGettingData = false;
ScaleWeightData? _currentWeight;
StreamSubscription<ScaleEvent>? _subscription;
@override
void initState() {
super.initState();
_listenToEvents();
_connectService();
}
@override
void dispose() {
_subscription?.cancel();
IminScaleNew.cancelGetData();
super.dispose();
}
void _listenToEvents() {
_subscription = IminScaleNew.eventStream.listen((event) {
if (event.isWeight) {
setState(() => _currentWeight = event.data as ScaleWeightData);
} else if (event.isConnection) {
final conn = event.data as ScaleConnectionData;
setState(() => _isConnected = conn.connected);
}
});
}
Future<void> _connectService() async {
final success = await IminScaleNew.connectService();
if (success) {
await Future.delayed(Duration(milliseconds: 500));
_startGetData();
}
}
Future<void> _startGetData() async {
final success = await IminScaleNew.getData();
setState(() => _isGettingData = success);
}
Future<void> _stopGetData() async {
await IminScaleNew.cancelGetData();
setState(() => _isGettingData = false);
}
@override
Widget build(BuildContext context) {
return Column(
children: [
Text('Connected: $_isConnected'),
Text('Getting Data: $_isGettingData'),
if (_currentWeight != null) ...[
Text('Net: ${_currentWeight!.net.toStringAsFixed(3)} kg'),
Text('Tare: ${_currentWeight!.tare.toStringAsFixed(3)} kg'),
Text('Stable: ${_currentWeight!.isStable ? "✓" : "~"}'),
],
ElevatedButton(
onPressed: _isConnected ? () => IminScaleNew.zero() : null,
child: Text('Zero'),
),
ElevatedButton(
onPressed: _isConnected ? () => IminScaleNew.tare() : null,
child: Text('Tare'),
),
],
);
}
}- Requires Android 13 or higher
- Connect to service before operations
- Weight data streams continuously when active
- Stop getting data when not needed
- Handle errors appropriately
iMin devices with electronic scale support (Android 13+)