nls 0.0.1 nls: ^0.0.1 copied to clipboard
Scan QR with android
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:nls/nls.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 _platformVersion = 'Unknown';
String qrCode = "";
final _nlsPlugin = Nls();
static const EventChannel _eventChannel = EventChannel('nlsresult');
StreamSubscription? _streamSubscription;
@override
void initState() {
super.initState();
initPlatformState();
_streamSubscription =
_eventChannel.receiveBroadcastStream().listen((value) {
try {
print(value);
setState(() {
qrCode = value;
});
} catch (e, s) {
print("e:" + e.toString());
print(s);
}
});
}
// 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.
// We also handle the message potentially returning null.
try {
platformVersion =
await _nlsPlugin.getPlatformVersion() ?? 'Unknown platform version';
} 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;
});
}
@override
void dispose() {
super.dispose();
_streamSubscription?.cancel();
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('NLS SCAN'),
),
body: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Padding(
padding: const EdgeInsets.all(10),
child: Text(qrCode),
),
Padding(
padding: const EdgeInsets.all(10),
child: ElevatedButton(
onPressed: () {
_nlsPlugin.scan();
},
child: const Text("Scan")))
],
),
),
);
}
}