ehsure_qr_scanner 0.0.7 ehsure_qr_scanner: ^0.0.7 copied to clipboard
Ehsure scanner Flutter plugin.
import 'package:ehsure_qr_scanner/ehsure_qr_scanner.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 _codeValue = 'Unknown';
@override
void initState() {
super.initState();
}
// Platform messages are asynchronous, so we initialize in an async method.
Future<void> initPlatformState(BuildContext cnx) async {
String codeValue;
// Platform messages may fail, so we use a try/catch PlatformException.
try {
codeValue = await EhsureScanner.getScanResult(cnx);
} on PlatformException {
codeValue = '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(() {
_codeValue = codeValue;
});
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text("扫码"),
),
body: Center(
child: Builder( builder: (cnx) {
return RaisedButton(
child: Text(_codeValue ?? ""),
onPressed: (){
initPlatformState(cnx);
});
})
)
),
);
}
}