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.
cloudsolutions-atoms/lib/views/widgets/qr/scan_qr.dart

90 lines
2.1 KiB
Dart

import 'dart:io';
import 'package:flutter/material.dart';
import 'package:mobile_scanner/mobile_scanner.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;
MobileScannerController? 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 initState() {
// TODO: implement initState
super.initState();
controller = MobileScannerController(
detectionSpeed: DetectionSpeed.noDuplicates,
formats: [],
returnImage: false,
torchEnabled: false,
invertImage: false,
autoZoom: true,
);
}
//
// @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: [
MobileScanner(
tapToFocus: true,
controller: controller,
onDetect: (result) {
if (!_scanDone) {
_scanDone = true;
Navigator.of(context).pop(result.barcodes.first.rawValue);
}
},
),
SafeArea(
child: Padding(
padding: const EdgeInsets.all(12.0),
child: AIconButton(
iconData: Icons.arrow_back,
onPressed: () {
Navigator.of(context).pop();
},
),
),
)
],
),
);
}
}