Skip to content

armgit / ente

Public Imported from GitHub
0

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

[mob][auth] Add QR code dialog matching Photos app design with Auth branding

Prateek Sunal918f13015505
diff --git a/mobile/apps/auth/assets/qr_logo.png b/mobile/apps/auth/assets/qr_logo.png
new file mode 100644
index 0000000000..6b7e0b043a
Binary files /dev/null and b/mobile/apps/auth/assets/qr_logo.png differ
diff --git a/mobile/apps/auth/lib/onboarding/view/view_qr_page.dart b/mobile/apps/auth/lib/onboarding/view/view_qr_page.dart
index 2dae39a2e2..17c3342bdb 100644
--- a/mobile/apps/auth/lib/onboarding/view/view_qr_page.dart
+++ b/mobile/apps/auth/lib/onboarding/view/view_qr_page.dart
@@ -2,9 +2,11 @@ import 'dart:math';
import "package:ente_auth/l10n/l10n.dart";
import 'package:ente_auth/models/code.dart';
+import 'package:ente_auth/theme/colors.dart';
import 'package:ente_auth/theme/ente_theme.dart';
import "package:flutter/material.dart";
-import 'package:qr_flutter/qr_flutter.dart';
+import 'package:flutter_svg/flutter_svg.dart';
+import 'package:pretty_qr_code/pretty_qr_code.dart';
class ViewQrPage extends StatelessWidget {
final Code? code;
@@ -17,6 +19,23 @@ class ViewQrPage extends StatelessWidget {
final double qrSize = min(screenWidth - 80, 300.0);
final enteTextTheme = getEnteTextTheme(context);
final l10n = context.l10n;
+
+ final String qrData = code!.rawData
+ .replaceAll('algorithm=Algorithm.', 'algorithm=')
+ .replaceAll('algorithm=sha1', 'algorithm=SHA1')
+ .replaceAll('algorithm=sha256', 'algorithm=SHA256')
+ .replaceAll('algorithm=sha512', 'algorithm=SHA512');
+
+ // QR text color - always black for scanability
+ const qrTextColor = textBaseLight;
+
+ // Get account name, truncate if too long
+ final String accountName = (code?.account ?? '').length > 30
+ ? '${(code?.account ?? '').substring(0, 27)}...'
+ : code?.account ?? '';
+
+ final String issuerName = code?.issuer ?? '';
+
return Scaffold(
appBar: AppBar(
title: Text(l10n.qrCode),
@@ -24,79 +43,116 @@ class ViewQrPage extends StatelessWidget {
body: Center(
child: SingleChildScrollView(
child: Padding(
- padding: const EdgeInsets.symmetric(vertical: 40.0, horizontal: 40),
+ padding: const EdgeInsets.fromLTRB(20, 40, 20, 40),
child: Column(
+ mainAxisSize: MainAxisSize.min,
children: [
- QrImageView(
- data: code!.rawData
- .replaceAll('algorithm=Algorithm.', 'algorithm=')
- .replaceAll('algorithm=sha1', 'algorithm=SHA1')
- .replaceAll('algorithm=sha256', 'algorithm=SHA256')
- .replaceAll('algorithm=sha512', 'algorithm=SHA512'),
- eyeStyle: QrEyeStyle(
- eyeShape: QrEyeShape.square,
- color: Theme.of(context).colorScheme.onSurface,
- ),
- dataModuleStyle: QrDataModuleStyle(
- dataModuleShape: QrDataModuleShape.square,
- color: Theme.of(context).colorScheme.onSurface,
+ // QR Code container
+ Container(
+ width: double.infinity,
+ padding: const EdgeInsets.fromLTRB(20, 20, 20, 12),
+ decoration: BoxDecoration(
+ color: qrBoxColor,
+ borderRadius: BorderRadius.circular(22),
),
- version: QrVersions.auto,
- size: qrSize,
- ),
- const SizedBox(
- height: 20,
- ),
- Row(
- mainAxisAlignment: MainAxisAlignment.center,
- children: [
- Text(
- l10n.account,
- style: enteTextTheme.largeMuted,
- ),
- const SizedBox(
- width: 10,
- ),
- Expanded(
- child: SingleChildScrollView(
- scrollDirection: Axis.horizontal,
- child: Text(
- code?.account ?? '',
- style: enteTextTheme.largeBold,
- ),
+ child: Stack(
+ alignment: Alignment.center,
+ children: [
+ Column(
+ mainAxisSize: MainAxisSize.min,
+ crossAxisAlignment: CrossAxisAlignment.center,
+ children: [
+ // Account name at top center (inside border)
+ Text(
+ accountName,
+ style: enteTextTheme.largeBold.copyWith(
+ color: qrTextColor,
+ fontSize: 20,
+ ),
+ textAlign: TextAlign.center,
+ ),
+ if (issuerName.isNotEmpty) ...[
+ const SizedBox(height: 4),
+ Text(
+ issuerName,
+ style: enteTextTheme.small.copyWith(
+ color: qrTextColor.withValues(alpha: 0.7),
+ fontSize: 14,
+ ),
+ textAlign: TextAlign.center,
+ ),
+ ],
+ const SizedBox(height: 20),
+
+ // QR Code with pretty styling
+ SizedBox(
+ width: qrSize - 100,
+ height: qrSize - 100,
+ child: PrettyQrView(
+ qrImage: QrImage(
+ QrCode.fromData(
+ data: qrData,
+ errorCorrectLevel: QrErrorCorrectLevel.L,
+ ),
+ ),
+ decoration: const PrettyQrDecoration(
+ shape: PrettyQrShape.custom(
+ PrettyQrDotsSymbol(
+ color: qrTextColor,
+ unifiedFinderPattern: false,
+ unifiedAlignmentPatterns: false,
+ ),
+ finderPattern: PrettyQrSquaresSymbol(
+ color: qrTextColor,
+ rounding: 0.5,
+ unifiedFinderPattern: true,
+ finderPatternOuterThickness: 1.4,
+ finderPatternOuterColor: accentColor,
+ finderPatternInnerDotSize: 0.8,
+ finderPatternInnerRounding: 1.0,
+ ),
+ alignmentPatterns: PrettyQrSquaresSymbol(
+ color: qrTextColor,
+ rounding: 1.0,
+ ),
+ ),
+ image: PrettyQrDecorationImage(
+ image: AssetImage('assets/qr_logo.png'),
+ scale: 0.25,
+ padding: EdgeInsets.all(24),
+ position:
+ PrettyQrDecorationImagePosition.embedded,
+ ),
+ background: Colors.transparent,
+ quietZone: PrettyQrQuietZone.zero,
+ ),
+ ),
+ ),
+ const SizedBox(height: 42),
+ ],
),
- ),
- ],
- ),
- const SizedBox(
- height: 4,
- ),
- Row(
- mainAxisAlignment: MainAxisAlignment.center,
- children: [
- Text(
- l10n.codeIssuerHint,
- style: enteTextTheme.largeMuted,
- ),
- const SizedBox(
- width: 10,
- ),
- Expanded(
- child: SingleChildScrollView(
- scrollDirection: Axis.horizontal,
- child: Text(
- code?.issuer ?? '',
- style: enteTextTheme.largeBold,
+
+ // Auth branding at bottom right (inside border)
+ 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: 80,
+ ],
+ ),
),
+ const SizedBox(height: 24),
+
+ // Save button
SizedBox(
- width: 400,
+ width: double.infinity,
child: OutlinedButton(
onPressed: () {
Navigator.of(context).pop();
@@ -104,7 +160,7 @@ class ViewQrPage extends StatelessWidget {
child: Padding(
padding: const EdgeInsets.symmetric(
horizontal: 16.0,
- vertical: 0,
+ vertical: 12,
),
child: Text(l10n.back),
),
diff --git a/mobile/apps/auth/lib/theme/colors.dart b/mobile/apps/auth/lib/theme/colors.dart
index e35a4b189e..45797ed40a 100644
--- a/mobile/apps/auth/lib/theme/colors.dart
+++ b/mobile/apps/auth/lib/theme/colors.dart
@@ -186,6 +186,9 @@ const EnteColorScheme darkScheme = EnteColorScheme(
const accentColor = Color(0xFFA75CFF);
+// QR code container background
+const Color qrBoxColor = Color.fromRGBO(245, 245, 247, 1);
+
// Background Colors
const Color backgroundBaseLight = Color.fromRGBO(255, 255, 255, 1);
const Color backgroundElevatedLight = Color.fromRGBO(255, 255, 255, 1);
diff --git a/mobile/apps/auth/lib/ui/code_widget.dart b/mobile/apps/auth/lib/ui/code_widget.dart
index e93a0fc660..3b9d26e6fe 100644
--- a/mobile/apps/auth/lib/ui/code_widget.dart
+++ b/mobile/apps/auth/lib/ui/code_widget.dart
@@ -9,7 +9,6 @@ import 'package:ente_auth/events/multi_select_action_requested_event.dart';
import 'package:ente_auth/l10n/l10n.dart';
import 'package:ente_auth/models/code.dart';
import 'package:ente_auth/onboarding/view/setup_enter_secret_key_page.dart';
-import 'package:ente_auth/onboarding/view/view_qr_page.dart';
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';
@@ -17,6 +16,7 @@ import 'package:ente_auth/store/code_store.dart';
import 'package:ente_auth/theme/ente_theme.dart';
import 'package:ente_auth/ui/code_timer_progress.dart';
import 'package:ente_auth/ui/components/note_dialog.dart';
+import 'package:ente_auth/ui/qr_code_dialog.dart';
import 'package:ente_auth/ui/share/code_share.dart';
import 'package:ente_auth/ui/utils/icon_utils.dart';
import 'package:ente_auth/utils/dialog_util.dart';
@@ -894,13 +894,11 @@ class _CodeWidgetState extends State<CodeWidget> {
if (!isAuthSuccessful) {
return;
}
- // ignore: unused_local_variable
- final Code? code = await Navigator.of(context).push(
- MaterialPageRoute(
- builder: (BuildContext context) {
- return ViewQrPage(code: widget.code);
- },
- ),
+ await showDialog(
+ context: context,
+ builder: (BuildContext context) {
+ return QrCodeDialog(code: widget.code);
+ },
);
}
diff --git a/mobile/apps/auth/lib/ui/home_page.dart b/mobile/apps/auth/lib/ui/home_page.dart
index c04cac9065..17142c42bf 100644
--- a/mobile/apps/auth/lib/ui/home_page.dart
+++ b/mobile/apps/auth/lib/ui/home_page.dart
@@ -15,7 +15,6 @@ import 'package:ente_auth/models/code.dart';
import 'package:ente_auth/onboarding/model/tag_enums.dart';
import 'package:ente_auth/onboarding/view/common/tag_chip.dart';
import 'package:ente_auth/onboarding/view/setup_enter_secret_key_page.dart';
-import 'package:ente_auth/onboarding/view/view_qr_page.dart';
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';
@@ -34,6 +33,7 @@ import 'package:ente_auth/ui/home/add_tag_sheet.dart';
import 'package:ente_auth/ui/home/coach_mark_widget.dart';
import 'package:ente_auth/ui/home/home_empty_state.dart';
import 'package:ente_auth/ui/home/speed_dial_label_widget.dart';
+import 'package:ente_auth/ui/qr_code_dialog.dart';
import 'package:ente_auth/ui/reorder_codes_page.dart';
import 'package:ente_auth/ui/scanner_page.dart';
import 'package:ente_auth/ui/settings_page.dart';
@@ -446,12 +446,11 @@ class _HomePageState extends State<HomePage> {
if (!isAuthSuccessful) return;
_codeDisplayStore.clearSelection();
- await Navigator.of(context).push(
- MaterialPageRoute(
- builder: (BuildContext context) {
- return ViewQrPage(code: code);
- },
- ),
+ await showDialog(
+ context: context,
+ builder: (BuildContext context) {
+ return QrCodeDialog(code: code);
+ },
);
}
diff --git a/mobile/apps/auth/lib/ui/qr_code_dialog.dart b/mobile/apps/auth/lib/ui/qr_code_dialog.dart
new file mode 100644
index 0000000000..8aa39912d7
--- /dev/null
+++ b/mobile/apps/auth/lib/ui/qr_code_dialog.dart
@@ -0,0 +1,281 @@
+import 'dart:io';
+import 'dart:math';
+import 'dart:typed_data';
+import 'dart:ui' as ui;
+
+import "package:ente_auth/l10n/l10n.dart";
+import 'package:ente_auth/models/code.dart';
+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:pretty_qr_code/pretty_qr_code.dart';
+import 'package:share_plus/share_plus.dart';
+
+class QrCodeDialog extends StatefulWidget {
+ final Code code;
+
+ const QrCodeDialog({
+ super.key,
+ required this.code,
+ });
+
+ @override
+ State<QrCodeDialog> createState() => _QrCodeDialogState();
+}
+
+class _QrCodeDialogState extends State<QrCodeDialog> {
+ final GlobalKey _qrKey = GlobalKey();
+
+ Future<void> _shareQrCode() async {
+ try {
+ final RenderRepaintBoundary boundary =
+ _qrKey.currentContext!.findRenderObject() as RenderRepaintBoundary;
+ final ui.Image image = await boundary.toImage(pixelRatio: 3.0);
+ final ByteData? byteData =
+ await image.toByteData(format: ui.ImageByteFormat.png);
+ if (byteData != null) {
+ final Uint8List pngBytes = byteData.buffer.asUint8List();
+
+ final directory = await getTemporaryDirectory();
+ final file = File(
+ '${directory.path}/ente_auth_qr_${widget.code.account}.png',
+ );
+ await file.writeAsBytes(pngBytes);
+
+ // Get the render box for share position (required for iPad)
+ final box = context.findRenderObject() as RenderBox?;
+ final sharePositionOrigin =
+ box != null ? box.localToGlobal(Offset.zero) & box.size : null;
+
+ await SharePlus.instance.share(
+ ShareParams(
+ files: [XFile(file.path)],
+ text: 'QR code for ${widget.code.account}',
+ sharePositionOrigin: sharePositionOrigin,
+ ),
+ );
+
+ // Close the dialog after sharing is initiated
+ if (mounted) {
+ Navigator.of(context).pop();
+ }
+ }
+ } catch (e) {
+ debugPrint('Error sharing QR code: $e');
+ }
+ }
+
+ @override
+ Widget build(BuildContext context) {
+ final screenWidth = MediaQuery.of(context).size.width;
+ final double qrSize = min(screenWidth - 80, 300.0);
+ final double qrCodeSize =
+ max(qrSize - 100, 150.0); // Ensure minimum size of 150
+ final enteTextTheme = getEnteTextTheme(context);
+ final enteColorScheme = getEnteColorScheme(context);
+ final l10n = context.l10n;
+
+ final String qrData = widget.code.rawData
+ .replaceAll('algorithm=Algorithm.', 'algorithm=')
+ .replaceAll('algorithm=sha1', 'algorithm=SHA1')
+ .replaceAll('algorithm=sha256', 'algorithm=SHA256')
+ .replaceAll('algorithm=sha512', 'algorithm=SHA512');
+
+ // Get account name, truncate if too long
+ final String accountName = (widget.code.account).length > 30
+ ? '${(widget.code.account).substring(0, 27)}...'
+ : widget.code.account;
+
+ final String issuerName = widget.code.issuer;
+
+ // QR text color - always black for scanability
+ const qrTextColor = textBaseLight;
+
+ final bool isDarkMode = Theme.of(context).brightness == Brightness.dark;
+
+ return Dialog(
+ shape: RoundedRectangleBorder(
+ borderRadius: BorderRadius.circular(24),
+ ),
+ child: Container(
+ padding: const EdgeInsets.fromLTRB(20, 18, 20, 20),
+ decoration: BoxDecoration(
+ color: enteColorScheme.backgroundBase,
+ borderRadius: BorderRadius.circular(24),
+ ),
+ child: Column(
+ mainAxisSize: MainAxisSize.min,
+ children: [
+ // Header with close button
+ Padding(
+ padding: const EdgeInsets.only(left: 6, bottom: 4),
+ child: Row(
+ mainAxisAlignment: MainAxisAlignment.spaceBetween,
+ children: [
+ Text(
+ l10n.qrCode,
+ style: enteTextTheme.largeBold.copyWith(
+ fontSize: 20,
+ fontWeight: FontWeight.w700,
+ ),
+ ),
+ GestureDetector(
+ onTap: () => Navigator.of(context).pop(),
+ child: Container(
+ width: 36,
+ height: 36,
+ decoration: BoxDecoration(
+ color: isDarkMode
+ ? enteColorScheme.backgroundElevated2
+ : qrBoxColor,
+ borderRadius: BorderRadius.circular(18),
+ ),
+ child: Icon(
+ Icons.close,
+ color:
+ isDarkMode ? enteColorScheme.textBase : qrTextColor,
+ size: 20,
+ ),
+ ),
+ ),
+ ],
+ ),
+ ),
+ const SizedBox(height: 8),
+
+ // QR Code with RepaintBoundary for sharing
+ 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 (inside border)
+ Text(
+ accountName,
+ style: enteTextTheme.largeBold.copyWith(
+ color: qrTextColor,
+ fontSize: 20,
+ ),
+ textAlign: TextAlign.center,
+ ),
+ if (issuerName.isNotEmpty) ...[
+ const SizedBox(height: 4),
+ Text(
+ issuerName,
+ style: enteTextTheme.small.copyWith(
+ color: qrTextColor.withValues(alpha: 0.7),
+ fontSize: 14,
+ ),
+ textAlign: TextAlign.center,
+ ),
+ ],
+ const SizedBox(height: 20),
+
+ // QR Code with pretty styling
+ SizedBox(
+ width: qrCodeSize,
+ height: qrCodeSize,
+ child: PrettyQrView(
+ qrImage: QrImage(
+ QrCode.fromData(
+ data: qrData,
+ errorCorrectLevel: QrErrorCorrectLevel.L,
+ ),
+ ),
+ decoration: const PrettyQrDecoration(
+ shape: PrettyQrShape.custom(
+ PrettyQrDotsSymbol(
+ color: qrTextColor,
+ unifiedFinderPattern: false,
+ unifiedAlignmentPatterns: false,
+ ),
+ finderPattern: PrettyQrSquaresSymbol(
+ color: qrTextColor,
+ rounding: 0.5,
+ unifiedFinderPattern: true,
+ finderPatternOuterThickness: 1.4,
+ finderPatternOuterColor: accentColor,
+ finderPatternInnerDotSize: 0.8,
+ finderPatternInnerRounding: 1.0,
+ ),
+ alignmentPatterns: PrettyQrSquaresSymbol(
+ color: qrTextColor,
+ rounding: 1.0,
+ ),
+ ),
+ image: PrettyQrDecorationImage(
+ image: AssetImage('assets/qr_logo.png'),
+ scale: 0.25,
+ padding: EdgeInsets.all(24),
+ position:
+ PrettyQrDecorationImagePosition.embedded,
+ ),
+ background: Colors.transparent,
+ quietZone: PrettyQrQuietZone.zero,
+ ),
+ ),
+ ),
+ const SizedBox(height: 42),
+ ],
+ ),
+
+ // Auth branding at bottom right (inside border)
+ Positioned(
+ bottom: 0,
+ right: 2,
+ child: SvgPicture.asset(
+ 'assets/svg/auth-logo.svg',
+ height: 12,
+ colorFilter: const ColorFilter.mode(
+ accentColor,
+ BlendMode.srcIn,
+ ),
+ ),
+ ),
+ ],
+ ),
+ ),
+ ),
+ const SizedBox(height: 24),
+
+ // Share button
+ GestureDetector(
+ onTap: _shareQrCode,
+ child: Container(
+ width: double.infinity,
+ padding:
+ const EdgeInsets.symmetric(horizontal: 16, vertical: 14),
+ decoration: BoxDecoration(
+ color: accentColor,
+ borderRadius: BorderRadius.circular(12),
+ ),
+ child: Text(
+ l10n.share,
+ textAlign: TextAlign.center,
+ style: enteTextTheme.bodyBold.copyWith(
+ color: Colors.white,
+ height: 1.25,
+ ),
+ ),
+ ),
+ ),
+ ],
+ ),
+ ),
+ );
+ }
+}
diff --git a/mobile/apps/auth/pubspec.lock b/mobile/apps/auth/pubspec.lock
index 9571ae068c..e467295970 100644
--- a/mobile/apps/auth/pubspec.lock
+++ b/mobile/apps/auth/pubspec.lock
@@ -1349,6 +1349,15 @@ packages:
url: "https://pub.dev"
source: hosted
version: "6.0.3"
+ pretty_qr_code:
+ dependency: "direct main"
+ description:
+ path: "."
+ ref: HEAD
+ resolved-ref: "912bf168492c90ee2a20b2997926372eb18adb0f"
+ url: "https://github.com/ente-io/flutter_pretty_qr_fork"
+ source: git
+ version: "3.5.0"
privacy_screen:
dependency: "direct main"
description:
diff --git a/mobile/apps/auth/pubspec.yaml b/mobile/apps/auth/pubspec.yaml
index 9adbbc22ed..83b4e75668 100644
--- a/mobile/apps/auth/pubspec.yaml
+++ b/mobile/apps/auth/pubspec.yaml
@@ -115,6 +115,9 @@ dependencies:
path_provider: ^2.0.11
pinput: ^5.0.0
pointycastle: ^3.7.3
+ pretty_qr_code:
+ git:
+ url: https://github.com/ente-io/flutter_pretty_qr_fork
privacy_screen: ^0.0.6
protobuf: ^4.1.0
qr_code_scanner: # no package updates on pub.dev