Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Improve live QR scanner feedback

Neeraj Guptae6f19b3cd989
diff --git a/mobile/apps/auth/lib/ui/scanner_gauth_page.dart b/mobile/apps/auth/lib/ui/scanner_gauth_page.dart
index 4e86c8cef1..2efe290d08 100644
--- a/mobile/apps/auth/lib/ui/scanner_gauth_page.dart
+++ b/mobile/apps/auth/lib/ui/scanner_gauth_page.dart
@@ -18,6 +18,8 @@ class ScannerGoogleAuthPage extends StatefulWidget {
}
class ScannerGoogleAuthPageState extends State<ScannerGoogleAuthPage> {
+ static const double _scannerToastBottomMargin = 96;
+
EnteQrScannerController? controller;
StreamSubscription<String>? _scanSubscription;
bool _hasCompletedScan = false;
@@ -70,7 +72,7 @@ class ScannerGoogleAuthPageState extends State<ScannerGoogleAuthPage> {
if (!qrCode.startsWith(kGoogleAuthExportPrefix)) {
if (mounted) {
- showToast(context, "Invalid QR code");
+ _showScannerToast("Invalid QR code");
}
return;
}
@@ -105,7 +107,11 @@ class ScannerGoogleAuthPageState extends State<ScannerGoogleAuthPage> {
return;
}
Navigator.of(context).pop();
- showToast(context, "Error $error");
+ _showScannerToast("Error $error");
+ }
+
+ void _showScannerToast(String message) {
+ showToast(context, message, mobileBottomMargin: _scannerToastBottomMargin);
}
void _cancelScanSubscription() {
diff --git a/mobile/apps/auth/lib/ui/scanner_page.dart b/mobile/apps/auth/lib/ui/scanner_page.dart
index 1b981ca7d9..a3eb85363e 100644
--- a/mobile/apps/auth/lib/ui/scanner_page.dart
+++ b/mobile/apps/auth/lib/ui/scanner_page.dart
@@ -39,6 +39,8 @@ class ScannerPage extends StatefulWidget {
}
class ScannerPageState extends State<ScannerPage> {
+ static const double _scannerToastBottomMargin = 96;
+
final Logger _logger = Logger('ScannerPage');
EnteQrScannerController? controller;
StreamSubscription<String>? _scanSubscription;
@@ -266,7 +268,7 @@ class ScannerPageState extends State<ScannerPage> {
);
} catch (e) {
if (mounted) {
- showToast(context, context.l10n.invalidQRCode);
+ _showInvalidQRCodeToast();
}
}
}
@@ -282,7 +284,7 @@ class ScannerPageState extends State<ScannerPage> {
final codes = parseGoogleAuth(qrCode);
if (codes.isEmpty) {
if (mounted) {
- showToast(context, context.l10n.invalidQRCode);
+ _showInvalidQRCodeToast();
}
return;
}
@@ -298,7 +300,7 @@ class ScannerPageState extends State<ScannerPage> {
} catch (e, s) {
_logger.severe("Error importing Google Authenticator QR", e, s);
if (mounted) {
- showToast(context, context.l10n.invalidQRCode);
+ _showInvalidQRCodeToast();
}
} finally {
if (shouldResumeCamera && mounted && !_hasCompletedScan) {
@@ -308,6 +310,14 @@ class ScannerPageState extends State<ScannerPage> {
}
}
+ void _showInvalidQRCodeToast() {
+ showToast(
+ context,
+ context.l10n.invalidQRCode,
+ mobileBottomMargin: _scannerToastBottomMargin,
+ );
+ }
+
Future<void> _handleImportFromGallery() async {
if (_isImportingFromGallery || _hasCompletedScan) {
return;
diff --git a/mobile/apps/auth/lib/utils/toast_util.dart b/mobile/apps/auth/lib/utils/toast_util.dart
index 5de2a01fd2..6ff7df3a26 100644
--- a/mobile/apps/auth/lib/utils/toast_util.dart
+++ b/mobile/apps/auth/lib/utils/toast_util.dart
@@ -9,6 +9,7 @@ void showToast(
String message, {
toastLength = Toast.LENGTH_LONG,
iOSDismissOnTap = true,
+ double mobileBottomMargin = 16,
}) async {
// If on mobile render toast above the keyboard using FToast.
final bool isMobile = PlatformDetector.isMobile();
@@ -49,11 +50,15 @@ void showToast(
gravity: ToastGravity.BOTTOM,
toastDuration: const Duration(seconds: 2),
positionedToastBuilder: (context, child, _) {
- final double currentInset = MediaQuery.of(context).viewInsets.bottom;
+ final mediaQuery = MediaQuery.of(context);
+ final double keyboardInset = mediaQuery.viewInsets.bottom;
+ final double bottomInset = keyboardInset > 0
+ ? keyboardInset
+ : mediaQuery.viewPadding.bottom;
return Positioned(
left: 16,
right: 16,
- bottom: currentInset + 16,
+ bottom: bottomInset + mobileBottomMargin,
child: child,
);
},