c72_uhf_plugin 0.0.1 c72_uhf_plugin: ^0.0.1 copied to clipboard
c72 plugin
import 'dart:developer';
import 'package:audioplayers/audioplayers.dart';
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:c72_uhf_plugin/c72_uhf_plugin.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({super.key});
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
final audioPlayer = AudioPlayer();
final _c72UhfPlugin = C72UhfPlugin();
@override
void initState() {
super.initState();
initPlatformState();
}
Future<void> initPlatformState() async {
_c72UhfPlugin.connectedStatusStream
.receiveBroadcastStream()
.listen(updateIsConnected);
_c72UhfPlugin.tagsStatusStream.receiveBroadcastStream().listen(updateTags);
_c72UhfPlugin.setObserveButton(true);
await _c72UhfPlugin.connect;
await _c72UhfPlugin.setWorkArea('2');
await _c72UhfPlugin.setPowerLevel('10');
if (!mounted) return;
}
List<TagEpc> _data = [];
void updateTags(dynamic result) {
log('update tags');
setState(() {
_data = TagEpc.parseTags(result);
});
}
void updateIsConnected(dynamic isConnected) {
log('connected $isConnected');
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Plugin example app'),
),
body: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
ElevatedButton(
child: const Text(
'Connect',
style: TextStyle(color: Colors.white),
),
onPressed: () async {
await _c72UhfPlugin.connect;
},
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Expanded(
flex: 1,
child: ElevatedButton(
child: const Text(
'Single reading',
style: TextStyle(color: Colors.white),
),
onPressed: () async {
final isStarted = await _c72UhfPlugin.startSingle;
log('Start signle $isStarted');
},
),
),
const SizedBox(
width: 20,
),
Expanded(
flex: 1,
child: ElevatedButton(
child: const Text(
'Continuous reading',
style: TextStyle(color: Colors.white),
),
onPressed: () async {
final isStarted = await _c72UhfPlugin.startContinuous;
log('Start Continuous $isStarted');
},
),
),
],
),
ElevatedButton(
child: const Text(
'Call Stop',
style: TextStyle(color: Colors.white),
),
onPressed: () async {
final isStopped = await _c72UhfPlugin.stop;
log('Stop $isStopped');
},
),
ElevatedButton(
child: const Text(
'Clear',
style: TextStyle(color: Colors.white),
),
onPressed: () async {
await _c72UhfPlugin.clearData;
setState(() {
_data.clear();
});
},
),
Text('All tag: ${_data.length}'),
Expanded(
child: ListView(
children: _data
.map(
(TagEpc tag) => Card(
color: Colors.blue.shade50,
child: Container(
width: 330,
alignment: Alignment.center,
padding: const EdgeInsets.all(8.0),
child: Text(
'Tag ${tag.epc} Count:${tag.count}',
style: TextStyle(color: Colors.blue.shade800),
),
),
),
)
.toList(),
),
),
],
),
),
);
}
}