sunmi_barcode_scanner 0.0.4 sunmi_barcode_scanner: ^0.0.4 copied to clipboard
Flutter plugin that wraps Sunmi Android SDK for integrated hardware barcode scanners
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:sunmi_barcode_scanner/sunmi_barcode_scanner.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({Key? key}) : super(key: key);
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
String _modelVersion = 'Unknown';
var sunmiBarcodeScanner = SunmiBarcodeScanner();
@override
void initState() {
super.initState();
initPlatformState();
sunmiBarcodeScanner.onBarcodeScanned().listen((event) => print(event));
}
// Platform messages are asynchronous, so we initialize in an async method.
Future<void> initPlatformState() async {
String modelVersion;
// Platform messages may fail, so we use a try/catch PlatformException.
try {
modelVersion = (await sunmiBarcodeScanner.getScannerModel()).toString();
} on PlatformException {
modelVersion = 'Failed to get model 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(() {
_modelVersion = modelVersion;
});
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Sunmi Barcode Plugin'),
),
body: Center(
child: Text('Scanner model: $_modelVersion\n'),
),
),
);
}
}