From 0728a30565a6c8cbad1adf86d67b4530e7979577 Mon Sep 17 00:00:00 2001 From: Christian Pauly Date: Tue, 24 Aug 2021 14:07:49 +0200 Subject: [PATCH] feat: Beautify qr code scanner --- lib/pages/new_private_chat.dart | 3 ++- lib/pages/qr_scanner_modal.dart | 22 ++++++++++++++++++---- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/lib/pages/new_private_chat.dart b/lib/pages/new_private_chat.dart index a0f97594..154d1106 100644 --- a/lib/pages/new_private_chat.dart +++ b/lib/pages/new_private_chat.dart @@ -79,9 +79,10 @@ class NewPrivateChatController extends State { void openScannerAction() async { final status = await Permission.camera.request(); if (!status.isGranted) return; - await showDialog( + await showModalBottomSheet( context: context, useRootNavigator: false, + //useSafeArea: false, builder: (_) => QrScannerModal(), ); } diff --git a/lib/pages/qr_scanner_modal.dart b/lib/pages/qr_scanner_modal.dart index f6c1d8bf..acbba8a4 100644 --- a/lib/pages/qr_scanner_modal.dart +++ b/lib/pages/qr_scanner_modal.dart @@ -1,3 +1,4 @@ +import 'dart:async'; import 'dart:io'; import 'package:fluffychat/utils/url_launcher.dart'; @@ -33,19 +34,32 @@ class _QrScannerModalState extends State { leading: IconButton( icon: Icon(Icons.close_outlined), onPressed: Navigator.of(context).pop, + tooltip: L10n.of(context).close, ), title: Text(L10n.of(context).scanQrCode), ), - body: QRView( - key: qrKey, - onQRViewCreated: _onQRViewCreated, + body: Stack( + children: [ + QRView( + key: qrKey, + onQRViewCreated: _onQRViewCreated, + overlay: QrScannerOverlayShape( + borderColor: Theme.of(context).primaryColor, + borderRadius: 10, + borderLength: 30, + borderWidth: 8, + ), + ), + ], ), ); } void _onQRViewCreated(QRViewController controller) { this.controller = controller; - controller.scannedDataStream.listen((scanData) { + StreamSubscription sub; + sub = controller.scannedDataStream.listen((scanData) { + sub.cancel(); Navigator.of(context).pop(); UrlLauncher(context, scanData.code).openMatrixToUrl(); });