cn80listener 0.0.2 cn80listener: ^0.0.2 copied to clipboard
A Honeywell CN80 Flutter Plugin
import 'package:cn80listener/cn80listener.dart';
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:flutter/services.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
String _code = 'Unknown';
static final channelName = 'cn80listener';
final methodChannel = MethodChannel(channelName);
Future<void> _scanDecoded(MethodCall call) async {
// type inference will work here avoiding an explicit cast
final String utterance = call.arguments;
switch(call.method) {
case "scanDecoded":
_code = utterance;
setState(() {
});
break;
case "scanDecodedWithError":
_code = utterance;
setState(() {
});
}
}
@override
void initState() {
super.initState();
methodChannel.setMethodCallHandler(this._scanDecoded);
initPlatformState();
}
@override
void dispose()
{
disposePlatformState();
super.dispose();
}
// Platform messages are asynchronous, so we initialize in an async method.
Future<void> initPlatformState() async {
// Platform messages may fail, so we use a try/catch PlatformException.
try {
await Cn80listener.startScanner;
} on PlatformException {
}
}
// Platform messages are asynchronous, so we initialize in an async method.
Future<void> disposePlatformState() async {
// Platform messages may fail, so we use a try/catch PlatformException.
try {
await Cn80listener.stopScanner;
} on PlatformException {
}
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: WillPopScope(
onWillPop: () async {
await disposePlatformState();
return true;
},
child: Scaffold(
appBar: AppBar(
title: const Text('Plugin example app'),
),
body: Center(
child: Text('Running on: $_code\n'),
),
),
),
);
}
}