feat: Beautify qr code scanner

This commit is contained in:
Christian Pauly 2021-08-24 14:07:49 +02:00
parent 8029a366f7
commit 0728a30565
2 changed files with 20 additions and 5 deletions

View File

@ -79,9 +79,10 @@ class NewPrivateChatController extends State<NewPrivateChat> {
void openScannerAction() async { void openScannerAction() async {
final status = await Permission.camera.request(); final status = await Permission.camera.request();
if (!status.isGranted) return; if (!status.isGranted) return;
await showDialog( await showModalBottomSheet(
context: context, context: context,
useRootNavigator: false, useRootNavigator: false,
//useSafeArea: false,
builder: (_) => QrScannerModal(), builder: (_) => QrScannerModal(),
); );
} }

View File

@ -1,3 +1,4 @@
import 'dart:async';
import 'dart:io'; import 'dart:io';
import 'package:fluffychat/utils/url_launcher.dart'; import 'package:fluffychat/utils/url_launcher.dart';
@ -33,19 +34,32 @@ class _QrScannerModalState extends State<QrScannerModal> {
leading: IconButton( leading: IconButton(
icon: Icon(Icons.close_outlined), icon: Icon(Icons.close_outlined),
onPressed: Navigator.of(context).pop, onPressed: Navigator.of(context).pop,
tooltip: L10n.of(context).close,
), ),
title: Text(L10n.of(context).scanQrCode), title: Text(L10n.of(context).scanQrCode),
), ),
body: QRView( body: Stack(
key: qrKey, children: [
onQRViewCreated: _onQRViewCreated, QRView(
key: qrKey,
onQRViewCreated: _onQRViewCreated,
overlay: QrScannerOverlayShape(
borderColor: Theme.of(context).primaryColor,
borderRadius: 10,
borderLength: 30,
borderWidth: 8,
),
),
],
), ),
); );
} }
void _onQRViewCreated(QRViewController controller) { void _onQRViewCreated(QRViewController controller) {
this.controller = controller; this.controller = controller;
controller.scannedDataStream.listen((scanData) { StreamSubscription sub;
sub = controller.scannedDataStream.listen((scanData) {
sub.cancel();
Navigator.of(context).pop(); Navigator.of(context).pop();
UrlLauncher(context, scanData.code).openMatrixToUrl(); UrlLauncher(context, scanData.code).openMatrixToUrl();
}); });