init
This commit is contained in:
96
lib/pages/page1/qr.dart
Normal file
96
lib/pages/page1/qr.dart
Normal file
@@ -0,0 +1,96 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:qr_code_scanner/qr_code_scanner.dart';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:qr_flutter/qr_flutter.dart';
|
||||
class QrWidget extends StatefulWidget {
|
||||
const QrWidget({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<QrWidget> createState() => _QrWidgetState();
|
||||
}
|
||||
|
||||
class _QrWidgetState extends State<QrWidget> {
|
||||
final GlobalKey qrKey = GlobalKey(debugLabel: 'QR');
|
||||
Barcode? result;
|
||||
QRViewController? controller;
|
||||
|
||||
@override
|
||||
initState(){
|
||||
|
||||
}
|
||||
|
||||
@override
|
||||
void reassemble() {
|
||||
super.reassemble();
|
||||
// if (Platform.isAndroid) {
|
||||
// controller!.pauseCamera();
|
||||
// } else if (Platform.isIOS) {
|
||||
// controller!.resumeCamera();
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text('QR'),
|
||||
centerTitle: true,
|
||||
elevation: 0.0,
|
||||
),
|
||||
body: Column(
|
||||
children: <Widget>[
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Container(
|
||||
width: 300,
|
||||
height: 300,
|
||||
child: QRView(
|
||||
key: qrKey,
|
||||
onQRViewCreated: _onQRViewCreated,
|
||||
),
|
||||
),
|
||||
Container(
|
||||
width: 300,
|
||||
height: 300,
|
||||
child: QrImage(
|
||||
data: "1234567890",
|
||||
version: QrVersions.auto,
|
||||
size: 200.0,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
Expanded(
|
||||
flex: 1,
|
||||
child: Center(
|
||||
child: (result != null)
|
||||
? Text(
|
||||
'Barcode Type:Data: ${result!.code}')
|
||||
: Text('Scan a code'),
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _onQRViewCreated(QRViewController controller) {
|
||||
this.controller = controller;
|
||||
controller.scannedDataStream.listen((scanData) {
|
||||
setState(() {
|
||||
result = scanData;
|
||||
print(result);
|
||||
});
|
||||
});
|
||||
controller.resumeCamera();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
controller?.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user