imin_electronic_scale 0.0.3
imin_electronic_scale: ^0.0.3 copied to clipboard
A new flutter plugin project.
example/lib/main.dart
import 'package:flutter/material.dart';
import 'package:imin_electronic_scale/imin_electronic_scale.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
String? _weight;
String? _weightStatus;
IminElectronicScale _scale = IminElectronicScale();
@override
void initState() {
super.initState();
_scale.initElectronic();
_scale.setWeightInfoCallback((weight, weightStatus) {
_weight = weight;
_weightStatus = weightStatus;
if (mounted) setState(() {});
});
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('IminElectronicScale'),
),
body: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Text(
'weight: $_weight\n weightStatus: $_weightStatus',
textAlign: TextAlign.center,
),
ElevatedButton(
onPressed: () {
_scale.turnZero();
},
child: Text('Turn Zero')),
ElevatedButton(
onPressed: () {
_scale.manualPeel(100);
},
child: Text('Manual Peel 100g')),
ElevatedButton(
onPressed: () {
_scale.removePeel();
},
child: Text('Remove Peel')),
ElevatedButton(
onPressed: () {
_scale.closeElectronic();
},
child: Text('Close Electronic'))
],
),
),
);
}
@override
void dispose() {
// TODO: implement dispose
super.dispose();
_scale.setWeightInfoCallback(null);
}
}