zebrascanner 0.0.4
zebrascanner: ^0.0.4 copied to clipboard
A new Flutter Plugin to Connect any Android Device to Zebra Bluetooth Scanner
example/lib/main.dart
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:flutter/services.dart';
import 'package:zebrascanner/zebrascanner.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
String _platformVersion = 'Unknown';
static const platform = const MethodChannel('com.zebra.zebrascanner/zebra');
static const _stream =
const EventChannel('com.zebra.zebrascanner/zebraevents');
dynamic map;
StreamSubscription subscription;
var eventData = "";
@override
void initState() {
super.initState();
initPlatformState();
subscription = Zebrascanner.getBarCodeEventStream.listen((barcodeData) {
setState(() {
map = barcodeData;
print(map);
var _list = map.values.toList();
// Barcode
print(_list[0]);
// BarcodeType
print(_list[1]);
// ScannerId
print(_list[2]);
eventData = _list[0] + "-" + _list[1] + "-" + _list[2];
});
});
}
initBarcodeReceiver() {
subscription = _stream.receiveBroadcastStream().listen((barcodeData) {
setState(() {
map = barcodeData;
print(map);
var _list = map.values.toList();
// Barcode
print(_list[0]);
// BarcodeType
print(_list[1]);
// ScannerId
print(_list[2]);
eventData = _list[0];
//eventData = map;
});
});
}
// Platform messages are asynchronous, so we initialize in an async method.
Future<void> initPlatformState() async {
String platformVersion;
// Platform messages may fail, so we use a try/catch PlatformException.
try {
platformVersion = await Zebrascanner.platformVersion;
} on PlatformException {
platformVersion = 'Failed to get platform version.';
}
// If the widget was removed from the tree while the asynchronous platform
// message was in flight, we want to discard the reply rather than calling
// setState to update our non-existent appearance.
if (!mounted) return;
setState(() {
_platformVersion = platformVersion;
});
}
// Platform messages are asynchronous, so we initialize in an async method.
Future<void> openBarcodeScreen() async {
String result;
// Platform messages may fail, so we use a try/catch PlatformException.
try {
result = await Zebrascanner.barcodeScreen;
} on PlatformException {
result = 'Failed.';
}
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Zebra Bluetooth Scanner app'),
),
body: Center(
child: Container(
child: Column(
children: [
SizedBox(
height: 10,
),
Text('Running on: $_platformVersion\n'),
SizedBox(
height: 10,
),
FlatButton(
onPressed: () {
openBarcodeScreen();
},
child: Text("Click to Open Barcode Screen")),
SizedBox(
height: 10,
),
Text('Scanned Barcode/Qrcode $eventData'),
],
),
),
),
),
);
}
}