Skip to content

armgit / ente

Public Imported from GitHub
0

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

[mob][auth] Add AuthQrDialog with basic QR style using qr_flutter

Prateek Sunal428ef28a1f1c
diff --git a/mobile/apps/auth/lib/ui/code_widget.dart b/mobile/apps/auth/lib/ui/code_widget.dart
index 51b334364d..9f3f292e7c 100644
--- a/mobile/apps/auth/lib/ui/code_widget.dart
+++ b/mobile/apps/auth/lib/ui/code_widget.dart
@@ -13,9 +13,9 @@ import 'package:ente_auth/services/local_backup_service.dart';
import 'package:ente_auth/services/preference_service.dart';
import 'package:ente_auth/store/code_display_store.dart';
import 'package:ente_auth/store/code_store.dart';
-import 'package:ente_auth/theme/colors.dart';
import 'package:ente_auth/theme/ente_theme.dart';
import 'package:ente_auth/ui/code_timer_progress.dart';
+import 'package:ente_auth/ui/components/auth_qr_dialog.dart';
import 'package:ente_auth/ui/components/note_dialog.dart';
import 'package:ente_auth/ui/home/shortcuts.dart';
import 'package:ente_auth/ui/share/code_share.dart';
@@ -26,7 +26,6 @@ import 'package:ente_auth/utils/toast_util.dart';
import 'package:ente_auth/utils/totp_util.dart';
import 'package:ente_events/event_bus.dart';
import 'package:ente_lock_screen/local_authentication_service.dart';
-import 'package:ente_qr_ui/ente_qr_ui.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_context_menu/flutter_context_menu.dart';
@@ -272,7 +271,8 @@ class _CodeWidgetState extends State<CodeWidget> {
child: Material(
color: Colors.transparent,
child: InkWell(
- focusNode: widget.focusNode,customBorder: RoundedRectangleBorder(
+ focusNode: widget.focusNode,
+ customBorder: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10),
),
// InkWell handles focus natively.
@@ -934,20 +934,14 @@ class _CodeWidgetState extends State<CodeWidget> {
await showDialog(
context: context,
builder: (BuildContext dialogContext) {
- return QrCodeDialog(
+ return AuthQrDialog(
data: qrData,
title: widget.code.account,
subtitle: widget.code.issuer,
- accentColor: accentColor,
shareFileName: 'ente_auth_qr_${widget.code.account}.png',
shareText: 'QR code for ${widget.code.account}',
dialogTitle: context.l10n.qrCode,
shareButtonText: context.l10n.share,
- logoAssetPath: 'assets/qr_logo.png',
- branding: const QrSvgBranding(
- assetPath: 'assets/svg/auth-logo.svg',
- height: 12,
- ),
);
},
);
diff --git a/mobile/apps/auth/lib/ui/components/auth_qr_dialog.dart b/mobile/apps/auth/lib/ui/components/auth_qr_dialog.dart
new file mode 100644
index 0000000000..3a237d826b
--- /dev/null
+++ b/mobile/apps/auth/lib/ui/components/auth_qr_dialog.dart
@@ -0,0 +1,264 @@
+import 'dart:io';
+import 'dart:math';
+import 'dart:typed_data';
+import 'dart:ui' as ui;
+
+import 'package:ente_auth/theme/colors.dart';
+import 'package:ente_auth/theme/ente_theme.dart';
+import 'package:flutter/material.dart';
+import 'package:flutter/rendering.dart';
+import 'package:flutter_svg/flutter_svg.dart';
+import 'package:path_provider/path_provider.dart';
+import 'package:qr_flutter/qr_flutter.dart';
+import 'package:share_plus/share_plus.dart';
+
+class AuthQrDialog extends StatefulWidget {
+ final String data;
+ final String title;
+ final String? subtitle;
+ final String shareFileName;
+ final String shareText;
+ final String dialogTitle;
+ final String shareButtonText;
+
+ const AuthQrDialog({
+ super.key,
+ required this.data,
+ required this.title,
+ required this.shareFileName,
+ required this.shareText,
+ this.subtitle,
+ this.dialogTitle = 'QR Code',
+ this.shareButtonText = 'Share',
+ });
+
+ @override
+ State<AuthQrDialog> createState() => _AuthQrDialogState();
+}
+
+class _AuthQrDialogState extends State<AuthQrDialog> {
+ final GlobalKey _qrKey = GlobalKey();
+
+ Future<void> _shareQrCode() async {
+ try {
+ final boundary =
+ _qrKey.currentContext?.findRenderObject() as RenderRepaintBoundary?;
+ if (boundary == null) return;
+
+ final ui.Image image = await boundary.toImage(pixelRatio: 3.0);
+ final ByteData? byteData =
+ await image.toByteData(format: ui.ImageByteFormat.png);
+ if (byteData == null) return;
+
+ final Uint8List pngBytes = byteData.buffer.asUint8List();
+ final directory = await getTemporaryDirectory();
+ final file = File('${directory.path}/${widget.shareFileName}');
+ await file.writeAsBytes(pngBytes);
+
+ final box = context.findRenderObject() as RenderBox?;
+ final shareOrigin =
+ box != null ? box.localToGlobal(Offset.zero) & box.size : null;
+
+ await SharePlus.instance.share(
+ ShareParams(
+ files: [XFile(file.path)],
+ text: widget.shareText,
+ sharePositionOrigin: shareOrigin,
+ ),
+ );
+ } catch (error) {
+ debugPrint('Error sharing QR code: $error');
+ }
+ }
+
+ @override
+ Widget build(BuildContext context) {
+ final screenWidth = MediaQuery.of(context).size.width;
+ final double qrSize = min(screenWidth - 80, 300.0);
+ final enteTextTheme = getEnteTextTheme(context);
+ final theme = Theme.of(context);
+ final isDark = theme.brightness == Brightness.dark;
+
+ // QR text color - always black for scanability
+ const qrTextColor = textBaseLight;
+
+ final dialogBackgroundColor = theme.colorScheme.surface;
+ final closeBgColor =
+ isDark ? theme.colorScheme.surfaceContainerHighest : qrBoxColor;
+ final closeIconColor = isDark ? theme.colorScheme.onSurface : qrTextColor;
+
+ final dialogTitleStyle = theme.textTheme.titleLarge?.copyWith(
+ fontSize: 20,
+ fontWeight: FontWeight.w700,
+ color: theme.colorScheme.onSurface,
+ );
+ final shareButtonStyle = theme.textTheme.labelLarge?.copyWith(
+ fontSize: 16,
+ fontWeight: FontWeight.w600,
+ color: Colors.white,
+ );
+
+ return Dialog(
+ shape: RoundedRectangleBorder(
+ borderRadius: BorderRadius.circular(24),
+ ),
+ shadowColor: isDark
+ ? Colors.black.withValues(alpha: 0.7)
+ : Colors.grey.withValues(alpha: 0.5),
+ child: ConstrainedBox(
+ constraints: const BoxConstraints(maxWidth: 400),
+ child: Container(
+ decoration: BoxDecoration(
+ color: dialogBackgroundColor,
+ borderRadius: BorderRadius.circular(24),
+ border: isDark
+ ? Border.all(
+ color: Colors.white.withValues(alpha: 0.1),
+ width: 1,
+ )
+ : null,
+ ),
+ child: SingleChildScrollView(
+ padding: const EdgeInsets.all(20),
+ child: Column(
+ mainAxisSize: MainAxisSize.min,
+ children: [
+ Padding(
+ padding: const EdgeInsets.only(left: 6, bottom: 4),
+ child: Row(
+ mainAxisAlignment: MainAxisAlignment.spaceBetween,
+ children: [
+ Text(widget.dialogTitle, style: dialogTitleStyle),
+ GestureDetector(
+ onTap: () => Navigator.of(context).pop(),
+ child: Container(
+ width: 36,
+ height: 36,
+ decoration: BoxDecoration(
+ color: closeBgColor,
+ borderRadius: BorderRadius.circular(18),
+ ),
+ child: Icon(
+ Icons.close,
+ size: 20,
+ color: closeIconColor,
+ ),
+ ),
+ ),
+ ],
+ ),
+ ),
+ const SizedBox(height: 8),
+ RepaintBoundary(
+ key: _qrKey,
+ child: Container(
+ width: double.infinity,
+ padding: const EdgeInsets.fromLTRB(20, 20, 20, 12),
+ decoration: BoxDecoration(
+ color: qrBoxColor,
+ borderRadius: BorderRadius.circular(22),
+ ),
+ child: Stack(
+ alignment: Alignment.center,
+ children: [
+ Column(
+ mainAxisSize: MainAxisSize.min,
+ crossAxisAlignment: CrossAxisAlignment.center,
+ children: [
+ // Account name at top center
+ ConstrainedBox(
+ constraints: BoxConstraints(
+ maxWidth: qrSize,
+ ),
+ child: Text(
+ widget.title,
+ style: enteTextTheme.largeBold.copyWith(
+ color: qrTextColor,
+ fontSize: 20,
+ ),
+ textAlign: TextAlign.center,
+ maxLines: 1,
+ overflow: TextOverflow.ellipsis,
+ ),
+ ),
+ if (widget.subtitle != null &&
+ widget.subtitle!.isNotEmpty) ...[
+ const SizedBox(height: 4),
+ ConstrainedBox(
+ constraints: BoxConstraints(
+ maxWidth: qrSize,
+ ),
+ child: Text(
+ widget.subtitle!,
+ style: enteTextTheme.small.copyWith(
+ color: qrTextColor.withValues(alpha: 0.7),
+ fontSize: 14,
+ ),
+ textAlign: TextAlign.center,
+ maxLines: 1,
+ overflow: TextOverflow.ellipsis,
+ ),
+ ),
+ ],
+ const SizedBox(height: 20),
+
+ // QR Code with square style and purple corners
+ QrImageView(
+ data: widget.data,
+ eyeStyle: const QrEyeStyle(
+ eyeShape: QrEyeShape.square,
+ color: accentColor,
+ ),
+ dataModuleStyle: const QrDataModuleStyle(
+ dataModuleShape: QrDataModuleShape.square,
+ color: qrTextColor,
+ ),
+ version: QrVersions.auto,
+ size: qrSize,
+ ),
+ const SizedBox(height: 42),
+ ],
+ ),
+
+ // Auth branding at bottom right
+ Positioned(
+ bottom: 0,
+ right: 2,
+ child: SvgPicture.asset(
+ 'assets/svg/auth-logo.svg',
+ height: 16,
+ colorFilter: const ColorFilter.mode(
+ accentColor,
+ BlendMode.srcIn,
+ ),
+ ),
+ ),
+ ],
+ ),
+ ),
+ ),
+ const SizedBox(height: 24),
+ GestureDetector(
+ onTap: _shareQrCode,
+ child: Container(
+ width: double.infinity,
+ padding: const EdgeInsets.symmetric(vertical: 14),
+ decoration: BoxDecoration(
+ color: accentColor,
+ borderRadius: BorderRadius.circular(12),
+ ),
+ child: Text(
+ widget.shareButtonText,
+ textAlign: TextAlign.center,
+ style: shareButtonStyle,
+ ),
+ ),
+ ),
+ ],
+ ),
+ ),
+ ),
+ ),
+ );
+ }
+}
diff --git a/mobile/apps/auth/lib/ui/home_page.dart b/mobile/apps/auth/lib/ui/home_page.dart
index 6adbf62677..7ac99dabef 100644
--- a/mobile/apps/auth/lib/ui/home_page.dart
+++ b/mobile/apps/auth/lib/ui/home_page.dart
@@ -19,12 +19,13 @@ import 'package:ente_auth/services/local_backup_service.dart';
import 'package:ente_auth/services/preference_service.dart';
import 'package:ente_auth/store/code_display_store.dart';
import 'package:ente_auth/store/code_store.dart';
-import 'package:ente_auth/theme/colors.dart';
+
import 'package:ente_auth/theme/ente_theme.dart';
import 'package:ente_auth/ui/account/logout_dialog.dart';
import 'package:ente_auth/ui/code_error_widget.dart';
import 'package:ente_auth/ui/code_widget.dart';
import 'package:ente_auth/ui/common/loading_widget.dart';
+import 'package:ente_auth/ui/components/auth_qr_dialog.dart';
import 'package:ente_auth/ui/components/buttons/button_widget.dart';
import 'package:ente_auth/ui/components/dialog_widget.dart';
import 'package:ente_auth/ui/components/models/button_type.dart';
@@ -50,7 +51,6 @@ import 'package:ente_events/event_bus.dart';
import 'package:ente_lock_screen/local_authentication_service.dart';
import 'package:ente_lock_screen/lock_screen_settings.dart';
import 'package:ente_lock_screen/ui/app_lock.dart';
-import 'package:ente_qr_ui/ente_qr_ui.dart';
import 'package:ente_ui/pages/base_home_page.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
@@ -458,20 +458,14 @@ class _HomePageState extends State<HomePage> {
await showDialog(
context: context,
builder: (BuildContext dialogContext) {
- return QrCodeDialog(
+ return AuthQrDialog(
data: qrData,
title: code.account,
subtitle: code.issuer,
- accentColor: accentColor,
shareFileName: 'ente_auth_qr_${code.account}.png',
shareText: 'QR code for ${code.account}',
dialogTitle: context.l10n.qrCode,
shareButtonText: context.l10n.share,
- logoAssetPath: 'assets/qr_logo.png',
- branding: const QrSvgBranding(
- assetPath: 'assets/svg/auth-logo.svg',
- height: 12,
- ),
);
},
);
@@ -1025,7 +1019,8 @@ class _HomePageState extends State<HomePage> {
_pressedKeys.contains(LogicalKeyboardKey.control) ||
_pressedKeys.contains(LogicalKeyboardKey.controlRight));
- if ((isMetaKeyPressed && event.logicalKey == LogicalKeyboardKey.keyF) || event.logicalKey == LogicalKeyboardKey.slash) {
+ if ((isMetaKeyPressed && event.logicalKey == LogicalKeyboardKey.keyF) ||
+ event.logicalKey == LogicalKeyboardKey.slash) {
setState(() {
_showSearchBox = true;
searchBoxFocusNode.requestFocus();
@@ -1345,7 +1340,8 @@ class _HomePageState extends State<HomePage> {
builder: (context) {
return Shortcuts(
shortcuts: <LogicalKeySet, Intent>{
- LogicalKeySet(LogicalKeyboardKey.keyC): const CopyIntent(),
+ LogicalKeySet(LogicalKeyboardKey.keyC):
+ const CopyIntent(),
LogicalKeySet(LogicalKeyboardKey.keyN):
const CopyNextIntent(),
},
@@ -1603,8 +1599,7 @@ class _HomePageState extends State<HomePage> {
final crossAxisCount = _calculateGridColumnCount(context);
_currentGridColumns = crossAxisCount;
final double keyboardInset = MediaQuery.of(context).viewInsets.bottom;
- final double gridBottomPadding =
- 80 + (_showSearchBox ? keyboardInset : 0);
+ final double gridBottomPadding = 80 + (_showSearchBox ? keyboardInset : 0);
if (_hasLoaded) {
final bool noCodesAnywhere = !hasNonTrashedCodes && !hasTrashedCodes;
if (_filteredCodes.isEmpty && _searchText.isEmpty && noCodesAnywhere) {
diff --git a/mobile/packages/qr/lib/ente_qr_ui.dart b/mobile/packages/qr/lib/ente_qr_ui.dart
index ce044fa3ee..f59a2f42a4 100644
--- a/mobile/packages/qr/lib/ente_qr_ui.dart
+++ b/mobile/packages/qr/lib/ente_qr_ui.dart
@@ -1,4 +1,16 @@
library ente_qr_ui;
-export 'package:pretty_qr_code/pretty_qr_code.dart' show QrErrorCorrectLevel;
+export 'package:pretty_qr_code/pretty_qr_code.dart'
+ show
+ PrettyQrDecoration,
+ PrettyQrDecorationImage,
+ PrettyQrDecorationImagePosition,
+ PrettyQrDotsSymbol,
+ PrettyQrQuietZone,
+ PrettyQrShape,
+ PrettyQrSquaresSymbol,
+ PrettyQrView,
+ QrCode,
+ QrErrorCorrectLevel,
+ QrImage;
export 'qr_code_dialog.dart';