You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
76 lines
1.9 KiB
Dart
76 lines
1.9 KiB
Dart
import 'dart:io';
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:qr_code_scanner_plus/qr_code_scanner_plus.dart';
|
|
|
|
import '../buttons/app_icon_button.dart';
|
|
|
|
class ScanQr extends StatefulWidget {
|
|
const ScanQr({Key? key}) : super(key: key);
|
|
|
|
@override
|
|
_ScanQrState createState() => _ScanQrState();
|
|
}
|
|
|
|
class _ScanQrState extends State<ScanQr> {
|
|
// Barcode result;
|
|
QRViewController? _controller;
|
|
bool _scanDone = false;
|
|
final GlobalKey qrKey = GlobalKey(debugLabel: 'QR_scanner');
|
|
|
|
// In order to get hot reload to work we need to pause the camera if the platform
|
|
// is android, or resume the camera if the platform is iOS.
|
|
|
|
@override
|
|
void reassemble() {
|
|
super.reassemble();
|
|
if (Platform.isAndroid) {
|
|
_controller?.pauseCamera();
|
|
} else if (Platform.isIOS) {
|
|
_controller?.resumeCamera();
|
|
}
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
super.dispose();
|
|
_controller?.dispose();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
body: Stack(
|
|
children: [
|
|
QRView(
|
|
key: qrKey,
|
|
onQRViewCreated: (QRViewController controller) {
|
|
setState(() {
|
|
_controller = controller;
|
|
});
|
|
controller.scannedDataStream.listen((scanData) {
|
|
if (!_scanDone) {
|
|
_scanDone = true;
|
|
Navigator.of(context).pop(scanData.code);
|
|
}
|
|
});
|
|
},
|
|
overlay: QrScannerOverlayShape(borderColor: Colors.red, borderRadius: 10, borderLength: 30, borderWidth: 10, cutOutSize: 280),
|
|
),
|
|
SafeArea(
|
|
child: Padding(
|
|
padding: const EdgeInsets.all(12.0),
|
|
child: AIconButton(
|
|
iconData: Icons.arrow_back,
|
|
onPressed: () {
|
|
Navigator.of(context).pop();
|
|
},
|
|
),
|
|
),
|
|
)
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|