Skip to content

armgit / ente

Public Imported from GitHub
0

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

mobile: add legacy kit flow

Neeraj Gupta8e0366d86c4e
diff --git a/mobile/apps/locker/assets/2.0x/legacy_kit_advert_foreground.png b/mobile/apps/locker/assets/2.0x/legacy_kit_advert_foreground.png
new file mode 100644
index 0000000000..572ef5429f
Binary files /dev/null and b/mobile/apps/locker/assets/2.0x/legacy_kit_advert_foreground.png differ
diff --git a/mobile/apps/locker/assets/2.0x/legacy_kit_empty.png b/mobile/apps/locker/assets/2.0x/legacy_kit_empty.png
new file mode 100644
index 0000000000..1907d01efe
Binary files /dev/null and b/mobile/apps/locker/assets/2.0x/legacy_kit_empty.png differ
diff --git a/mobile/apps/locker/assets/2.0x/trusted_contact_empty.png b/mobile/apps/locker/assets/2.0x/trusted_contact_empty.png
new file mode 100644
index 0000000000..cc07372b98
Binary files /dev/null and b/mobile/apps/locker/assets/2.0x/trusted_contact_empty.png differ
diff --git a/mobile/apps/locker/assets/2.0x/trusted_contact_empty_dark.png b/mobile/apps/locker/assets/2.0x/trusted_contact_empty_dark.png
new file mode 100644
index 0000000000..f6c0534664
Binary files /dev/null and b/mobile/apps/locker/assets/2.0x/trusted_contact_empty_dark.png differ
diff --git a/mobile/apps/locker/assets/3.0x/legacy_kit_advert_foreground.png b/mobile/apps/locker/assets/3.0x/legacy_kit_advert_foreground.png
new file mode 100644
index 0000000000..4650cfcabf
Binary files /dev/null and b/mobile/apps/locker/assets/3.0x/legacy_kit_advert_foreground.png differ
diff --git a/mobile/apps/locker/assets/3.0x/legacy_kit_empty.png b/mobile/apps/locker/assets/3.0x/legacy_kit_empty.png
new file mode 100644
index 0000000000..4c8c593194
Binary files /dev/null and b/mobile/apps/locker/assets/3.0x/legacy_kit_empty.png differ
diff --git a/mobile/apps/locker/assets/3.0x/trusted_contact_empty.png b/mobile/apps/locker/assets/3.0x/trusted_contact_empty.png
new file mode 100644
index 0000000000..70536c981a
Binary files /dev/null and b/mobile/apps/locker/assets/3.0x/trusted_contact_empty.png differ
diff --git a/mobile/apps/locker/assets/3.0x/trusted_contact_empty_dark.png b/mobile/apps/locker/assets/3.0x/trusted_contact_empty_dark.png
new file mode 100644
index 0000000000..af06f65456
Binary files /dev/null and b/mobile/apps/locker/assets/3.0x/trusted_contact_empty_dark.png differ
diff --git a/mobile/apps/locker/assets/legacy_kit_advert_foreground.png b/mobile/apps/locker/assets/legacy_kit_advert_foreground.png
new file mode 100644
index 0000000000..543da05211
Binary files /dev/null and b/mobile/apps/locker/assets/legacy_kit_advert_foreground.png differ
diff --git a/mobile/apps/locker/assets/legacy_kit_empty.png b/mobile/apps/locker/assets/legacy_kit_empty.png
new file mode 100644
index 0000000000..c586f23ea9
Binary files /dev/null and b/mobile/apps/locker/assets/legacy_kit_empty.png differ
diff --git a/mobile/apps/locker/assets/trusted_contact_empty.png b/mobile/apps/locker/assets/trusted_contact_empty.png
new file mode 100644
index 0000000000..ec561e38ba
Binary files /dev/null and b/mobile/apps/locker/assets/trusted_contact_empty.png differ
diff --git a/mobile/apps/locker/assets/trusted_contact_empty_dark.png b/mobile/apps/locker/assets/trusted_contact_empty_dark.png
new file mode 100644
index 0000000000..c460118a9c
Binary files /dev/null and b/mobile/apps/locker/assets/trusted_contact_empty_dark.png differ
diff --git a/mobile/apps/locker/lib/main.dart b/mobile/apps/locker/lib/main.dart
index 1d069d73ab..8aed250c97 100644
--- a/mobile/apps/locker/lib/main.dart
+++ b/mobile/apps/locker/lib/main.dart
@@ -6,6 +6,7 @@ import 'package:ente_accounts/services/user_service.dart';
import 'package:ente_crypto_api/ente_crypto_api.dart';
import 'package:ente_crypto_dart_adapter/ente_crypto_dart_adapter.dart';
import "package:ente_legacy/services/emergency_service.dart";
+import "package:ente_legacy/services/legacy_kit_service.dart";
import 'package:ente_lock_screen/lock_screen_settings.dart';
import 'package:ente_lock_screen/ui/app_lock.dart';
import 'package:ente_lock_screen/ui/lock_screen.dart';
@@ -223,6 +224,10 @@ Future<void> _init(bool bool, {String? via}) async {
preferences: preferences,
packageInfo: packageInfo,
);
+ await LegacyKitService.instance.init(
+ config: Configuration.instance,
+ sessionProvider: LockerContactsDisplayService.buildSession,
+ );
} catch (e) {
_logger.severe("Error during initialization", e);
}
diff --git a/mobile/apps/locker/lib/services/contacts_display_service.dart b/mobile/apps/locker/lib/services/contacts_display_service.dart
index 25e9b4755e..c1ec0fcf98 100644
--- a/mobile/apps/locker/lib/services/contacts_display_service.dart
+++ b/mobile/apps/locker/lib/services/contacts_display_service.dart
@@ -21,7 +21,7 @@ class LockerContactsDisplayService {
}
static Future<void> ensureReady() async {
- final session = _buildSession();
+ final session = buildSession();
if (session == null) {
return;
}
@@ -68,7 +68,7 @@ class LockerContactsDisplayService {
return current;
}
- static contacts.ContactsSession? _buildSession() {
+ static contacts.ContactsSession? buildSession() {
final packageInfo = _packageInfo;
final token = Configuration.instance.getToken();
final userId = Configuration.instance.getUserID();
diff --git a/mobile/apps/locker/lib/ui/utils/legacy_utils.dart b/mobile/apps/locker/lib/ui/utils/legacy_utils.dart
index e3b2db1555..dbf90bb4d8 100644
--- a/mobile/apps/locker/lib/ui/utils/legacy_utils.dart
+++ b/mobile/apps/locker/lib/ui/utils/legacy_utils.dart
@@ -19,7 +19,16 @@ Future<void> openLegacyPage(BuildContext context) async {
await Navigator.of(context).push(
MaterialPageRoute(
builder: (BuildContext context) {
- return EmergencyPage(config: Configuration.instance);
+ return EmergencyPage(
+ config: Configuration.instance,
+ legacyKitAuthenticator: (context, reason) async {
+ if (kDebugMode) {
+ return true;
+ }
+ return LocalAuthenticationService.instance
+ .requestLocalAuthentication(context, reason);
+ },
+ );
},
),
);
diff --git a/mobile/apps/locker/pubspec.lock b/mobile/apps/locker/pubspec.lock
index fa3eeb70fb..31e3b2d2b9 100644
--- a/mobile/apps/locker/pubspec.lock
+++ b/mobile/apps/locker/pubspec.lock
@@ -73,6 +73,22 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.13.0"
+ barcode:
+ dependency: transitive
+ description:
+ name: barcode
+ sha256: "7b6729c37e3b7f34233e2318d866e8c48ddb46c1f7ad01ff7bb2a8de1da2b9f4"
+ url: "https://pub.dev"
+ source: hosted
+ version: "2.2.9"
+ bidi:
+ dependency: transitive
+ description:
+ name: bidi
+ sha256: "77f475165e94b261745cf1032c751e2032b8ed92ccb2bf5716036db79320637d"
+ url: "https://pub.dev"
+ source: hosted
+ version: "2.0.13"
bip39:
dependency: "direct main"
description:
@@ -689,10 +705,10 @@ packages:
dependency: transitive
description:
name: image
- sha256: "492bd52f6c4fbb6ee41f781ff27765ce5f627910e1e0cbecfa3d9add5562604c"
+ sha256: "4e973fcf4caae1a4be2fa0a13157aa38a8f9cb049db6529aa00b4d71abc4d928"
url: "https://pub.dev"
source: hosted
- version: "4.7.2"
+ version: "4.5.4"
intl:
dependency: "direct main"
description:
@@ -1045,6 +1061,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.3.0"
+ pdf:
+ dependency: transitive
+ description:
+ name: pdf
+ sha256: "28eacad99bffcce2e05bba24e50153890ad0255294f4dd78a17075a2ba5c8416"
+ url: "https://pub.dev"
+ source: hosted
+ version: "3.11.3"
petitparser:
dependency: transitive
description:
@@ -1109,6 +1133,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.2.0"
+ qr:
+ dependency: transitive
+ description:
+ name: qr
+ sha256: "5a1d2586170e172b8a8c8470bbbffd5eb0cd38a66c0d77155ea138d3af3a4445"
+ url: "https://pub.dev"
+ source: hosted
+ version: "3.0.2"
screen_retriever:
dependency: transitive
description:
diff --git a/mobile/packages/.gitignore b/mobile/packages/.gitignore
index 009c454944..877ebfbd95 100644
--- a/mobile/packages/.gitignore
+++ b/mobile/packages/.gitignore
@@ -1,2 +1,3 @@
.dart_tool/
.flutter-plugins-dependencies
+build/
diff --git a/mobile/packages/legacy/lib/components/gradient_button.dart b/mobile/packages/legacy/lib/components/gradient_button.dart
index 696a145cfc..49c55eaa1f 100644
--- a/mobile/packages/legacy/lib/components/gradient_button.dart
+++ b/mobile/packages/legacy/lib/components/gradient_button.dart
@@ -7,6 +7,10 @@ class GradientButton extends StatelessWidget {
final IconData? icon;
final double paddingValue;
final Color? backgroundColor;
+ final Color? textColor;
+ final Color? disabledTextColor;
+ final double height;
+ final TextStyle? textStyle;
const GradientButton({
super.key,
@@ -15,13 +19,17 @@ class GradientButton extends StatelessWidget {
this.icon,
this.paddingValue = 6.0,
this.backgroundColor,
+ this.textColor,
+ this.disabledTextColor,
+ this.height = 56,
+ this.textStyle,
});
static const TextStyle _textStyle = TextStyle(
color: Colors.white,
fontWeight: FontWeight.w600,
fontFamily: 'Inter-SemiBold',
- fontSize: 18,
+ fontSize: 18.0,
);
@override
@@ -30,8 +38,10 @@ class GradientButton extends StatelessWidget {
final bool isEnabled = onTap != null;
final Color effectiveBackgroundColor = backgroundColor ??
(isEnabled ? colorScheme.primary700 : colorScheme.fillFaint);
- final TextStyle effectiveTextStyle = _textStyle.copyWith(
- color: isEnabled ? Colors.white : colorScheme.textMuted,
+ final TextStyle effectiveTextStyle = (textStyle ?? _textStyle).copyWith(
+ color: isEnabled
+ ? (textColor ?? Colors.white)
+ : (disabledTextColor ?? colorScheme.textMuted),
);
final Widget textWidget = Text(text, style: effectiveTextStyle);
@@ -44,7 +54,9 @@ class GradientButton extends StatelessWidget {
children: [
Icon(
icon,
- color: isEnabled ? Colors.white : colorScheme.textMuted,
+ color: isEnabled
+ ? (textColor ?? Colors.white)
+ : (disabledTextColor ?? colorScheme.textMuted),
),
Padding(padding: EdgeInsets.symmetric(horizontal: paddingValue)),
if (text.isNotEmpty) textWidget,
@@ -61,7 +73,7 @@ class GradientButton extends StatelessWidget {
splashColor: isEnabled ? null : Colors.transparent,
highlightColor: isEnabled ? null : Colors.transparent,
child: SizedBox(
- height: 56,
+ height: height,
child: Center(child: content),
),
),
diff --git a/mobile/packages/legacy/lib/components/legacy_kit_icons.dart b/mobile/packages/legacy/lib/components/legacy_kit_icons.dart
new file mode 100644
index 0000000000..2dfb22158e
--- /dev/null
+++ b/mobile/packages/legacy/lib/components/legacy_kit_icons.dart
@@ -0,0 +1,67 @@
+import "package:flutter/widgets.dart";
+import "package:hugeicons/hugeicons.dart";
+
+const double _hugeIconStrokeWidth = 1.5;
+
+class LegacyKitDownloadIcon extends StatelessWidget {
+ final Color color;
+ final double size;
+
+ const LegacyKitDownloadIcon({
+ required this.color,
+ this.size = 18,
+ super.key,
+ });
+
+ @override
+ Widget build(BuildContext context) {
+ return HugeIcon(
+ icon: HugeIcons.strokeRoundedDownload02,
+ color: color,
+ size: size,
+ strokeWidth: _hugeIconStrokeWidth,
+ );
+ }
+}
+
+class LegacyKitEditIcon extends StatelessWidget {
+ final Color color;
+ final double size;
+
+ const LegacyKitEditIcon({
+ required this.color,
+ this.size = 18,
+ super.key,
+ });
+
+ @override
+ Widget build(BuildContext context) {
+ return HugeIcon(
+ icon: HugeIcons.strokeRoundedPencilEdit02,
+ color: color,
+ size: size,
+ strokeWidth: _hugeIconStrokeWidth,
+ );
+ }
+}
+
+class LegacyKitClockIcon extends StatelessWidget {
+ final Color color;
+ final double size;
+
+ const LegacyKitClockIcon({
+ required this.color,
+ this.size = 18,
+ super.key,
+ });
+
+ @override
+ Widget build(BuildContext context) {
+ return HugeIcon(
+ icon: HugeIcons.strokeRoundedClock01,
+ color: color,
+ size: size,
+ strokeWidth: _hugeIconStrokeWidth,
+ );
+ }
+}
diff --git a/mobile/packages/legacy/lib/components/recovery_date_selector.dart b/mobile/packages/legacy/lib/components/recovery_date_selector.dart
index d9bad36042..7cfbbdfc68 100644
--- a/mobile/packages/legacy/lib/components/recovery_date_selector.dart
+++ b/mobile/packages/legacy/lib/components/recovery_date_selector.dart
@@ -2,13 +2,19 @@ import "package:ente_strings/ente_strings.dart";
import "package:ente_ui/theme/ente_theme.dart";
import "package:flutter/material.dart";
+enum RecoveryDateSelectorLayout { chips, list }
+
class RecoveryDateSelector extends StatelessWidget {
final int selectedDays;
final ValueChanged<int> onDaysChanged;
+ final List<int> dayOptions;
+ final RecoveryDateSelectorLayout layout;
const RecoveryDateSelector({
required this.selectedDays,
required this.onDaysChanged,
+ this.dayOptions = const [7, 14, 30],
+ this.layout = RecoveryDateSelectorLayout.chips,
super.key,
});
@@ -17,16 +23,26 @@ class RecoveryDateSelector extends StatelessWidget {
final colorScheme = getEnteColorScheme(context);
final textTheme = getEnteTextTheme(context);
- return Row(
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- children: [
- _buildChip(context, 7, colorScheme, textTheme),
- const SizedBox(width: 12),
- _buildChip(context, 14, colorScheme, textTheme),
- const SizedBox(width: 12),
- _buildChip(context, 30, colorScheme, textTheme),
- ],
- );
+ return switch (layout) {
+ RecoveryDateSelectorLayout.chips => _buildChips(
+ context,
+ colorScheme,
+ textTheme,
+ ),
+ RecoveryDateSelectorLayout.list => Column(
+ children: [
+ for (var index = 0; index < dayOptions.length; index++) ...[
+ _buildListItem(
+ context,
+ dayOptions[index],
+ colorScheme,
+ textTheme,
+ ),
+ if (index < dayOptions.length - 1) const SizedBox(height: 8),
+ ],
+ ],
+ ),
+ };
}
Widget _buildChip(
@@ -48,7 +64,7 @@ class RecoveryDateSelector extends StatelessWidget {
borderRadius: BorderRadius.circular(14),
),
child: Text(
- context.strings.nDays(days),
+ days == 0 ? context.strings.immediate : context.strings.nDays(days),
style: textTheme.bodyBold.copyWith(
color: isSelected ? Colors.white : colorScheme.primary700,
),
@@ -56,4 +72,89 @@ class RecoveryDateSelector extends StatelessWidget {
),
);
}
+
+ Widget _buildChips(
+ BuildContext context,
+ colorScheme,
+ textTheme,
+ ) {
+ final chips = dayOptions
+ .map((days) => _buildChip(context, days, colorScheme, textTheme))
+ .toList(growable: false);
+
+ if (chips.length == 3) {
+ return Row(
+ mainAxisAlignment: MainAxisAlignment.spaceBetween,
+ children: [
+ chips[0],
+ const SizedBox(width: 12),
+ chips[1],
+ const SizedBox(width: 12),
+ chips[2],
+ ],
+ );
+ }
+
+ return Wrap(
+ spacing: 12,
+ runSpacing: 12,
+ children: chips,
+ );
+ }
+
+ Widget _buildListItem(
+ BuildContext context,
+ int days,
+ colorScheme,
+ textTheme,
+ ) {
+ final isSelected = selectedDays == days;
+ final cardColor = colorScheme.isLightTheme
+ ? Colors.white
+ : colorScheme.backgroundElevated2;
+ final borderColor = colorScheme.primary700.withValues(alpha: 0.24);
+
+ return Material(
+ color: cardColor,
+ borderRadius: BorderRadius.circular(20),
+ child: InkWell(
+ borderRadius: BorderRadius.circular(20),
+ onTap: () => onDaysChanged(days),
+ child: Container(
+ height: 60,
+ padding: const EdgeInsets.only(left: 16, right: 12),
+ decoration: BoxDecoration(
+ borderRadius: BorderRadius.circular(20),
+ border: isSelected ? Border.all(color: borderColor) : null,
+ ),
+ child: Row(
+ children: [
+ Expanded(
+ child: Text(
+ days == 0
+ ? context.strings.immediate
+ : context.strings.nDays(days),
+ style: textTheme.small.copyWith(height: 20 / 14),
+ overflow: TextOverflow.ellipsis,
+ ),
+ ),
+ SizedBox(
+ width: 34,
+ height: 34,
+ child: isSelected
+ ? Center(
+ child: Icon(
+ Icons.check_circle,
+ size: 18,
+ color: colorScheme.primary700,
+ ),
+ )
+ : const SizedBox.shrink(),
+ ),
+ ],
+ ),
+ ),
+ ),
+ );
+ }
}
diff --git a/mobile/packages/legacy/lib/ente_legacy.dart b/mobile/packages/legacy/lib/ente_legacy.dart
index ad41738510..3e8ac5983c 100644
--- a/mobile/packages/legacy/lib/ente_legacy.dart
+++ b/mobile/packages/legacy/lib/ente_legacy.dart
@@ -1,5 +1,9 @@
export 'models/emergency_models.dart';
+export 'models/legacy_kit_models.dart';
+export 'pages/create_legacy_kit_sheet.dart';
export 'pages/emergency_page.dart';
+export 'pages/legacy_kit_page.dart';
export 'pages/other_contact_page.dart';
export 'pages/recover_others_account.dart';
export 'services/emergency_service.dart';
+export 'services/legacy_kit_service.dart';
diff --git a/mobile/packages/legacy/lib/models/legacy_kit_models.dart b/mobile/packages/legacy/lib/models/legacy_kit_models.dart
new file mode 100644
index 0000000000..1144d9a336
--- /dev/null
+++ b/mobile/packages/legacy/lib/models/legacy_kit_models.dart
@@ -0,0 +1,222 @@
+import "dart:convert";
+
+import "package:ente_rust/ente_rust.dart" as rust;
+
+enum LegacyKitRecoveryStatus {
+ waiting,
+ ready,
+ blocked,
+ cancelled,
+ recovered,
+}
+
+class LegacyKitRecoverySession {
+ final String id;
+ final String kitId;
+ final LegacyKitRecoveryStatus status;
+ final int waitTill;
+ final int createdAt;
+
+ const LegacyKitRecoverySession({
+ required this.id,
+ required this.kitId,
+ required this.status,
+ required this.waitTill,
+ required this.createdAt,
+ });
+
+ factory LegacyKitRecoverySession.fromRust(
+ rust.LegacyKitRecoverySession session,
+ ) {
+ return LegacyKitRecoverySession(
+ id: session.id,
+ kitId: session.kitId,
+ status: _statusFromRust(session.status),
+ waitTill: session.waitTill,
+ createdAt: session.createdAt,
+ );
+ }
+}
+
+class LegacyKitRecoveryInitiatorHint {
+ final List<int> usedPartIndexes;
+ final String ip;
+ final String userAgent;
+
+ const LegacyKitRecoveryInitiatorHint({
+ required this.usedPartIndexes,
+ required this.ip,
+ required this.userAgent,
+ });
+
+ factory LegacyKitRecoveryInitiatorHint.fromRust(
+ rust.LegacyKitRecoveryInitiatorHint hint,
+ ) {
+ return LegacyKitRecoveryInitiatorHint(
+ usedPartIndexes: hint.usedPartIndexes,
+ ip: hint.ip,
+ userAgent: hint.userAgent,
+ );
+ }
+}
+
+class LegacyKitOwnerRecoverySessionDetails {
+ final LegacyKitRecoverySession? session;
+ final List<LegacyKitRecoveryInitiatorHint> initiators;
+
+ const LegacyKitOwnerRecoverySessionDetails({
+ required this.session,
+ required this.initiators,
+ });
+
+ factory LegacyKitOwnerRecoverySessionDetails.fromRust(
+ rust.LegacyKitOwnerRecoverySessionDetails details,
+ ) {
+ return LegacyKitOwnerRecoverySessionDetails(
+ session: details.session == null
+ ? null
+ : LegacyKitRecoverySession.fromRust(details.session!),
+ initiators: details.initiators
+ .map(LegacyKitRecoveryInitiatorHint.fromRust)
+ .toList(growable: false),
+ );
+ }
+}
+
+class LegacyKitPart {
+ final int index;
+ final String name;
+
+ const LegacyKitPart({
+ required this.index,
+ required this.name,
+ });
+
+ factory LegacyKitPart.fromRust(rust.LegacyKitPart part) {
+ return LegacyKitPart(index: part.index, name: part.name);
+ }
+}
+
+class LegacyKit {
+ final String id;
+ final int noticePeriodInHours;
+ final List<LegacyKitPart> parts;
+ final int createdAt;
+ final int updatedAt;
+ final LegacyKitRecoverySession? activeRecoverySession;
+
+ const LegacyKit({
+ required this.id,
+ required this.noticePeriodInHours,
+ required this.parts,
+ required this.createdAt,
+ required this.updatedAt,
+ required this.activeRecoverySession,
+ });
+
+ factory LegacyKit.fromRust(rust.LegacyKit kit) {
+ return LegacyKit(
+ id: kit.id,
+ noticePeriodInHours: kit.noticePeriodInHours,
+ parts: kit.metadata.parts.map(LegacyKitPart.fromRust).toList(
+ growable: false,
+ ),
+ createdAt: kit.createdAt,
+ updatedAt: kit.updatedAt,
+ activeRecoverySession: kit.activeRecoverySession == null
+ ? null
+ : LegacyKitRecoverySession.fromRust(kit.activeRecoverySession!),
+ );
+ }
+
+ String get displayName => parts.map((part) => part.name).join(" Β· ");
+
+ bool get hasActiveRecoverySession => activeRecoverySession != null;
+}
+
+class LegacyKitShare {
+ final int payloadVersion;
+ final int variant;
+ final String kitId;
+ final int shareIndex;
+ final String share;
+ final String checksum;
+ final String partName;
+
+ const LegacyKitShare({
+ required this.payloadVersion,
+ required this.variant,
+ required this.kitId,
+ required this.shareIndex,
+ required this.share,
+ required this.checksum,
+ required this.partName,
+ });
+
+ factory LegacyKitShare.fromRust(rust.LegacyKitShare share) {
+ return LegacyKitShare(
+ payloadVersion: share.payloadVersion,
+ variant: _variantToCode(share.variant),
+ kitId: share.kitId,
+ shareIndex: share.shareIndex,
+ share: share.share,
+ checksum: share.checksum,
+ partName: share.partName,
+ );
+ }
+
+ String toQrPayload() {
+ return jsonEncode({
+ "pv": payloadVersion,
+ "kv": variant,
+ "k": _withoutWhitespace(kitId),
+ "i": shareIndex,
+ "s": _withoutWhitespace(share),
+ "c": _withoutWhitespace(checksum),
+ "n": partName,
+ });
+ }
+
+ String toCopyCode() {
+ return base64Url.encode(utf8.encode(toQrPayload())).replaceAll("=", "");
+ }
+
+ String _withoutWhitespace(String value) {
+ return value.replaceAll(RegExp(r"\s+"), "");
+ }
+}
+
+class LegacyKitCreateResult {
+ final LegacyKit kit;
+ final List<LegacyKitShare> shares;
+
+ const LegacyKitCreateResult({
+ required this.kit,
+ required this.shares,
+ });
+
+ factory LegacyKitCreateResult.fromRust(rust.LegacyKitCreateResult result) {
+ return LegacyKitCreateResult(
+ kit: LegacyKit.fromRust(result.kit),
+ shares: result.shares.map(LegacyKitShare.fromRust).toList(
+ growable: false,
+ ),
+ );
+ }
+}
+
+LegacyKitRecoveryStatus _statusFromRust(rust.LegacyKitRecoveryStatus status) {
+ return switch (status) {
+ rust.LegacyKitRecoveryStatus.waiting => LegacyKitRecoveryStatus.waiting,
+ rust.LegacyKitRecoveryStatus.ready => LegacyKitRecoveryStatus.ready,
+ rust.LegacyKitRecoveryStatus.blocked => LegacyKitRecoveryStatus.blocked,
+ rust.LegacyKitRecoveryStatus.cancelled => LegacyKitRecoveryStatus.cancelled,
+ rust.LegacyKitRecoveryStatus.recovered => LegacyKitRecoveryStatus.recovered,
+ };
+}
+
+int _variantToCode(rust.LegacyKitVariant variant) {
+ return switch (variant) {
+ rust.LegacyKitVariant.twoOfThree => 1,
+ };
+}
diff --git a/mobile/packages/legacy/lib/pages/create_legacy_kit_sheet.dart b/mobile/packages/legacy/lib/pages/create_legacy_kit_sheet.dart
new file mode 100644
index 0000000000..3ba61447c6
--- /dev/null
+++ b/mobile/packages/legacy/lib/pages/create_legacy_kit_sheet.dart
@@ -0,0 +1,572 @@
+import "package:ente_legacy/components/gradient_button.dart";
+import "package:ente_legacy/components/legacy_kit_icons.dart";
+import "package:ente_legacy/components/recovery_date_selector.dart";
+import "package:ente_strings/ente_strings.dart";
+import "package:ente_ui/components/base_bottom_sheet.dart";
+import "package:ente_ui/components/menu_section_title.dart";
+import "package:ente_ui/theme/ente_theme.dart";
+import "package:flutter/material.dart";
+
+class LegacyKitCreateInput {
+ final List<String> partNames;
+ final int noticePeriodInHours;
+
+ const LegacyKitCreateInput({
+ required this.partNames,
+ required this.noticePeriodInHours,
+ });
+}
+
+Future<LegacyKitCreateInput?> showCreateLegacyKitSheet(BuildContext context) {
+ return showCreateLegacyKitPage(context);
+}
+
+Future<LegacyKitCreateInput?> showCreateLegacyKitPage(BuildContext context) {
+ return Navigator.of(context).push<LegacyKitCreateInput>(
+ MaterialPageRoute(
+ builder: (context) => const CreateLegacyKitPage(),
+ ),
+ );
+}
+
+Future<LegacyKitCreateInput?> showCreateLegacyKitBottomSheet(
+ BuildContext context,
+) {
+ return showBaseBottomSheet<LegacyKitCreateInput>(
+ context,
+ title: context.strings.createLegacyKit,
+ headerSpacing: 20,
+ isKeyboardAware: true,
+ child: const CreateLegacyKitSheet(),
+ );
+}
+
+Future<int?> showLegacyKitRecoveryWaitTimeSheet(
+ BuildContext context, {
+ required int selectedDays,
+ bool showCancellationWarning = true,
+}) {
+ final colorScheme = getEnteColorScheme(context);
+ final textTheme = getEnteTextTheme(context);
+ return showBaseBottomSheet<int>(
+ context,
+ title: context.strings.recoveryWaitTime,
+ headerSpacing: 16,
+ backgroundColor: colorScheme.backgroundBase,
+ padding: const EdgeInsets.all(20),
+ borderRadius: const BorderRadius.only(
+ topLeft: Radius.circular(20),
+ topRight: Radius.circular(20),
+ ),
+ border: Border.all(color: colorScheme.fillMuted),
+ titleTextStyle: textTheme.largeBold.copyWith(
+ fontSize: 18.0,
+ height: 24 / 18,
+ ),
+ child: _LegacyKitRecoveryWaitSheet(
+ selectedDays: selectedDays,
+ showCancellationWarning: showCancellationWarning,
+ ),
+ );
+}
+
+class CreateLegacyKitPage extends StatefulWidget {
+ const CreateLegacyKitPage({super.key});
+
+ @override
+ State<CreateLegacyKitPage> createState() => _CreateLegacyKitPageState();
+}
+
+class _CreateLegacyKitPageState extends State<CreateLegacyKitPage> {
+ final List<TextEditingController> _controllers = List.generate(
+ 3,
+ (_) => TextEditingController(),
+ );
+ final List<FocusNode> _focusNodes = List.generate(3, (_) => FocusNode());
+ int _selectedDays = 7;
+
+ @override
+ void dispose() {
+ for (final controller in _controllers) {
+ controller.dispose();
+ }
+ for (final focusNode in _focusNodes) {
+ focusNode.dispose();
+ }
+ super.dispose();
+ }
+
+ @override
+ Widget build(BuildContext context) {
+ final colorScheme = getEnteColorScheme(context);
+ final textTheme = getEnteTextTheme(context);
+
+ return Scaffold(
+ backgroundColor: colorScheme.backgroundBase,
+ appBar: AppBar(
+ backgroundColor: colorScheme.backgroundBase,
+ surfaceTintColor: Colors.transparent,
+ elevation: 0,
+ toolbarHeight: 48,
+ leadingWidth: 48,
+ leading: GestureDetector(
+ onTap: () => Navigator.pop(context),
+ child: const Icon(Icons.arrow_back_outlined),
+ ),
+ ),
+ body: ListView(
+ padding: const EdgeInsets.symmetric(horizontal: 16),
+ children: [
+ Text(
+ "Create a legacy kit",
+ style: textTheme.largeBold.copyWith(
+ fontSize: 20.0,
+ height: 28 / 20,
+ ),
+ ),
+ const SizedBox(height: 4),
+ Text(
+ context.strings.legacyKitCreateDescription,
+ style: textTheme.smallMuted.copyWith(height: 20 / 14),
+ ),
+ const SizedBox(height: 20),
+ for (var index = 0; index < _controllers.length; index++) ...[
+ _LegacyKitNameField(
+ controller: _controllers[index],
+ focusNode: _focusNodes[index],
+ hintText: _hintForIndex(context, index),
+ textInputAction:
+ index == 2 ? TextInputAction.done : TextInputAction.next,
+ onSubmitted: (_) {
+ if (index < 2) {
+ _focusNodes[index + 1].requestFocus();
+ } else {
+ _focusNodes[index].unfocus();
+ }
+ },
+ onChanged: (_) => setState(() {}),
+ ),
+ if (index < _controllers.length - 1) const SizedBox(height: 16),
+ ],
+ const SizedBox(height: 20),
+ MenuSectionTitle(
+ title: context.strings.settings,
+ padding: EdgeInsets.zero,
+ textStyle: textTheme.bodyBold,
+ ),
+ const SizedBox(height: 8),
+ _RecoveryWaitTimeRow(
+ title: context.strings.recoveryWaitTime,
+ value: _formatNoticePeriod(_selectedDays * 24),
+ onTap: _editRecoveryWaitTime,
+ ),
+ ],
+ ),
+ bottomNavigationBar: SafeArea(
+ top: false,
+ child: Container(
+ color: colorScheme.backgroundBase,
+ padding: const EdgeInsets.all(24),
+ child: GradientButton(
+ text: context.strings.createKit,
+ height: 48,
+ textStyle: textTheme.small.copyWith(height: 20 / 14),
+ onTap: _isValid ? _submit : null,
+ ),
+ ),
+ ),
+ );
+ }
+
+ Future<void> _editRecoveryWaitTime() async {
+ final selectedDays = await showLegacyKitRecoveryWaitTimeSheet(
+ context,
+ selectedDays: _selectedDays,
+ showCancellationWarning: false,
+ );
+ if (selectedDays != null && mounted) {
+ setState(() {
+ _selectedDays = selectedDays;
+ });
+ }
+ }
+
+ bool get _isValid {
+ final names = _partNames;
+ return names.length == 3 &&
+ names.every((name) => name.isNotEmpty) &&
+ names.toSet().length == 3;
+ }
+
+ List<String> get _partNames {
+ return _controllers
+ .map((controller) => controller.text.trim())
+ .where((name) => name.isNotEmpty)
+ .toList(growable: false);
+ }
+
+ void _submit() {
+ Navigator.of(context).pop(
+ LegacyKitCreateInput(
+ partNames: _partNames,
+ noticePeriodInHours: _selectedDays * 24,
+ ),
+ );
+ }
+
+ String _hintForIndex(BuildContext context, int index) {
+ const examples = ["Mom", "Alex", "Lawyer"];
+ return "e.g. ${examples[index]}";
+ }
+
+ String _formatNoticePeriod(int hours) {
+ if (hours == 0) {
+ return context.strings.immediate;
+ }
+ if (hours % 24 == 0) {
+ return context.strings.nDays(hours ~/ 24);
+ }
+ return context.strings.nHours(hours);
+ }
+}
+
+class _RecoveryWaitTimeRow extends StatelessWidget {
+ final String title;
+ final String value;
+ final VoidCallback onTap;
+
+ const _RecoveryWaitTimeRow({
+ required this.title,
+ required this.value,
+ required this.onTap,
+ });
+
+ @override
+ Widget build(BuildContext context) {
+ final colorScheme = getEnteColorScheme(context);
+ final textTheme = getEnteTextTheme(context);
+ final cardColor = colorScheme.isLightTheme
+ ? Colors.white
+ : colorScheme.backgroundElevated2;
+
+ return Material(
+ color: cardColor,
+ borderRadius: BorderRadius.circular(20),
+ child: InkWell(
+ borderRadius: BorderRadius.circular(20),
+ onTap: onTap,
+ child: SizedBox(
+ height: 60,
+ child: Padding(
+ padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 10),
+ child: Row(
+ children: [
+ SizedBox(
+ height: 36,
+ width: 36,
+ child: Center(
+ child: LegacyKitClockIcon(
+ color: colorScheme.primary700,
+ ),
+ ),
+ ),
+ const SizedBox(width: 12),
+ Expanded(
+ child: Column(
+ mainAxisAlignment: MainAxisAlignment.center,
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ Text(
+ title,
+ style: textTheme.small.copyWith(height: 20 / 14),
+ overflow: TextOverflow.ellipsis,
+ ),
+ const SizedBox(height: 4),
+ Text(
+ value,
+ style: textTheme.mini.copyWith(
+ color: colorScheme.textMuted,
+ height: 16 / 12,
+ ),
+ overflow: TextOverflow.ellipsis,
+ ),
+ ],
+ ),
+ ),
+ SizedBox(
+ height: 40,
+ width: 40,
+ child: Center(
+ child: LegacyKitEditIcon(
+ color: colorScheme.textBase,
+ ),
+ ),
+ ),
+ ],
+ ),
+ ),
+ ),
+ ),
+ );
+ }
+}
+
+class CreateLegacyKitSheet extends StatefulWidget {
+ const CreateLegacyKitSheet({super.key});
+
+ @override
+ State<CreateLegacyKitSheet> createState() => _CreateLegacyKitSheetState();
+}
+
+class _LegacyKitRecoveryWaitSheet extends StatefulWidget {
+ final int selectedDays;
+ final bool showCancellationWarning;
+
+ const _LegacyKitRecoveryWaitSheet({
+ required this.selectedDays,
+ required this.showCancellationWarning,
+ });
+
+ @override
+ State<_LegacyKitRecoveryWaitSheet> createState() =>
+ _LegacyKitRecoveryWaitSheetState();
+}
+
+class _LegacyKitRecoveryWaitSheetState
+ extends State<_LegacyKitRecoveryWaitSheet> {
+ late int _selectedDays = widget.selectedDays;
+ bool get _hasChanges => _selectedDays != widget.selectedDays;
+
+ @override
+ Widget build(BuildContext context) {
+ final colorScheme = getEnteColorScheme(context);
+ final textTheme = getEnteTextTheme(context);
+
+ return Column(
+ mainAxisSize: MainAxisSize.min,
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ Text(
+ "How long before account recovery can happen after your sheets are scanned.",
+ style: textTheme.small.copyWith(
+ color: colorScheme.textMuted,
+ height: 20 / 14,
+ ),
+ ),
+ if (widget.showCancellationWarning) ...[
+ const SizedBox(height: 12),
+ Text(
+ "Changing this will cancel any ongoing attempts.",
+ style: textTheme.small.copyWith(
+ color: colorScheme.textMuted,
+ height: 20 / 14,
+ ),
+ ),
+ ],
+ const SizedBox(height: 16),
+ RecoveryDateSelector(
+ selectedDays: _selectedDays,
+ dayOptions: const [0, 1, 7, 15, 30],
+ layout: RecoveryDateSelectorLayout.list,
+ onDaysChanged: (days) {
+ setState(() {
+ _selectedDays = days;
+ });
+ },
+ ),
+ const SizedBox(height: 16),
+ GradientButton(
+ text: context.strings.confirm,
+ height: 52,
+ textStyle: textTheme.small.copyWith(height: 20 / 14),
+ disabledTextColor: colorScheme.textFaint,
+ onTap: _hasChanges
+ ? () => Navigator.of(context).pop(_selectedDays)
+ : null,
+ ),
+ ],
+ );
+ }
+}
+
+class _LegacyKitNameField extends StatelessWidget {
+ final TextEditingController controller;
+ final FocusNode focusNode;
+ final String hintText;
+ final TextInputAction textInputAction;
+ final ValueChanged<String> onChanged;
+ final ValueChanged<String> onSubmitted;
+
+ const _LegacyKitNameField({
+ required this.controller,
+ required this.focusNode,
+ required this.hintText,
+ required this.textInputAction,
+ required this.onChanged,
+ required this.onSubmitted,
+ });
+
+ @override
+ Widget build(BuildContext context) {
+ final colorScheme = getEnteColorScheme(context);
+ final textTheme = getEnteTextTheme(context);
+ final fillColor = colorScheme.isLightTheme
+ ? Colors.white
+ : colorScheme.backgroundElevated2;
+
+ return SizedBox(
+ height: 52,
+ child: TextFormField(
+ controller: controller,
+ focusNode: focusNode,
+ style: textTheme.small.copyWith(height: 20 / 14),
+ textAlignVertical: TextAlignVertical.center,
+ decoration: InputDecoration(
+ fillColor: fillColor,
+ filled: true,
+ hintText: hintText,
+ hintStyle: textTheme.small.copyWith(
+ color: colorScheme.textFaint,
+ height: 20 / 14,
+ ),
+ contentPadding: const EdgeInsets.symmetric(horizontal: 16),
+ border: OutlineInputBorder(
+ borderSide: BorderSide.none,
+ borderRadius: BorderRadius.circular(16),
+ ),
+ enabledBorder: OutlineInputBorder(
+ borderSide: BorderSide.none,
+ borderRadius: BorderRadius.circular(16),
+ ),
+ focusedBorder: OutlineInputBorder(
+ borderRadius: BorderRadius.circular(16),
+ borderSide: BorderSide(color: colorScheme.primary700, width: 2),
+ ),
+ ),
+ textCapitalization: TextCapitalization.words,
+ textInputAction: textInputAction,
+ onChanged: onChanged,
+ onFieldSubmitted: onSubmitted,
+ ),
+ );
+ }
+}
+
+class _CreateLegacyKitSheetState extends State<CreateLegacyKitSheet> {
+ final List<TextEditingController> _controllers = List.generate(
+ 3,
+ (_) => TextEditingController(),
+ );
+ int _selectedDays = 7;
+
+ @override
+ void dispose() {
+ for (final controller in _controllers) {
+ controller.dispose();
+ }
+ super.dispose();
+ }
+
+ @override
+ Widget build(BuildContext context) {
+ final colorScheme = getEnteColorScheme(context);
+ final textTheme = getEnteTextTheme(context);
+ final canCreate = _isValid;
+
+ return SingleChildScrollView(
+ child: Column(
+ mainAxisSize: MainAxisSize.min,
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ Text(
+ context.strings.legacyKitCreateDescription,
+ style: textTheme.smallMuted,
+ ),
+ const SizedBox(height: 20),
+ ...List.generate(3, (index) {
+ return Padding(
+ padding: EdgeInsets.only(bottom: index == 2 ? 0 : 12),
+ child: TextFormField(
+ controller: _controllers[index],
+ decoration: InputDecoration(
+ fillColor: colorScheme.fillFaint,
+ filled: true,
+ hintText: context.strings.legacyKitPartNameHint(index + 1),
+ hintStyle: TextStyle(color: colorScheme.textMuted),
+ contentPadding: const EdgeInsets.symmetric(
+ horizontal: 16,
+ vertical: 14,
+ ),
+ border: OutlineInputBorder(
+ borderSide: BorderSide.none,
+ borderRadius: BorderRadius.circular(8),
+ ),
+ enabledBorder: OutlineInputBorder(
+ borderSide: BorderSide.none,
+ borderRadius: BorderRadius.circular(8),
+ ),
+ focusedBorder: OutlineInputBorder(
+ borderRadius: BorderRadius.circular(8),
+ borderSide: BorderSide(color: colorScheme.strokeMuted),
+ ),
+ ),
+ textCapitalization: TextCapitalization.words,
+ textInputAction:
+ index == 2 ? TextInputAction.done : TextInputAction.next,
+ onChanged: (_) => setState(() {}),
+ ),
+ );
+ }),
+ const SizedBox(height: 20),
+ Text(
+ context.strings.recoveryWaitTime,
+ style: textTheme.bodyMuted,
+ ),
+ const SizedBox(height: 12),
+ RecoveryDateSelector(
+ selectedDays: _selectedDays,
+ dayOptions: const [0, 1, 7, 15, 30],
+ onDaysChanged: (days) {
+ setState(() {
+ _selectedDays = days;
+ });
+ },
+ ),
+ const SizedBox(height: 20),
+ Text(
+ context.strings.legacyKitStorageGuidance,
+ style: textTheme.smallMuted,
+ ),
+ const SizedBox(height: 20),
+ GradientButton(
+ text: context.strings.createLegacyKit,
+ onTap: canCreate ? _submit : null,
+ ),
+ ],
+ ),
+ );
+ }
+
+ bool get _isValid {
+ final names = _partNames;
+ return names.length == 3 &&
+ names.every((name) => name.isNotEmpty) &&
+ names.toSet().length == 3;
+ }
+
+ List<String> get _partNames {
+ return _controllers
+ .map((controller) => controller.text.trim())
+ .where((name) => name.isNotEmpty)
+ .toList(growable: false);
+ }
+
+ void _submit() {
+ Navigator.of(context).pop(
+ LegacyKitCreateInput(
+ partNames: _partNames,
+ noticePeriodInHours: _selectedDays * 24,
+ ),
+ );
+ }
+}
diff --git a/mobile/packages/legacy/lib/pages/emergency_page.dart b/mobile/packages/legacy/lib/pages/emergency_page.dart
index 6a355b1b86..631663ac3b 100644
--- a/mobile/packages/legacy/lib/pages/emergency_page.dart
+++ b/mobile/packages/legacy/lib/pages/emergency_page.dart
@@ -6,9 +6,15 @@ import "package:ente_legacy/components/gradient_button.dart";
import "package:ente_legacy/components/invite_reject_bottom_sheet.dart";
import "package:ente_legacy/components/trusted_contact_bottom_sheet.dart";
import "package:ente_legacy/models/emergency_models.dart";
+import "package:ente_legacy/models/legacy_kit_models.dart";
+import "package:ente_legacy/pages/create_legacy_kit_sheet.dart";
+import "package:ente_legacy/pages/legacy_kit_advert_page.dart";
+import "package:ente_legacy/pages/legacy_kit_creating_page.dart";
+import "package:ente_legacy/pages/legacy_kit_page.dart";
import "package:ente_legacy/pages/other_contact_page.dart";
import "package:ente_legacy/pages/select_contact_page.dart";
import "package:ente_legacy/services/emergency_service.dart";
+import "package:ente_legacy/services/legacy_kit_service.dart";
import "package:ente_sharing/extensions/user_extension.dart";
import "package:ente_sharing/user_avator_widget.dart";
import "package:ente_strings/ente_strings.dart";
@@ -18,16 +24,28 @@ import "package:ente_ui/components/divider_widget.dart";
import "package:ente_ui/components/loading_widget.dart";
import "package:ente_ui/components/menu_item_widget_v2.dart";
import "package:ente_ui/components/menu_section_title.dart";
-import "package:ente_ui/components/title_bar_title_widget.dart";
+import "package:ente_ui/theme/colors.dart";
import "package:ente_ui/theme/ente_theme.dart";
+import "package:ente_ui/theme/text_style.dart";
import "package:ente_ui/utils/toast_util.dart";
import "package:flutter/foundation.dart";
-import 'package:flutter/material.dart';
+import "package:flutter/material.dart";
+import "package:intl/intl.dart";
+import "package:logging/logging.dart";
+
+final _logger = Logger("EmergencyPage");
+const _legacyEmptyStateDescription =
+ "Keep your Ente account accessible to people you trust, even if something happens to you.";
class EmergencyPage extends StatefulWidget {
final BaseConfiguration config;
+ final LegacyKitAuthenticator? legacyKitAuthenticator;
- const EmergencyPage({required this.config, super.key});
+ const EmergencyPage({
+ required this.config,
+ this.legacyKitAuthenticator,
+ super.key,
+ });
@override
State<EmergencyPage> createState() => _EmergencyPageState();
@@ -36,7 +54,7 @@ class EmergencyPage extends StatefulWidget {
class _EmergencyPageState extends State<EmergencyPage> {
late int currentUserID;
EmergencyInfo? info;
- bool hasTrustedContact = false;
+ List<LegacyKit> legacyKits = [];
@override
void initState() {
@@ -50,10 +68,11 @@ class _EmergencyPageState extends State<EmergencyPage> {
Future<void> _fetchData() async {
try {
final result = await EmergencyContactService.instance.getInfo();
+ final kits = await _fetchLegacyKits();
if (mounted) {
setState(() {
info = result;
- hasTrustedContact = info?.contacts.isNotEmpty ?? false;
+ legacyKits = kits;
});
}
} catch (e) {
@@ -61,6 +80,18 @@ class _EmergencyPageState extends State<EmergencyPage> {
}
}
+ Future<List<LegacyKit>> _fetchLegacyKits() async {
+ if (!LegacyKitService.instance.isInitialized) {
+ return <LegacyKit>[];
+ }
+ try {
+ return await LegacyKitService.instance.getKits();
+ } catch (error, stackTrace) {
+ _logger.warning("Failed to fetch legacy kits", error, stackTrace);
+ return legacyKits;
+ }
+ }
+
@override
Widget build(BuildContext context) {
return ValueListenableBuilder<int>(
@@ -71,9 +102,20 @@ class _EmergencyPageState extends State<EmergencyPage> {
final List<EmergencyContact> othersTrustedContacts =
info?.othersEmergencyContact ?? [];
final List<EmergencyContact> trustedContacts = info?.contacts ?? [];
+ final hasSecondaryLegacyContent =
+ legacyKits.isNotEmpty || othersTrustedContacts.isNotEmpty;
+ final showFullEmptyState = info != null &&
+ info!.recoverSessions.isEmpty &&
+ trustedContacts.isEmpty &&
+ othersTrustedContacts.isEmpty &&
+ legacyKits.isEmpty;
return Scaffold(
+ backgroundColor: colorScheme.backgroundBase,
appBar: AppBar(
+ backgroundColor: colorScheme.backgroundBase,
+ surfaceTintColor: Colors.transparent,
+ elevation: 0,
toolbarHeight: 48,
leadingWidth: 48,
leading: GestureDetector(
@@ -88,18 +130,29 @@ class _EmergencyPageState extends State<EmergencyPage> {
SliverToBoxAdapter(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 16),
- child: TitleBarTitleWidget(title: context.strings.legacy),
+ child: _buildPageTitle(colorScheme, textTheme),
),
),
- SliverToBoxAdapter(
- child: Padding(
- padding: const EdgeInsets.symmetric(horizontal: 16),
- child: Text(
- context.strings.legacyPageDesc,
- style: textTheme.smallMuted,
+ if (!showFullEmptyState)
+ SliverToBoxAdapter(
+ child: Padding(
+ padding: const EdgeInsets.symmetric(horizontal: 16),
+ child: Text(
+ context.strings.legacyPageDesc,
+ style: textTheme.smallMuted,
+ ),
+ ),
+ ),
+ if (showFullEmptyState)
+ SliverFillRemaining(
+ hasScrollBody: false,
+ child: _FullLegacyEmptyState(
+ onAddContact: _addTrustedContact,
+ onCreateLegacyKit: LegacyKitService.instance.isInitialized
+ ? _createLegacyKit
+ : null,
),
),
- ),
if (info == null)
const SliverFillRemaining(
hasScrollBody: false,
@@ -169,54 +222,62 @@ class _EmergencyPageState extends State<EmergencyPage> {
),
),
),
- if (info != null)
+ if (info != null && !showFullEmptyState)
SliverPadding(
padding: const EdgeInsets.only(
top: 16,
left: 16,
right: 16,
- bottom: 8,
),
sliver: SliverList(
delegate: SliverChildBuilderDelegate(
(context, index) {
- if (index == 0 && trustedContacts.isNotEmpty) {
- return MenuSectionTitle(
+ if (index == 0 &&
+ (trustedContacts.isNotEmpty ||
+ hasSecondaryLegacyContent)) {
+ return _buildSectionTitle(
title: context.strings.trustedContacts,
+ colorScheme: colorScheme,
+ textTheme: textTheme,
+ bottom: 12,
);
} else if (index > 0 &&
index <= trustedContacts.length) {
final listIndex = index - 1;
final contact = trustedContacts[listIndex];
- final isLastItem =
- listIndex == trustedContacts.length - 1;
+ final rowColor = _legacyRowColor(colorScheme);
return Column(
children: [
MenuItemWidgetV2(
captionedTextWidget: CaptionedTextWidgetV2(
title: contact
.emergencyContact.resolvedDisplayName,
- textStyle: textTheme.small.copyWith(
- color: colorScheme.textMuted,
+ subTitle: _contactStatusText(contact),
+ subTitleInNewLine: true,
+ textStyle: _legacyRowTitleStyle(
+ colorScheme,
+ textTheme,
+ ),
+ subTitleTextStyle: _legacyRowSubTitleStyle(
+ colorScheme,
+ textTheme,
),
- trailingTitleWidget: contact.isPendingInvite()
- ? Image.asset(
- "assets/warning-yellow.png",
- width: 20,
- height: 20,
- )
- : null,
),
- leadingIconSize: 24.0,
+ leadingIconSize: 32.0,
surfaceExecutionStates: false,
alwaysShowSuccessState: false,
- leadingIconWidget: UserAvatarWidget(
- contact.emergencyContact,
- type: AvatarType.mini,
- currentUserID: currentUserID,
- config: widget.config,
+ leadingIconWidget: _ContactAvatarWithStatus(
+ isPending: contact.isPendingInvite(),
+ borderColor: rowColor,
+ child: UserAvatarWidget(
+ contact.emergencyContact,
+ type: AvatarType.small,
+ currentUserID: currentUserID,
+ config: widget.config,
+ ),
),
- menuItemColor: colorScheme.fillFaint,
+ menuItemColor: rowColor,
+ singleBorderRadius: 20,
trailingIcon: Icons.chevron_right,
trailingIconIsMuted: true,
onTap: () async {
@@ -225,68 +286,58 @@ class _EmergencyPageState extends State<EmergencyPage> {
contact,
);
},
- isTopBorderRadiusRemoved: listIndex > 0,
- isBottomBorderRadiusRemoved: !isLastItem,
- isFirstItem: listIndex == 0,
- isLastItem: isLastItem,
),
- if (!isLastItem)
- DividerWidget(
- dividerType: DividerType.menu,
- bgColor: colorScheme.fillFaint,
- ),
+ if (listIndex < trustedContacts.length - 1)
+ const SizedBox(height: 8),
],
);
} else if (index == (1 + trustedContacts.length)) {
if (trustedContacts.isEmpty) {
+ if (hasSecondaryLegacyContent) {
+ return _TrustedContactsEmptyCard(
+ onAddContact: _addTrustedContact,
+ );
+ }
return Column(
children: [
- SizedBox(
- height: 200,
- width: 200,
- child: Image.asset(
- "assets/legacy.png",
- width: 200,
+ if (legacyKits.isEmpty) ...[
+ SizedBox(
height: 200,
+ width: 200,
+ child: Image.asset(
+ "assets/legacy.png",
+ width: 200,
+ height: 200,
+ ),
),
- ),
- Text(
- context.strings.legacyPageDesc2,
- style: textTheme.smallMuted,
- ),
- const SizedBox(height: 16),
- GradientButton(
- text: context.strings.addTrustedContact,
- onTap: () async {
- final result = await showAddContactSheet(
- context,
- emergencyInfo: info!,
- config: widget.config,
- );
- if (result == true) {
- unawaited(_fetchData());
- }
- },
- ),
+ Text(
+ context.strings.legacyPageDesc2,
+ style: textTheme.smallMuted,
+ ),
+ const SizedBox(height: 16),
+ ],
+ _buildAddTrustedContactButton(),
+ if (LegacyKitService.instance.isInitialized &&
+ legacyKits.isEmpty) ...[
+ const SizedBox(height: 12),
+ GradientButton(
+ text: context.strings.createLegacyKit,
+ height: 52,
+ textStyle: _legacyButtonTextStyle(
+ textTheme,
+ ),
+ onTap: () async {
+ await _createLegacyKit();
+ },
+ ),
+ ],
],
);
}
return Column(
children: [
- const SizedBox(height: 20),
- GradientButton(
- text: context.strings.addTrustedContact,
- onTap: () async {
- final result = await showAddContactSheet(
- context,
- emergencyInfo: info!,
- config: widget.config,
- );
- if (result == true) {
- unawaited(_fetchData());
- }
- },
- ),
+ const SizedBox(height: 12),
+ _buildAddTrustedContactButton(),
],
);
}
@@ -296,7 +347,9 @@ class _EmergencyPageState extends State<EmergencyPage> {
),
),
),
- if (info != null && info!.othersEmergencyContact.isNotEmpty)
+ if (info != null &&
+ !showFullEmptyState &&
+ info!.othersEmergencyContact.isNotEmpty)
SliverPadding(
padding: const EdgeInsets.only(top: 0, left: 16, right: 16),
sliver: SliverList(
@@ -305,14 +358,11 @@ class _EmergencyPageState extends State<EmergencyPage> {
if (index == 0 && (othersTrustedContacts.isNotEmpty)) {
return Column(
children: [
- const Padding(
- padding: EdgeInsets.symmetric(vertical: 8),
- child: DividerWidget(
- dividerType: DividerType.solid,
- ),
- ),
- MenuSectionTitle(
+ const SizedBox(height: 20),
+ _buildSectionTitle(
title: context.strings.legacyAccounts,
+ colorScheme: colorScheme,
+ textTheme: textTheme,
),
],
);
@@ -320,36 +370,38 @@ class _EmergencyPageState extends State<EmergencyPage> {
index <= othersTrustedContacts.length) {
final listIndex = index - 1;
final currentUser = othersTrustedContacts[listIndex];
- final isLastItem =
- index == othersTrustedContacts.length;
+ final rowColor = _legacyRowColor(colorScheme);
return Column(
children: [
MenuItemWidgetV2(
captionedTextWidget: CaptionedTextWidgetV2(
title: currentUser.user.resolvedDisplayName,
- textStyle: textTheme.small.copyWith(
- color: colorScheme.textMuted,
- fontWeight: FontWeight.w500,
+ subTitle: _contactStatusText(currentUser),
+ subTitleInNewLine: true,
+ textStyle: _legacyRowTitleStyle(
+ colorScheme,
+ textTheme,
+ ),
+ subTitleTextStyle: _legacyRowSubTitleStyle(
+ colorScheme,
+ textTheme,
),
- trailingTitleWidget:
- currentUser.isPendingInvite()
- ? Image.asset(
- "assets/warning-yellow.png",
- width: 20,
- height: 20,
- )
- : null,
),
- leadingIconSize: 24.0,
+ leadingIconSize: 32.0,
surfaceExecutionStates: false,
alwaysShowSuccessState: false,
- leadingIconWidget: UserAvatarWidget(
- currentUser.user,
- type: AvatarType.mini,
- currentUserID: currentUserID,
- config: widget.config,
+ leadingIconWidget: _ContactAvatarWithStatus(
+ isPending: currentUser.isPendingInvite(),
+ borderColor: rowColor,
+ child: UserAvatarWidget(
+ currentUser.user,
+ type: AvatarType.small,
+ currentUserID: currentUserID,
+ config: widget.config,
+ ),
),
- menuItemColor: colorScheme.fillFaint,
+ menuItemColor: rowColor,
+ singleBorderRadius: 20,
trailingIcon: Icons.chevron_right,
trailingIconIsMuted: true,
onTap: () async {
@@ -375,17 +427,9 @@ class _EmergencyPageState extends State<EmergencyPage> {
}
}
},
- isTopBorderRadiusRemoved: listIndex > 0,
- isBottomBorderRadiusRemoved: !isLastItem,
- isFirstItem: listIndex == 0,
- isLastItem: isLastItem,
),
- isLastItem
- ? const SizedBox.shrink()
- : DividerWidget(
- dividerType: DividerType.menu,
- bgColor: colorScheme.fillFaint,
- ),
+ if (listIndex < othersTrustedContacts.length - 1)
+ const SizedBox(height: 8),
],
);
}
@@ -395,6 +439,13 @@ class _EmergencyPageState extends State<EmergencyPage> {
),
),
),
+ if (info != null &&
+ !showFullEmptyState &&
+ LegacyKitService.instance.isInitialized &&
+ (legacyKits.isNotEmpty ||
+ trustedContacts.isNotEmpty ||
+ othersTrustedContacts.isNotEmpty))
+ _buildLegacyKitsSliver(colorScheme, textTheme),
],
),
);
@@ -402,6 +453,285 @@ class _EmergencyPageState extends State<EmergencyPage> {
);
}
+ Widget _buildPageTitle(
+ EnteColorScheme colorScheme,
+ EnteTextTheme textTheme,
+ ) {
+ return SizedBox(
+ height: 40,
+ child: Align(
+ alignment: Alignment.centerLeft,
+ child: Text(
+ context.strings.legacy,
+ style: textTheme.h3Bold.copyWith(
+ color: colorScheme.textBase,
+ fontSize: 20.0,
+ height: 28 / 20,
+ ),
+ overflow: TextOverflow.ellipsis,
+ maxLines: 1,
+ ),
+ ),
+ );
+ }
+
+ Widget _buildLegacyKitsSliver(
+ EnteColorScheme colorScheme,
+ EnteTextTheme textTheme,
+ ) {
+ return SliverToBoxAdapter(
+ child: Padding(
+ padding: const EdgeInsets.only(left: 16, right: 16, bottom: 8),
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ const SizedBox(height: 20),
+ _buildSectionTitle(
+ title: context.strings.legacyKits,
+ colorScheme: colorScheme,
+ textTheme: textTheme,
+ ),
+ if (legacyKits.isEmpty)
+ _LegacyKitEmptyCard(onCreate: _createLegacyKit)
+ else
+ ..._buildLegacyKitRows(colorScheme, textTheme),
+ const SizedBox(height: 12),
+ if (legacyKits.isNotEmpty && legacyKits.length < 5)
+ GradientButton(
+ text: context.strings.createAnotherKit,
+ height: 52,
+ textStyle: _legacyButtonTextStyle(textTheme),
+ backgroundColor: _legacySecondaryButtonColor(colorScheme),
+ textColor: colorScheme.primary700,
+ onTap: () async {
+ await _createLegacyKit();
+ },
+ ),
+ ],
+ ),
+ ),
+ );
+ }
+
+ List<Widget> _buildLegacyKitRows(
+ EnteColorScheme colorScheme,
+ EnteTextTheme textTheme,
+ ) {
+ final cardColor = _legacyRowColor(colorScheme);
+ return [
+ for (var index = 0; index < legacyKits.length; index++) ...[
+ MenuItemWidgetV2(
+ captionedTextWidget: CaptionedTextWidgetV2(
+ title: legacyKits[index].displayName,
+ subTitle: legacyKits[index].hasActiveRecoverySession
+ ? context.strings.legacyKitRecoveryInProgress
+ : context.strings.createdOn(
+ _formatKitDate(legacyKits[index].createdAt),
+ ),
+ subTitleInNewLine: true,
+ textStyle: _legacyRowTitleStyle(
+ colorScheme,
+ textTheme,
+ isWarning: legacyKits[index].hasActiveRecoverySession,
+ ),
+ subTitleTextStyle: _legacyRowSubTitleStyle(
+ colorScheme,
+ textTheme,
+ isWarning: legacyKits[index].hasActiveRecoverySession,
+ ),
+ ),
+ leadingIconSize: 32,
+ leadingIconWidget:
+ _LegacyKitLeadingIcon(color: colorScheme.primary700),
+ menuItemColor: cardColor,
+ singleBorderRadius: 20,
+ trailingIcon: Icons.chevron_right,
+ trailingIconIsMuted: true,
+ surfaceExecutionStates: false,
+ alwaysShowSuccessState: false,
+ onTap: () async {
+ await Navigator.of(context).push(
+ MaterialPageRoute(
+ builder: (context) {
+ return LegacyKitPage(
+ kit: legacyKits[index],
+ accountEmail: widget.config.getEmail() ?? "",
+ authenticator: widget.legacyKitAuthenticator,
+ onChanged: () => unawaited(_fetchData()),
+ );
+ },
+ ),
+ );
+ if (mounted) {
+ unawaited(_fetchData());
+ }
+ },
+ isFirstItem: index == 0,
+ isLastItem: index == legacyKits.length - 1,
+ ),
+ if (index < legacyKits.length - 1) const SizedBox(height: 8),
+ ],
+ ];
+ }
+
+ Widget _buildAddTrustedContactButton() {
+ final textTheme = getEnteTextTheme(context);
+ return GradientButton(
+ text: context.strings.addTrustedContact,
+ height: 52,
+ textStyle: _legacyButtonTextStyle(textTheme),
+ onTap: () async {
+ await _addTrustedContact();
+ },
+ );
+ }
+
+ Future<void> _addTrustedContact() async {
+ final result = await showAddContactSheet(
+ context,
+ emergencyInfo: info!,
+ config: widget.config,
+ );
+ if (result == true) {
+ unawaited(_fetchData());
+ }
+ }
+
+ Widget _buildSectionTitle({
+ required String title,
+ required EnteColorScheme colorScheme,
+ required EnteTextTheme textTheme,
+ double bottom = 8,
+ }) {
+ return MenuSectionTitle(
+ title: title,
+ padding: EdgeInsets.only(bottom: bottom),
+ textStyle: textTheme.bodyBold.copyWith(color: colorScheme.textBase),
+ );
+ }
+
+ Color _legacyRowColor(EnteColorScheme colorScheme) {
+ return colorScheme.backdropBase;
+ }
+
+ Color _legacySecondaryButtonColor(EnteColorScheme colorScheme) {
+ return colorScheme.isLightTheme
+ ? colorScheme.primary300
+ : colorScheme.backdropBase;
+ }
+
+ TextStyle _legacyRowTitleStyle(
+ EnteColorScheme colorScheme,
+ EnteTextTheme textTheme, {
+ bool isWarning = false,
+ }) {
+ return textTheme.small.copyWith(
+ color: isWarning ? colorScheme.warning500 : colorScheme.textBase,
+ fontWeight: isWarning ? FontWeight.w600 : FontWeight.w500,
+ height: 20 / 14,
+ );
+ }
+
+ TextStyle _legacyRowSubTitleStyle(
+ EnteColorScheme colorScheme,
+ EnteTextTheme textTheme, {
+ bool isWarning = false,
+ }) {
+ return textTheme.mini.copyWith(
+ color: isWarning ? colorScheme.warning500 : colorScheme.textMuted,
+ height: 16 / 12,
+ );
+ }
+
+ TextStyle _legacyButtonTextStyle(EnteTextTheme textTheme) {
+ return textTheme.small.copyWith(height: 20 / 14);
+ }
+
+ Future<void> _createLegacyKit() async {
+ if (legacyKits.length >= 5) {
+ await showAlertBottomSheet(
+ context,
+ title: context.strings.legacyKits,
+ message: context.strings.legacyKitMaxReached,
+ assetPath: "assets/warning-blue.png",
+ );
+ return;
+ }
+ if (legacyKits.isEmpty) {
+ final shouldStart = await showLegacyKitAdvertPage(context);
+ if (!shouldStart || !mounted) {
+ return;
+ }
+ }
+ final input = await showCreateLegacyKitSheet(context);
+ if (input == null) {
+ return;
+ }
+ if (!await _authenticate(context.strings.authToManageLegacyKit)) {
+ return;
+ }
+
+ final navigator = Navigator.of(context);
+ unawaited(
+ navigator.push<void>(
+ MaterialPageRoute(
+ builder: (context) => const LegacyKitCreatingPage(),
+ ),
+ ),
+ );
+
+ try {
+ final result = await LegacyKitService.instance.createKit(
+ partNames: input.partNames,
+ noticePeriodInHours: input.noticePeriodInHours,
+ );
+ if (!mounted) {
+ return;
+ }
+ setState(() {
+ legacyKits = [result.kit, ...legacyKits];
+ });
+ unawaited(_fetchData());
+ await navigator.pushReplacement(
+ MaterialPageRoute(
+ builder: (context) {
+ return LegacyKitPage(
+ kit: result.kit,
+ accountEmail: widget.config.getEmail() ?? "",
+ authenticator: widget.legacyKitAuthenticator,
+ onChanged: () => unawaited(_fetchData()),
+ );
+ },
+ ),
+ );
+ if (mounted) {
+ unawaited(_fetchData());
+ }
+ } catch (_) {
+ if (mounted) {
+ navigator.pop();
+ showShortToast(context, context.strings.somethingWentWrong);
+ }
+ }
+ }
+
+ Future<bool> _authenticate(String reason) async {
+ final authenticator = widget.legacyKitAuthenticator;
+ if (authenticator == null) {
+ return true;
+ }
+ return authenticator(context, reason);
+ }
+
+ String _formatKitDate(int micros) {
+ final dateTime = DateTime.fromMicrosecondsSinceEpoch(micros).toLocal();
+ return DateFormat.yMMMd().format(dateTime);
+ }
+
+ String _contactStatusText(EmergencyContact contact) {
+ return contact.isPendingInvite() ? "Pending" : "Accepted";
+ }
+
Future<void> showRevokeOrRemoveDialog(
BuildContext context,
EmergencyContact contact,
@@ -582,6 +912,152 @@ class _EmergencyPageState extends State<EmergencyPage> {
}
}
+class _ContactAvatarWithStatus extends StatelessWidget {
+ final Widget child;
+ final bool isPending;
+ final Color borderColor;
+
+ const _ContactAvatarWithStatus({
+ required this.child,
+ required this.isPending,
+ required this.borderColor,
+ });
+
+ @override
+ Widget build(BuildContext context) {
+ final colorScheme = getEnteColorScheme(context);
+
+ return Stack(
+ clipBehavior: Clip.none,
+ children: [
+ child,
+ if (isPending)
+ Positioned(
+ right: -1,
+ bottom: -1,
+ child: Container(
+ width: 11,
+ height: 11,
+ decoration: BoxDecoration(
+ color: colorScheme.caution500,
+ shape: BoxShape.circle,
+ border: Border.all(
+ color: borderColor,
+ width: 1.5,
+ ),
+ ),
+ child: const Center(
+ child: Text(
+ "!",
+ style: TextStyle(
+ color: Colors.white,
+ fontSize: 7.0,
+ height: 1,
+ fontWeight: FontWeight.w700,
+ ),
+ ),
+ ),
+ ),
+ ),
+ ],
+ );
+ }
+}
+
+class _FullLegacyEmptyState extends StatelessWidget {
+ final Future<void> Function() onAddContact;
+ final Future<void> Function()? onCreateLegacyKit;
+
+ const _FullLegacyEmptyState({
+ required this.onAddContact,
+ required this.onCreateLegacyKit,
+ });
+
+ @override
+ Widget build(BuildContext context) {
+ final colorScheme = getEnteColorScheme(context);
+ final textTheme = getEnteTextTheme(context);
+ final buttonTextStyle = textTheme.small.copyWith(height: 20 / 14);
+
+ return Column(
+ children: [
+ Expanded(
+ child: Padding(
+ padding: const EdgeInsets.symmetric(horizontal: 48),
+ child: Column(
+ mainAxisAlignment: MainAxisAlignment.center,
+ children: [
+ SizedBox(
+ width: 200,
+ height: 150,
+ child: Image.asset(
+ "assets/legacy.png",
+ fit: BoxFit.contain,
+ ),
+ ),
+ const SizedBox(height: 24),
+ Text(
+ _legacyEmptyStateDescription,
+ textAlign: TextAlign.center,
+ style: textTheme.small.copyWith(
+ color: colorScheme.textMuted,
+ height: 20 / 14,
+ ),
+ ),
+ ],
+ ),
+ ),
+ ),
+ SafeArea(
+ top: false,
+ minimum: const EdgeInsets.fromLTRB(16, 0, 16, 40),
+ child: Column(
+ mainAxisSize: MainAxisSize.min,
+ children: [
+ GradientButton(
+ text: context.strings.addTrustedContact,
+ height: 52,
+ textStyle: buttonTextStyle,
+ onTap: () async {
+ await onAddContact();
+ },
+ ),
+ if (onCreateLegacyKit != null) ...[
+ const SizedBox(height: 12),
+ GradientButton(
+ text: context.strings.createLegacyKit,
+ height: 52,
+ textStyle: buttonTextStyle,
+ onTap: () async {
+ await onCreateLegacyKit!();
+ },
+ ),
+ ],
+ ],
+ ),
+ ),
+ ],
+ );
+ }
+}
+
+class _LegacyKitLeadingIcon extends StatelessWidget {
+ final Color color;
+
+ const _LegacyKitLeadingIcon({required this.color});
+
+ @override
+ Widget build(BuildContext context) {
+ return Center(
+ child: Icon(
+ Icons.insert_drive_file_outlined,
+ size: 18,
+ color: color,
+ ),
+ );
+ }
+}
+
class _WarningBanner extends StatelessWidget {
final String text;
@@ -595,7 +1071,7 @@ class _WarningBanner extends StatelessWidget {
return Container(
padding: const EdgeInsets.all(18),
decoration: BoxDecoration(
- color: colorScheme.warning400.withOpacity(0.13),
+ color: colorScheme.warning400.withValues(alpha: 0.13),
borderRadius: BorderRadius.circular(20),
),
child: Row(
@@ -613,3 +1089,112 @@ class _WarningBanner extends StatelessWidget {
);
}
}
+
+class _TrustedContactsEmptyCard extends StatelessWidget {
+ final Future<void> Function() onAddContact;
+
+ const _TrustedContactsEmptyCard({required this.onAddContact});
+
+ @override
+ Widget build(BuildContext context) {
+ final colorScheme = getEnteColorScheme(context);
+ final textTheme = getEnteTextTheme(context);
+ final cardColor =
+ colorScheme.isLightTheme ? Colors.white : colorScheme.backdropBase;
+
+ return Container(
+ width: double.infinity,
+ padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 32),
+ decoration: BoxDecoration(
+ color: cardColor,
+ borderRadius: BorderRadius.circular(20),
+ ),
+ child: Column(
+ mainAxisSize: MainAxisSize.min,
+ crossAxisAlignment: CrossAxisAlignment.center,
+ children: [
+ Image.asset(
+ colorScheme.isLightTheme
+ ? "assets/trusted_contact_empty.png"
+ : "assets/trusted_contact_empty_dark.png",
+ width: 45,
+ height: 45,
+ fit: BoxFit.contain,
+ ),
+ const SizedBox(height: 12),
+ Text(
+ "Nominate another Ente user as a trusted contact to recover your account",
+ textAlign: TextAlign.center,
+ style: textTheme.small.copyWith(
+ color: colorScheme.textMuted,
+ height: 20 / 14,
+ ),
+ ),
+ const SizedBox(height: 12),
+ GradientButton(
+ text: context.strings.addTrustedContact,
+ height: 52,
+ textStyle: textTheme.small.copyWith(height: 20 / 14),
+ onTap: () async {
+ await onAddContact();
+ },
+ ),
+ ],
+ ),
+ );
+ }
+}
+
+class _LegacyKitEmptyCard extends StatelessWidget {
+ final Future<void> Function() onCreate;
+
+ const _LegacyKitEmptyCard({required this.onCreate});
+
+ @override
+ Widget build(BuildContext context) {
+ final colorScheme = getEnteColorScheme(context);
+ final textTheme = getEnteTextTheme(context);
+ final cardColor = colorScheme.isLightTheme
+ ? Colors.white
+ : colorScheme.backgroundElevated2;
+
+ return Container(
+ width: double.infinity,
+ padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 32),
+ decoration: BoxDecoration(
+ color: cardColor,
+ borderRadius: BorderRadius.circular(12),
+ ),
+ child: Column(
+ mainAxisSize: MainAxisSize.min,
+ crossAxisAlignment: CrossAxisAlignment.center,
+ children: [
+ Image.asset(
+ "assets/legacy_kit_empty.png",
+ width: 43,
+ height: 42,
+ fit: BoxFit.contain,
+ ),
+ const SizedBox(height: 12),
+ Text(
+ "Split your account recovery among people you really trust",
+ textAlign: TextAlign.center,
+ style: textTheme.small.copyWith(
+ color: colorScheme.textMuted,
+ height: 20 / 14,
+ ),
+ ),
+ const SizedBox(height: 12),
+ GradientButton(
+ text: context.strings.createLegacyKit,
+ height: 52,
+ textStyle: textTheme.small.copyWith(height: 20 / 14),
+ onTap: () async {
+ await onCreate();
+ },
+ ),
+ ],
+ ),
+ );
+ }
+}
diff --git a/mobile/packages/legacy/lib/pages/legacy_kit_advert_page.dart b/mobile/packages/legacy/lib/pages/legacy_kit_advert_page.dart
new file mode 100644
index 0000000000..0d65cc32e7
--- /dev/null
+++ b/mobile/packages/legacy/lib/pages/legacy_kit_advert_page.dart
@@ -0,0 +1,213 @@
+import "package:ente_legacy/components/gradient_button.dart";
+import "package:ente_ui/theme/colors.dart";
+import "package:ente_ui/theme/ente_theme.dart";
+import "package:ente_ui/theme/text_style.dart";
+import "package:flutter/material.dart";
+
+const _legacyKitAdvertDescription =
+ "Keep your Ente account accessible to people you trust, even if something happens to you.";
+
+const _legacyKitAdvertBullets = [
+ "Account recovery is split into 3 parts",
+ "Give each part to someone you trust",
+ "Any 2 parts can recover your account",
+];
+
+Future<bool> showLegacyKitAdvertPage(BuildContext context) async {
+ return await Navigator.of(context).push<bool>(
+ MaterialPageRoute(
+ builder: (context) => const LegacyKitAdvertPage(),
+ ),
+ ) ??
+ false;
+}
+
+class LegacyKitAdvertPage extends StatelessWidget {
+ const LegacyKitAdvertPage({super.key});
+
+ @override
+ Widget build(BuildContext context) {
+ final colorScheme = getEnteColorScheme(context);
+ final textTheme = getEnteTextTheme(context);
+
+ return Scaffold(
+ backgroundColor: colorScheme.backgroundBase,
+ appBar: AppBar(
+ backgroundColor: colorScheme.backgroundBase,
+ surfaceTintColor: Colors.transparent,
+ elevation: 0,
+ toolbarHeight: 48,
+ leadingWidth: 48,
+ leading: GestureDetector(
+ onTap: () => Navigator.pop(context, false),
+ child: const Icon(Icons.arrow_back_outlined),
+ ),
+ ),
+ body: LayoutBuilder(
+ builder: (context, constraints) {
+ return SingleChildScrollView(
+ child: ConstrainedBox(
+ constraints: BoxConstraints(minHeight: constraints.maxHeight),
+ child: Padding(
+ padding: const EdgeInsets.symmetric(horizontal: 32),
+ child: Column(
+ children: [
+ const SizedBox(height: 80),
+ _LegacyKitAdvertContent(
+ colorScheme: colorScheme,
+ textTheme: textTheme,
+ ),
+ const SizedBox(height: 112),
+ GradientButton(
+ text: "Get started",
+ height: 52,
+ textStyle: textTheme.small.copyWith(height: 20 / 14),
+ onTap: () => Navigator.pop(context, true),
+ ),
+ const SizedBox(height: 24),
+ ],
+ ),
+ ),
+ ),
+ );
+ },
+ ),
+ );
+ }
+}
+
+class _LegacyKitAdvertContent extends StatelessWidget {
+ final EnteColorScheme colorScheme;
+ final EnteTextTheme textTheme;
+
+ const _LegacyKitAdvertContent({
+ required this.colorScheme,
+ required this.textTheme,
+ });
+
+ @override
+ Widget build(BuildContext context) {
+ return Column(
+ children: [
+ _LegacyKitAdvertIllustration(colorScheme: colorScheme),
+ const SizedBox(height: 24),
+ Text(
+ "Create a legacy kit",
+ textAlign: TextAlign.center,
+ style: textTheme.h3Bold.copyWith(
+ color: colorScheme.textBase,
+ fontSize: 24.0,
+ height: 28 / 24,
+ ),
+ ),
+ const SizedBox(height: 8),
+ Text(
+ _legacyKitAdvertDescription,
+ textAlign: TextAlign.center,
+ style: textTheme.mini.copyWith(
+ color: colorScheme.textMuted,
+ height: 16 / 12,
+ ),
+ ),
+ const SizedBox(height: 32),
+ ConstrainedBox(
+ constraints: const BoxConstraints(maxWidth: 279),
+ child: Column(
+ children: [
+ for (var index = 0;
+ index < _legacyKitAdvertBullets.length;
+ index++) ...[
+ _LegacyKitAdvertBullet(
+ text: _legacyKitAdvertBullets[index],
+ colorScheme: colorScheme,
+ textTheme: textTheme,
+ ),
+ if (index < _legacyKitAdvertBullets.length - 1)
+ const SizedBox(height: 24),
+ ],
+ ],
+ ),
+ ),
+ ],
+ );
+ }
+}
+
+class _LegacyKitAdvertIllustration extends StatelessWidget {
+ final EnteColorScheme colorScheme;
+
+ const _LegacyKitAdvertIllustration({required this.colorScheme});
+
+ @override
+ Widget build(BuildContext context) {
+ return SizedBox(
+ width: 200,
+ height: 116,
+ child: Stack(
+ children: [
+ Positioned(
+ left: 34,
+ top: 14,
+ child: Container(
+ width: 132,
+ height: 97,
+ decoration: BoxDecoration(
+ color: colorScheme.primary700,
+ borderRadius: BorderRadius.circular(97),
+ ),
+ ),
+ ),
+ Positioned(
+ left: 37,
+ top: 0,
+ child: Image.asset(
+ "assets/legacy_kit_advert_foreground.png",
+ width: 120,
+ height: 115,
+ fit: BoxFit.contain,
+ ),
+ ),
+ ],
+ ),
+ );
+ }
+}
+
+class _LegacyKitAdvertBullet extends StatelessWidget {
+ final String text;
+ final EnteColorScheme colorScheme;
+ final EnteTextTheme textTheme;
+
+ const _LegacyKitAdvertBullet({
+ required this.text,
+ required this.colorScheme,
+ required this.textTheme,
+ });
+
+ @override
+ Widget build(BuildContext context) {
+ return Row(
+ crossAxisAlignment: CrossAxisAlignment.center,
+ children: [
+ Container(
+ width: 5,
+ height: 5,
+ decoration: BoxDecoration(
+ color: colorScheme.primary700,
+ shape: BoxShape.circle,
+ ),
+ ),
+ const SizedBox(width: 12),
+ Expanded(
+ child: Text(
+ text,
+ style: textTheme.small.copyWith(
+ color: colorScheme.textBase,
+ height: 20 / 14,
+ ),
+ ),
+ ),
+ ],
+ );
+ }
+}
diff --git a/mobile/packages/legacy/lib/pages/legacy_kit_creating_page.dart b/mobile/packages/legacy/lib/pages/legacy_kit_creating_page.dart
new file mode 100644
index 0000000000..7f5689a14e
--- /dev/null
+++ b/mobile/packages/legacy/lib/pages/legacy_kit_creating_page.dart
@@ -0,0 +1,68 @@
+import "package:ente_ui/theme/ente_theme.dart";
+import "package:flutter/material.dart";
+
+class LegacyKitCreatingPage extends StatelessWidget {
+ const LegacyKitCreatingPage({super.key});
+
+ @override
+ Widget build(BuildContext context) {
+ final colorScheme = getEnteColorScheme(context);
+ final textTheme = getEnteTextTheme(context);
+
+ return PopScope(
+ canPop: false,
+ child: Scaffold(
+ backgroundColor: colorScheme.backgroundBase,
+ appBar: AppBar(
+ backgroundColor: colorScheme.backgroundBase,
+ surfaceTintColor: Colors.transparent,
+ elevation: 0,
+ toolbarHeight: 48,
+ leadingWidth: 48,
+ leading: const Icon(Icons.arrow_back_outlined),
+ ),
+ body: Stack(
+ children: [
+ Padding(
+ padding: const EdgeInsets.symmetric(horizontal: 16),
+ child: Text(
+ "Creating your kit",
+ style: textTheme.largeBold.copyWith(
+ fontSize: 20.0,
+ height: 28 / 20,
+ ),
+ ),
+ ),
+ Center(
+ child: Column(
+ mainAxisSize: MainAxisSize.min,
+ children: [
+ SizedBox.square(
+ dimension: 48,
+ child: CircularProgressIndicator(
+ strokeWidth: 6,
+ strokeCap: StrokeCap.round,
+ color: colorScheme.primary700,
+ backgroundColor: colorScheme.isLightTheme
+ ? colorScheme.primary300
+ : colorScheme.fillFaint,
+ ),
+ ),
+ const SizedBox(height: 20),
+ Text(
+ "Setting up your legacy kit",
+ textAlign: TextAlign.center,
+ style: textTheme.small.copyWith(
+ color: colorScheme.textMuted,
+ height: 20 / 14,
+ ),
+ ),
+ ],
+ ),
+ ),
+ ],
+ ),
+ ),
+ );
+ }
+}
diff --git a/mobile/packages/legacy/lib/pages/legacy_kit_page.dart b/mobile/packages/legacy/lib/pages/legacy_kit_page.dart
new file mode 100644
index 0000000000..3b70a18c64
--- /dev/null
+++ b/mobile/packages/legacy/lib/pages/legacy_kit_page.dart
@@ -0,0 +1,872 @@
+import "dart:typed_data";
+
+import "package:collection/collection.dart";
+import "package:ente_legacy/components/gradient_button.dart";
+import "package:ente_legacy/components/legacy_kit_icons.dart";
+import "package:ente_legacy/models/legacy_kit_models.dart";
+import "package:ente_legacy/pages/create_legacy_kit_sheet.dart";
+import "package:ente_legacy/services/legacy_kit_pdf_service.dart";
+import "package:ente_legacy/services/legacy_kit_service.dart";
+import "package:ente_rust/ente_rust.dart" as rust;
+import "package:ente_strings/ente_strings.dart";
+import "package:ente_ui/components/alert_bottom_sheet.dart";
+import "package:ente_ui/theme/ente_theme.dart";
+import "package:ente_ui/utils/dialog_util.dart";
+import "package:ente_ui/utils/toast_util.dart";
+import "package:ente_utils/file_saver_util.dart";
+import "package:file_saver/file_saver.dart";
+import "package:flutter/material.dart";
+import "package:intl/intl.dart";
+
+typedef LegacyKitAuthenticator = Future<bool> Function(
+ BuildContext context,
+ String reason,
+);
+
+class LegacyKitPage extends StatefulWidget {
+ final LegacyKit kit;
+ final String accountEmail;
+ final LegacyKitAuthenticator? authenticator;
+ final VoidCallback? onChanged;
+
+ const LegacyKitPage({
+ required this.kit,
+ required this.accountEmail,
+ this.authenticator,
+ this.onChanged,
+ super.key,
+ });
+
+ @override
+ State<LegacyKitPage> createState() => _LegacyKitPageState();
+}
+
+class _LegacyKitPageState extends State<LegacyKitPage> {
+ late LegacyKit _kit = widget.kit;
+ bool _loadingRecoveryDetails = false;
+ bool _updatingNotice = false;
+ LegacyKitOwnerRecoverySessionDetails? _recoveryDetails;
+
+ @override
+ void initState() {
+ super.initState();
+ if (_kit.hasActiveRecoverySession) {
+ _loadRecoveryDetails();
+ }
+ }
+
+ @override
+ Widget build(BuildContext context) {
+ final colorScheme = getEnteColorScheme(context);
+ final textTheme = getEnteTextTheme(context);
+ final canUpdateNotice = !_kit.hasActiveRecoverySession && !_updatingNotice;
+
+ return Scaffold(
+ backgroundColor: colorScheme.backgroundBase,
+ appBar: AppBar(
+ backgroundColor: colorScheme.backgroundBase,
+ surfaceTintColor: Colors.transparent,
+ elevation: 0,
+ toolbarHeight: 48,
+ leadingWidth: 48,
+ leading: GestureDetector(
+ onTap: () => Navigator.pop(context),
+ child: const Icon(Icons.arrow_back_outlined),
+ ),
+ ),
+ body: Column(
+ children: [
+ Expanded(
+ child: ListView(
+ padding: const EdgeInsets.symmetric(horizontal: 16),
+ children: [
+ Text(
+ context.strings.legacyKit,
+ style: textTheme.largeBold.copyWith(
+ fontSize: 20.0,
+ height: 28 / 20,
+ ),
+ ),
+ if (_kit.hasActiveRecoverySession) ...[
+ const SizedBox(height: 20),
+ _RecoveryBanner(
+ session: _kit.activeRecoverySession!,
+ parts: _kit.parts,
+ loadingDetails: _loadingRecoveryDetails,
+ details: _recoveryDetails,
+ onBlockRecovery: _blockRecovery,
+ ),
+ ],
+ const SizedBox(height: 20),
+ ..._buildPartRows(colorScheme),
+ const SizedBox(height: 20),
+ Text(
+ context.strings.settings,
+ style: textTheme.bodyBold,
+ ),
+ const SizedBox(height: 8),
+ _RecoveryWaitTimeRow(
+ title: context.strings.recoveryWaitTime,
+ value: _formatNoticePeriod(_kit.noticePeriodInHours),
+ canEdit: canUpdateNotice,
+ onTap: _editRecoveryWaitTime,
+ ),
+ ],
+ ),
+ ),
+ SafeArea(
+ top: false,
+ minimum: const EdgeInsets.fromLTRB(24, 0, 24, 32),
+ child: Column(
+ mainAxisSize: MainAxisSize.min,
+ children: [
+ GradientButton(
+ text: context.strings.downloadAll,
+ height: 52,
+ textStyle: textTheme.small.copyWith(height: 20 / 14),
+ onTap: _downloadAll,
+ ),
+ const SizedBox(height: 12),
+ GestureDetector(
+ onTap: _deleteKit,
+ child: SizedBox(
+ height: 52,
+ width: double.infinity,
+ child: Center(
+ child: Text(
+ context.strings.deleteLegacyKit,
+ style: textTheme.small.copyWith(
+ color: colorScheme.warning700,
+ height: 20 / 14,
+ decoration: TextDecoration.underline,
+ decorationColor: colorScheme.warning700,
+ ),
+ ),
+ ),
+ ),
+ ),
+ ],
+ ),
+ ),
+ ],
+ ),
+ );
+ }
+
+ List<Widget> _buildPartRows(colorScheme) {
+ final cardColor = colorScheme.isLightTheme
+ ? Colors.white
+ : colorScheme.backgroundElevated2;
+ return [
+ for (var index = 0; index < _kit.parts.length; index++) ...[
+ _LegacyKitPartRow(
+ name: _kit.parts[index].name,
+ subtitle: context.strings.legacyKitPartOf(
+ _kit.parts[index].index,
+ _kit.parts.length,
+ ),
+ cardColor: cardColor,
+ avatarColor: _avatarColor(index),
+ onTap: () async {
+ await _downloadPart(_kit.parts[index]);
+ },
+ ),
+ if (index < _kit.parts.length - 1) const SizedBox(height: 8),
+ ],
+ ];
+ }
+
+ Color _avatarColor(int index) {
+ const colors = [
+ Color(0xFF8A38F5),
+ Color(0xFFFFA939),
+ Color(0xFF1071FF),
+ ];
+ return colors[index % colors.length];
+ }
+
+ Future<void> _loadRecoveryDetails() async {
+ setState(() {
+ _loadingRecoveryDetails = true;
+ });
+ try {
+ final details =
+ await LegacyKitService.instance.getRecoverySession(_kit.id);
+ if (mounted) {
+ setState(() {
+ _recoveryDetails = details;
+ });
+ }
+ } catch (_) {
+ if (mounted) {
+ showShortToast(context, context.strings.somethingWentWrong);
+ }
+ } finally {
+ if (mounted) {
+ setState(() {
+ _loadingRecoveryDetails = false;
+ });
+ }
+ }
+ }
+
+ Future<void> _editRecoveryWaitTime() async {
+ final selectedDays = await showLegacyKitRecoveryWaitTimeSheet(
+ context,
+ selectedDays: _kit.noticePeriodInHours ~/ 24,
+ );
+ if (selectedDays == null || selectedDays * 24 == _kit.noticePeriodInHours) {
+ return;
+ }
+ if (!await _authenticate(context.strings.authToManageLegacyKit)) {
+ return;
+ }
+ if (!mounted) {
+ return;
+ }
+
+ setState(() {
+ _updatingNotice = true;
+ });
+ final dialog = createProgressDialog(context, context.strings.pleaseWait);
+ await dialog.show();
+
+ Object? updateError;
+ try {
+ await LegacyKitService.instance.updateRecoveryNotice(
+ kitId: _kit.id,
+ noticePeriodInHours: selectedDays * 24,
+ );
+ if (mounted) {
+ setState(() {
+ _kit = LegacyKit(
+ id: _kit.id,
+ noticePeriodInHours: selectedDays * 24,
+ parts: _kit.parts,
+ createdAt: _kit.createdAt,
+ updatedAt: _kit.updatedAt,
+ activeRecoverySession: _kit.activeRecoverySession,
+ );
+ });
+ }
+ try {
+ await _refreshKit();
+ } catch (_) {
+ // The update has succeeded; the parent page will refresh as well.
+ }
+ widget.onChanged?.call();
+ } catch (e) {
+ updateError = e;
+ } finally {
+ await dialog.hide();
+ if (mounted) {
+ setState(() {
+ _updatingNotice = false;
+ });
+ }
+ }
+
+ if (!mounted) {
+ return;
+ }
+ if (updateError == null) {
+ showShortToast(context, context.strings.recoveryTimeUpdated);
+ } else if (_isActiveRecoverySessionError(updateError)) {
+ try {
+ await _refreshKit();
+ } catch (_) {
+ // The backend rejection is enough to explain the failed update.
+ }
+ await showAlertBottomSheet(
+ context,
+ title: context.strings.cannotUpdateRecoveryTime,
+ message: context.strings.cannotUpdateRecoveryTimeMessage,
+ assetPath: "assets/warning-blue.png",
+ );
+ } else {
+ showShortToast(context, context.strings.somethingWentWrong);
+ }
+ }
+
+ Future<void> _refreshKit() async {
+ final refreshed = await LegacyKitService.instance.getKits();
+ final current = refreshed.where((kit) => kit.id == _kit.id).firstOrNull;
+ if (current != null && mounted) {
+ setState(() {
+ _kit = current;
+ if (!_kit.hasActiveRecoverySession) {
+ _recoveryDetails = null;
+ }
+ });
+ }
+ }
+
+ Future<void> _downloadAll() async {
+ if (!await _authenticate(context.strings.authToManageLegacyKit)) {
+ return;
+ }
+ final dialog = createProgressDialog(context, context.strings.pleaseWait);
+ await dialog.show();
+ try {
+ final shares = await LegacyKitService.instance.downloadShares(_kit.id);
+ final sortedShares = shares.toList(growable: false)
+ ..sort((a, b) => a.shareIndex.compareTo(b.shareIndex));
+ for (final share in sortedShares) {
+ final bytes = await const LegacyKitPdfService().buildRecoverySheet(
+ accountEmail: widget.accountEmail,
+ share: share,
+ allShares: shares,
+ );
+ await _savePdf(bytes, _kit, part: _partForShare(share));
+ }
+ await dialog.hide();
+ if (mounted) {
+ showShortToast(context, context.strings.legacyKitDownloaded);
+ }
+ } catch (_) {
+ await dialog.hide();
+ if (mounted) {
+ showShortToast(context, context.strings.somethingWentWrong);
+ }
+ }
+ }
+
+ Future<void> _downloadPart(LegacyKitPart part) async {
+ if (!await _authenticate(context.strings.authToManageLegacyKit)) {
+ return;
+ }
+ final dialog = createProgressDialog(context, context.strings.pleaseWait);
+ await dialog.show();
+ try {
+ final shares = await LegacyKitService.instance.downloadShares(_kit.id);
+ final share = shares.firstWhereOrNull(
+ (share) => share.shareIndex == part.index,
+ );
+ if (share == null) {
+ throw StateError("Missing legacy kit share for part ${part.index}");
+ }
+ final bytes = await const LegacyKitPdfService().buildRecoverySheet(
+ accountEmail: widget.accountEmail,
+ share: share,
+ allShares: shares,
+ );
+ await _savePdf(bytes, _kit, part: part);
+ await dialog.hide();
+ if (mounted) {
+ showShortToast(context, context.strings.legacyKitSheetDownloaded);
+ }
+ } catch (_) {
+ await dialog.hide();
+ if (mounted) {
+ showShortToast(context, context.strings.somethingWentWrong);
+ }
+ }
+ }
+
+ Future<void> _deleteKit() async {
+ final colorScheme = getEnteColorScheme(context);
+ final confirmed = await showAlertBottomSheet<bool>(
+ context,
+ title: context.strings.deleteLegacyKit,
+ message: context.strings.deleteLegacyKitMessage,
+ assetPath: "assets/warning-red.png",
+ buttons: [
+ SizedBox(
+ width: double.infinity,
+ child: GradientButton(
+ text: context.strings.delete,
+ backgroundColor: colorScheme.warning700,
+ onTap: () => Navigator.of(context).pop(true),
+ ),
+ ),
+ ],
+ );
+ if (confirmed != true) {
+ return;
+ }
+ if (!await _authenticate(context.strings.authToManageLegacyKit)) {
+ return;
+ }
+ try {
+ await LegacyKitService.instance.deleteKit(_kit.id);
+ widget.onChanged?.call();
+ if (mounted) {
+ Navigator.pop(context);
+ }
+ } catch (_) {
+ if (mounted) {
+ showShortToast(context, context.strings.somethingWentWrong);
+ }
+ }
+ }
+
+ Future<void> _blockRecovery() async {
+ final colorScheme = getEnteColorScheme(context);
+ final confirmed = await showAlertBottomSheet<bool>(
+ context,
+ title: context.strings.rejectRecovery,
+ message: context.strings.blockLegacyKitRecoveryMessage,
+ assetPath: "assets/warning-red.png",
+ buttons: [
+ SizedBox(
+ width: double.infinity,
+ child: GradientButton(
+ text: context.strings.rejectRecovery,
+ backgroundColor: colorScheme.warning700,
+ onTap: () => Navigator.of(context).pop(true),
+ ),
+ ),
+ ],
+ );
+ if (confirmed != true) {
+ return;
+ }
+ if (!await _authenticate(context.strings.authToManageLegacyKit)) {
+ return;
+ }
+ try {
+ await LegacyKitService.instance.blockRecovery(_kit.id);
+ final refreshed = await LegacyKitService.instance.getKits();
+ final current = refreshed.where((kit) => kit.id == _kit.id).firstOrNull;
+ if (current != null && mounted) {
+ setState(() {
+ _kit = current;
+ _recoveryDetails = null;
+ });
+ }
+ widget.onChanged?.call();
+ } catch (_) {
+ if (mounted) {
+ showShortToast(context, context.strings.somethingWentWrong);
+ }
+ }
+ }
+
+ Future<bool> _authenticate(String reason) async {
+ final authenticator = widget.authenticator;
+ if (authenticator == null) {
+ return true;
+ }
+ return authenticator(context, reason);
+ }
+
+ Future<void> _savePdf(
+ Uint8List bytes,
+ LegacyKit kit, {
+ LegacyKitPart? part,
+ }) {
+ return FileSaverUtil.saveFile(
+ _fileNameForKit(kit, part: part),
+ "pdf",
+ bytes,
+ MimeType.pdf,
+ );
+ }
+
+ LegacyKitPart _partForShare(LegacyKitShare share) {
+ return _kit.parts.firstWhereOrNull(
+ (part) => part.index == share.shareIndex,
+ ) ??
+ LegacyKitPart(index: share.shareIndex, name: share.partName);
+ }
+
+ String _formatNoticePeriod(int hours) {
+ if (hours == 0) {
+ return context.strings.immediate;
+ }
+ if (hours % 24 == 0) {
+ return context.strings.nDays(hours ~/ 24);
+ }
+ return context.strings.nHours(hours);
+ }
+
+ bool _isActiveRecoverySessionError(Object error) {
+ return error is rust.ContactsError_Http &&
+ error.status == 400 &&
+ error.message.contains("active recovery session");
+ }
+
+ String _fileNameForKit(LegacyKit kit, {LegacyKitPart? part}) {
+ final name = part == null
+ ? _fileNameComponent(kit.displayName, fallback: kit.id)
+ : _fileNameComponent(
+ part.name,
+ fallback: "part-${part.index}",
+ );
+ return "ente-recovery-sheet-$name";
+ }
+
+ String _fileNameComponent(String value, {required String fallback}) {
+ final sanitized = value
+ .trim()
+ .toLowerCase()
+ .replaceAll(RegExp(r"""[\\/:*?"<>|\x00-\x1F]+"""), "-")
+ .replaceAll(RegExp(r"[^a-z0-9]+"), "-")
+ .replaceAll(RegExp(r"-+"), "-")
+ .replaceAll(RegExp(r"^-+|-+$"), "");
+ return sanitized.isEmpty ? fallback : sanitized;
+ }
+}
+
+class _RecoveryBanner extends StatelessWidget {
+ final LegacyKitRecoverySession session;
+ final List<LegacyKitPart> parts;
+ final bool loadingDetails;
+ final LegacyKitOwnerRecoverySessionDetails? details;
+ final VoidCallback onBlockRecovery;
+
+ const _RecoveryBanner({
+ required this.session,
+ required this.parts,
+ required this.loadingDetails,
+ required this.details,
+ required this.onBlockRecovery,
+ });
+
+ @override
+ Widget build(BuildContext context) {
+ final colorScheme = getEnteColorScheme(context);
+ final textTheme = getEnteTextTheme(context);
+ final createdAt = _formatDateTime(session.createdAt);
+ final waitTill = _formatWaitTill(session.waitTill);
+ final attemptSummaries = details == null
+ ? const <_RecoveryAttemptSummary>[]
+ : _summarizeAttempts(details!.initiators);
+
+ return Container(
+ padding: const EdgeInsets.all(18),
+ decoration: BoxDecoration(
+ color: colorScheme.warning400.withValues(alpha: 0.13),
+ borderRadius: BorderRadius.circular(20),
+ ),
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ Text(
+ context.strings.legacyKitRecoveryInProgress,
+ style: textTheme.bodyBold.copyWith(color: colorScheme.warning400),
+ ),
+ const SizedBox(height: 8),
+ Text(
+ context.strings.legacyKitRecoveryWindow(createdAt, waitTill),
+ style: textTheme.smallMuted,
+ ),
+ if (!loadingDetails && details != null) ...[
+ const SizedBox(height: 8),
+ Text(
+ context.strings.legacyKitRecoveryAuditHints(
+ details!.initiators.length,
+ ),
+ style: textTheme.smallMuted,
+ ),
+ if (attemptSummaries.isNotEmpty) ...[
+ const SizedBox(height: 8),
+ ...attemptSummaries.map(
+ (summary) => Padding(
+ padding: const EdgeInsets.only(bottom: 8),
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ Text(
+ "${summary.sheetNames} β€’ ${_formatAttemptCount(summary.attemptCount)}",
+ style: textTheme.miniMuted,
+ ),
+ Text(
+ "Latest IP: ${summary.latestIP}",
+ maxLines: 1,
+ overflow: TextOverflow.ellipsis,
+ style: textTheme.miniMuted,
+ ),
+ Text(
+ "Latest UA: ${summary.latestUserAgent}",
+ maxLines: 2,
+ overflow: TextOverflow.ellipsis,
+ style: textTheme.miniMuted,
+ ),
+ ],
+ ),
+ ),
+ ),
+ ],
+ ],
+ const SizedBox(height: 14),
+ GradientButton(
+ text: context.strings.rejectRecovery,
+ backgroundColor: colorScheme.warning700,
+ onTap: () async => onBlockRecovery(),
+ ),
+ ],
+ ),
+ );
+ }
+
+ String _formatDateTime(int micros) {
+ final dateTime = DateTime.fromMicrosecondsSinceEpoch(micros).toLocal();
+ return DateFormat.yMMMd().add_jm().format(dateTime);
+ }
+
+ String _formatWaitTill(int waitTillMicros) {
+ final dateTime = DateTime.now().add(
+ Duration(microseconds: waitTillMicros),
+ );
+ return DateFormat.yMMMd().add_jm().format(dateTime);
+ }
+
+ List<_RecoveryAttemptSummary> _summarizeAttempts(
+ List<LegacyKitRecoveryInitiatorHint> initiators,
+ ) {
+ final summaryByKey = <String, _RecoveryAttemptSummary>{};
+ for (var index = 0; index < initiators.length; index++) {
+ final initiator = initiators[index];
+ final partIndexes = initiator.usedPartIndexes.toSet().toList()..sort();
+ final key = partIndexes.isEmpty ? "unknown" : partIndexes.join(",");
+ final sheetNames = _sheetNames(partIndexes);
+ final existing = summaryByKey[key];
+ summaryByKey[key] = _RecoveryAttemptSummary(
+ sheetNames: sheetNames,
+ attemptCount: (existing?.attemptCount ?? 0) + 1,
+ latestAttemptIndex: index,
+ latestIP: _nonEmptyOrUnknown(initiator.ip),
+ latestUserAgent: _nonEmptyOrUnknown(initiator.userAgent),
+ );
+ }
+ return summaryByKey.values.toList()
+ ..sort((a, b) => b.latestAttemptIndex.compareTo(a.latestAttemptIndex));
+ }
+
+ String _sheetNames(List<int> partIndexes) {
+ if (partIndexes.isEmpty) {
+ return "Unknown sheets";
+ }
+ return partIndexes.map((partIndex) {
+ final partName = parts
+ .firstWhereOrNull((part) => part.index == partIndex)
+ ?.name
+ .trim();
+ return partName == null || partName.isEmpty
+ ? "Part $partIndex"
+ : partName;
+ }).join(" + ");
+ }
+
+ String _formatAttemptCount(int count) {
+ return count == 1 ? "1 attempt" : "$count attempts";
+ }
+
+ String _nonEmptyOrUnknown(String value) {
+ final trimmed = value.trim();
+ return trimmed.isEmpty ? "Unknown" : trimmed;
+ }
+}
+
+class _RecoveryAttemptSummary {
+ final String sheetNames;
+ final int attemptCount;
+ final int latestAttemptIndex;
+ final String latestIP;
+ final String latestUserAgent;
+
+ const _RecoveryAttemptSummary({
+ required this.sheetNames,
+ required this.attemptCount,
+ required this.latestAttemptIndex,
+ required this.latestIP,
+ required this.latestUserAgent,
+ });
+}
+
+class _LegacyKitPartRow extends StatelessWidget {
+ final String name;
+ final String subtitle;
+ final Color cardColor;
+ final Color avatarColor;
+ final VoidCallback onTap;
+
+ const _LegacyKitPartRow({
+ required this.name,
+ required this.subtitle,
+ required this.cardColor,
+ required this.avatarColor,
+ required this.onTap,
+ });
+
+ @override
+ Widget build(BuildContext context) {
+ final colorScheme = getEnteColorScheme(context);
+ final textTheme = getEnteTextTheme(context);
+
+ return Material(
+ color: cardColor,
+ borderRadius: BorderRadius.circular(20),
+ child: InkWell(
+ borderRadius: BorderRadius.circular(20),
+ onTap: onTap,
+ child: SizedBox(
+ height: 60,
+ child: Padding(
+ padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 10),
+ child: Row(
+ children: [
+ _PartInitial(name: name, color: avatarColor),
+ const SizedBox(width: 12),
+ Expanded(
+ child: Column(
+ mainAxisAlignment: MainAxisAlignment.center,
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ Text(
+ name,
+ style: textTheme.small.copyWith(height: 20 / 14),
+ overflow: TextOverflow.ellipsis,
+ ),
+ const SizedBox(height: 4),
+ Text(
+ subtitle,
+ style: textTheme.mini.copyWith(
+ color: colorScheme.textMuted,
+ height: 16 / 12,
+ ),
+ overflow: TextOverflow.ellipsis,
+ ),
+ ],
+ ),
+ ),
+ SizedBox(
+ height: 40,
+ width: 40,
+ child: Center(
+ child: LegacyKitDownloadIcon(
+ color: colorScheme.textBase,
+ ),
+ ),
+ ),
+ ],
+ ),
+ ),
+ ),
+ ),
+ );
+ }
+}
+
+class _RecoveryWaitTimeRow extends StatelessWidget {
+ final String title;
+ final String value;
+ final bool canEdit;
+ final VoidCallback onTap;
+
+ const _RecoveryWaitTimeRow({
+ required this.title,
+ required this.value,
+ required this.canEdit,
+ required this.onTap,
+ });
+
+ @override
+ Widget build(BuildContext context) {
+ final colorScheme = getEnteColorScheme(context);
+ final textTheme = getEnteTextTheme(context);
+ final cardColor = colorScheme.isLightTheme
+ ? Colors.white
+ : colorScheme.backgroundElevated2;
+
+ return Material(
+ color: cardColor,
+ borderRadius: BorderRadius.circular(20),
+ child: InkWell(
+ borderRadius: BorderRadius.circular(20),
+ onTap: canEdit ? onTap : null,
+ child: SizedBox(
+ height: 60,
+ child: Padding(
+ padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 10),
+ child: Row(
+ children: [
+ SizedBox(
+ height: 36,
+ width: 36,
+ child: Center(
+ child: LegacyKitClockIcon(
+ color: colorScheme.primary700,
+ ),
+ ),
+ ),
+ const SizedBox(width: 12),
+ Expanded(
+ child: Column(
+ mainAxisAlignment: MainAxisAlignment.center,
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ Text(
+ title,
+ style: textTheme.small.copyWith(height: 20 / 14),
+ overflow: TextOverflow.ellipsis,
+ ),
+ const SizedBox(height: 4),
+ Text(
+ value,
+ style: textTheme.mini.copyWith(
+ color: colorScheme.textMuted,
+ height: 16 / 12,
+ ),
+ overflow: TextOverflow.ellipsis,
+ ),
+ ],
+ ),
+ ),
+ SizedBox(
+ height: 40,
+ width: 40,
+ child: canEdit
+ ? Center(
+ child: LegacyKitEditIcon(
+ color: colorScheme.textBase,
+ ),
+ )
+ : const SizedBox.shrink(),
+ ),
+ ],
+ ),
+ ),
+ ),
+ ),
+ );
+ }
+}
+
+class _PartInitial extends StatelessWidget {
+ final String name;
+ final Color color;
+
+ const _PartInitial({required this.name, required this.color});
+
+ @override
+ Widget build(BuildContext context) {
+ final textTheme = getEnteTextTheme(context);
+ final initial = name.trim().isEmpty ? "?" : name.trim()[0].toUpperCase();
+
+ return SizedBox(
+ height: 36,
+ width: 36,
+ child: Center(
+ child: Container(
+ width: 33,
+ height: 33,
+ decoration: BoxDecoration(
+ color: color,
+ shape: BoxShape.circle,
+ ),
+ child: Center(
+ child: Text(
+ initial,
+ style: textTheme.mini.copyWith(
+ color: Colors.white,
+ height: 15 / 12,
+ ),
+ ),
+ ),
+ ),
+ ),
+ );
+ }
+}
diff --git a/mobile/packages/legacy/lib/pages/recover_others_account.dart b/mobile/packages/legacy/lib/pages/recover_others_account.dart
index dc195accda..858f4031e8 100644
--- a/mobile/packages/legacy/lib/pages/recover_others_account.dart
+++ b/mobile/packages/legacy/lib/pages/recover_others_account.dart
@@ -140,7 +140,7 @@ class _RecoverOthersAccountState extends State<RecoverOthersAccount> {
style: Theme.of(context)
.textTheme
.titleMedium!
- .copyWith(fontSize: 14),
+ .copyWith(fontSize: 14.0),
),
),
const Padding(padding: EdgeInsets.all(12)),
diff --git a/mobile/packages/legacy/lib/services/legacy_kit_pdf_service.dart b/mobile/packages/legacy/lib/services/legacy_kit_pdf_service.dart
new file mode 100644
index 0000000000..26653b5393
--- /dev/null
+++ b/mobile/packages/legacy/lib/services/legacy_kit_pdf_service.dart
@@ -0,0 +1,454 @@
+import "dart:convert";
+import "dart:typed_data";
+
+import "package:ente_legacy/models/legacy_kit_models.dart";
+import "package:pdf/pdf.dart";
+import "package:pdf/widgets.dart" as pw;
+
+class LegacyKitPdfService {
+ const LegacyKitPdfService();
+
+ static const String _shareMetadataPrefix = "ente-legacy-kit-share-v1:";
+
+ static const PdfPageFormat _sheetPageFormat = PdfPageFormat(676, 900);
+ static const PdfColor _background = PdfColor.fromInt(0xFFFAFAFA);
+ static const PdfColor _green = PdfColor.fromInt(0xFF08C225);
+ static const PdfColor _dark = PdfColor.fromInt(0xFF212121);
+ static const PdfColor _black = PdfColor.fromInt(0xFF000000);
+ static const PdfColor _white = PdfColor.fromInt(0xFFFFFFFF);
+ static const PdfColor _muted = PdfColor.fromInt(0xFF969696);
+ static const PdfColor _lightText = PdfColor.fromInt(0xFFE5E5E5);
+
+ Future<Uint8List> buildRecoverySheet({
+ required String accountEmail,
+ required LegacyKitShare share,
+ required List<LegacyKitShare> allShares,
+ }) async {
+ final sortedShares = _sortedShares(allShares);
+ final pdf = _document(
+ keywords: _shareMetadata(share),
+ );
+ pdf.addPage(_buildPage(accountEmail, share, sortedShares));
+ return pdf.save();
+ }
+
+ pw.Document _document({required String keywords}) {
+ return pw.Document(
+ title: "Ente Legacy Kit",
+ author: "ente",
+ creator: "ente locker",
+ subject: "Ente Legacy Kit recovery sheet",
+ keywords: keywords,
+ producer: "ente locker",
+ );
+ }
+
+ String _shareMetadata(LegacyKitShare share) {
+ return "$_shareMetadataPrefix${_encodeMetadataPayload(share.toQrPayload())}";
+ }
+
+ String _encodeMetadataPayload(String payload) {
+ return base64Url.encode(utf8.encode(payload)).replaceAll("=", "");
+ }
+
+ pw.Page _buildPage(
+ String accountEmail,
+ LegacyKitShare share,
+ List<LegacyKitShare> sortedShares,
+ ) {
+ return pw.Page(
+ pageFormat: _sheetPageFormat,
+ margin: pw.EdgeInsets.zero,
+ build: (context) {
+ final otherShares = sortedShares
+ .where((item) => item.shareIndex != share.shareIndex)
+ .toList(growable: false);
+ return _buildSheet(
+ accountEmail: accountEmail,
+ share: share,
+ otherShares: otherShares,
+ );
+ },
+ );
+ }
+
+ pw.Widget _buildSheet({
+ required String accountEmail,
+ required LegacyKitShare share,
+ required List<LegacyKitShare> otherShares,
+ }) {
+ final qrPayload = share.toQrPayload();
+ final copyCode = share.toCopyCode();
+ return pw.Container(
+ color: _background,
+ padding: const pw.EdgeInsets.fromLTRB(42, 40, 42, 40),
+ child: pw.Column(
+ crossAxisAlignment: pw.CrossAxisAlignment.start,
+ children: [
+ _header(),
+ pw.SizedBox(height: 29),
+ _hero(accountEmail, share),
+ pw.SizedBox(height: 32),
+ pw.Text(
+ "How to recover the account?",
+ style: pw.TextStyle(
+ color: _black,
+ fontSize: 20,
+ fontWeight: pw.FontWeight.bold,
+ ),
+ ),
+ pw.SizedBox(height: 12),
+ _recoveryBlock(qrPayload, copyCode, otherShares),
+ pw.Spacer(),
+ pw.Center(
+ child: pw.Text(
+ "Store this sheet somewhere safe.\nOn its own, this sheet cannot unlock the account.",
+ textAlign: pw.TextAlign.center,
+ style: const pw.TextStyle(
+ color: _muted,
+ fontSize: 12,
+ lineSpacing: 3,
+ ),
+ ),
+ ),
+ ],
+ ),
+ );
+ }
+
+ pw.Widget _header() {
+ return pw.Row(
+ mainAxisSize: pw.MainAxisSize.min,
+ children: [
+ pw.Container(
+ width: 29,
+ height: 29,
+ decoration: pw.BoxDecoration(
+ border: pw.Border.all(color: _black, width: 1.6),
+ shape: pw.BoxShape.circle,
+ ),
+ child: pw.Center(
+ child: pw.Text(
+ "e",
+ style: pw.TextStyle(
+ color: _black,
+ fontSize: 22,
+ fontWeight: pw.FontWeight.bold,
+ ),
+ ),
+ ),
+ ),
+ pw.SizedBox(width: 10),
+ pw.Column(
+ crossAxisAlignment: pw.CrossAxisAlignment.start,
+ children: [
+ pw.Text(
+ "ente",
+ style: pw.TextStyle(
+ color: _green,
+ fontSize: 22,
+ fontWeight: pw.FontWeight.bold,
+ ),
+ ),
+ pw.Text(
+ "Legacy Kit",
+ style: const pw.TextStyle(color: _muted, fontSize: 12),
+ ),
+ ],
+ ),
+ ],
+ );
+ }
+
+ pw.Widget _hero(String accountEmail, LegacyKitShare share) {
+ return pw.Container(
+ width: 592,
+ height: 213,
+ padding: const pw.EdgeInsets.all(24),
+ decoration: const pw.BoxDecoration(
+ color: _green,
+ borderRadius: pw.BorderRadius.all(pw.Radius.circular(24)),
+ ),
+ child: pw.Row(
+ crossAxisAlignment: pw.CrossAxisAlignment.center,
+ children: [
+ pw.SizedBox(
+ width: 344,
+ child: pw.Column(
+ crossAxisAlignment: pw.CrossAxisAlignment.start,
+ mainAxisAlignment: pw.MainAxisAlignment.center,
+ children: [
+ pw.Text(
+ "HELD BY",
+ style: const pw.TextStyle(
+ color: _white,
+ fontSize: 14,
+ letterSpacing: 2.2,
+ ),
+ ),
+ pw.SizedBox(height: 6),
+ pw.Text(
+ share.partName,
+ style: pw.TextStyle(
+ color: _white,
+ fontSize: 32,
+ fontWeight: pw.FontWeight.bold,
+ ),
+ ),
+ pw.SizedBox(height: 12),
+ pw.Container(
+ padding: const pw.EdgeInsets.symmetric(
+ horizontal: 14,
+ vertical: 8,
+ ),
+ decoration: const pw.BoxDecoration(
+ color: PdfColor(0, 0, 0, 0.36),
+ borderRadius: pw.BorderRadius.all(pw.Radius.circular(12)),
+ ),
+ child: pw.Text(
+ "Legacy Kit for $accountEmail",
+ style: const pw.TextStyle(color: _white, fontSize: 14),
+ ),
+ ),
+ pw.SizedBox(height: 14),
+ pw.Text(
+ "This sheet is one part of a recovery key. If $accountEmail loses access, this and any one other can recover their account.",
+ style: const pw.TextStyle(
+ color: PdfColor(1, 1, 1, 0.86),
+ fontSize: 12,
+ lineSpacing: 3,
+ ),
+ ),
+ ],
+ ),
+ ),
+ pw.Spacer(),
+ pw.Container(
+ width: 146,
+ height: 146,
+ decoration: const pw.BoxDecoration(
+ color: _white,
+ borderRadius: pw.BorderRadius.all(pw.Radius.circular(18)),
+ ),
+ child: pw.Center(
+ child: pw.Text(
+ "QR",
+ style: pw.TextStyle(
+ color: _green,
+ fontSize: 42,
+ fontWeight: pw.FontWeight.bold,
+ ),
+ ),
+ ),
+ ),
+ ],
+ ),
+ );
+ }
+
+ pw.Widget _recoveryBlock(
+ String qrPayload,
+ String copyCode,
+ List<LegacyKitShare> otherShares,
+ ) {
+ return pw.Container(
+ width: 592,
+ height: 378,
+ padding: const pw.EdgeInsets.all(24),
+ decoration: const pw.BoxDecoration(
+ color: _dark,
+ borderRadius: pw.BorderRadius.all(pw.Radius.circular(24)),
+ ),
+ child: pw.Row(
+ crossAxisAlignment: pw.CrossAxisAlignment.center,
+ children: [
+ pw.SizedBox(
+ width: 201,
+ child: pw.Column(
+ crossAxisAlignment: pw.CrossAxisAlignment.center,
+ children: [
+ pw.Container(
+ width: 200,
+ height: 200,
+ padding: const pw.EdgeInsets.all(20),
+ decoration: const pw.BoxDecoration(
+ color: _white,
+ borderRadius: pw.BorderRadius.all(pw.Radius.circular(20)),
+ ),
+ child: pw.BarcodeWidget(
+ barcode: pw.Barcode.qrCode(),
+ data: qrPayload,
+ ),
+ ),
+ pw.SizedBox(height: 8),
+ pw.Text(
+ "OR",
+ style: pw.TextStyle(
+ color: _white,
+ fontSize: 16,
+ fontWeight: pw.FontWeight.bold,
+ ),
+ ),
+ pw.Text(
+ "copy code text",
+ style: const pw.TextStyle(color: _lightText, fontSize: 12),
+ ),
+ pw.SizedBox(height: 10),
+ pw.Container(
+ width: 201,
+ height: 75,
+ padding: const pw.EdgeInsets.all(10),
+ decoration: pw.BoxDecoration(
+ color: _green,
+ border: pw.Border.all(
+ color: _white,
+ width: 1,
+ style: pw.BorderStyle.dashed,
+ ),
+ borderRadius:
+ const pw.BorderRadius.all(pw.Radius.circular(12)),
+ ),
+ child: pw.Center(
+ child: pw.Text(
+ copyCode,
+ textAlign: pw.TextAlign.center,
+ style: pw.TextStyle(
+ color: _background,
+ fontSize: copyCode.length > 220 ? 5.5 : 6.5,
+ fontWeight: pw.FontWeight.bold,
+ lineSpacing: 1,
+ ),
+ ),
+ ),
+ ),
+ ],
+ ),
+ ),
+ pw.SizedBox(width: 28),
+ pw.SizedBox(
+ width: 291,
+ child: pw.Column(
+ mainAxisAlignment: pw.MainAxisAlignment.center,
+ crossAxisAlignment: pw.CrossAxisAlignment.start,
+ children: [
+ _instruction(
+ "1.",
+ "Get one other sheet. The other holders are:",
+ extra: _holderChips(otherShares),
+ ),
+ _instruction(
+ "2.",
+ "Go to legacy.ente.com and click Start recovery",
+ ),
+ _instruction("3.", "Scan the QR codes from both sheets"),
+ _instruction(
+ "4.",
+ "Wait through the recovery period (if one is set).",
+ ),
+ _instruction(
+ "5.",
+ "Return to the site to get the recovery key",
+ bottomPadding: 0,
+ ),
+ ],
+ ),
+ ),
+ ],
+ ),
+ );
+ }
+
+ pw.Widget _instruction(
+ String number,
+ String text, {
+ pw.Widget? extra,
+ double bottomPadding = 16,
+ }) {
+ return pw.Padding(
+ padding: pw.EdgeInsets.only(bottom: bottomPadding),
+ child: pw.Row(
+ crossAxisAlignment: pw.CrossAxisAlignment.start,
+ children: [
+ pw.SizedBox(
+ width: 20,
+ child: pw.Text(
+ number,
+ style: const pw.TextStyle(color: _muted, fontSize: 14),
+ ),
+ ),
+ pw.SizedBox(width: 4),
+ pw.Expanded(
+ child: pw.Column(
+ crossAxisAlignment: pw.CrossAxisAlignment.start,
+ children: [
+ pw.Text(
+ text,
+ style: const pw.TextStyle(
+ color: _white,
+ fontSize: 14,
+ lineSpacing: 3,
+ ),
+ ),
+ if (extra != null) ...[
+ pw.SizedBox(height: 8),
+ extra,
+ ],
+ ],
+ ),
+ ),
+ ],
+ ),
+ );
+ }
+
+ pw.Widget _holderChips(List<LegacyKitShare> shares) {
+ return pw.Wrap(
+ spacing: 6,
+ runSpacing: 6,
+ children: shares.map(_holderChip).toList(growable: false),
+ );
+ }
+
+ pw.Widget _holderChip(LegacyKitShare share) {
+ final initial = share.partName.trim().isEmpty
+ ? "?"
+ : share.partName.trim()[0].toUpperCase();
+ return pw.Container(
+ padding: const pw.EdgeInsets.fromLTRB(4, 4, 10, 4),
+ decoration: const pw.BoxDecoration(
+ color: PdfColor.fromInt(0xFF0A0A0A),
+ // The PDF renderer does not clamp pill radii like Flutter does.
+ borderRadius: pw.BorderRadius.all(pw.Radius.circular(16)),
+ ),
+ child: pw.Row(
+ mainAxisSize: pw.MainAxisSize.min,
+ children: [
+ pw.Container(
+ width: 24,
+ height: 24,
+ decoration: const pw.BoxDecoration(
+ color: PdfColor.fromInt(0xFFFFA939),
+ shape: pw.BoxShape.circle,
+ ),
+ child: pw.Center(
+ child: pw.Text(
+ initial,
+ style: const pw.TextStyle(color: _white, fontSize: 12),
+ ),
+ ),
+ ),
+ pw.SizedBox(width: 6),
+ pw.Text(
+ share.partName,
+ style: const pw.TextStyle(color: _muted, fontSize: 12),
+ ),
+ ],
+ ),
+ );
+ }
+
+ List<LegacyKitShare> _sortedShares(List<LegacyKitShare> shares) {
+ return shares.toList(growable: false)
+ ..sort((a, b) => a.shareIndex.compareTo(b.shareIndex));
+ }
+}
diff --git a/mobile/packages/legacy/lib/services/legacy_kit_service.dart b/mobile/packages/legacy/lib/services/legacy_kit_service.dart
new file mode 100644
index 0000000000..3015b3ee07
--- /dev/null
+++ b/mobile/packages/legacy/lib/services/legacy_kit_service.dart
@@ -0,0 +1,168 @@
+import "package:ente_base/models/key_attributes.dart" as base;
+import "package:ente_configuration/base_configuration.dart";
+import "package:ente_contacts/contacts.dart" as contacts;
+import "package:ente_legacy/models/legacy_kit_models.dart";
+import "package:ente_rust/ente_rust.dart" as rust;
+import "package:logging/logging.dart";
+
+typedef LegacyKitSessionProvider = contacts.ContactsSession? Function();
+
+class LegacyKitService {
+ LegacyKitService._privateConstructor();
+
+ static final LegacyKitService instance =
+ LegacyKitService._privateConstructor();
+
+ final Logger _logger = Logger("LegacyKitService");
+
+ BaseConfiguration? _config;
+ LegacyKitSessionProvider? _sessionProvider;
+ rust.ContactsCtx? _ctx;
+ String? _ctxBaseUrl;
+ int? _ctxUserId;
+ String? _ctxAuthToken;
+
+ bool get isInitialized => _config != null && _sessionProvider != null;
+
+ Future<void> init({
+ required BaseConfiguration config,
+ required LegacyKitSessionProvider sessionProvider,
+ }) async {
+ _config = config;
+ _sessionProvider = sessionProvider;
+ }
+
+ Future<List<LegacyKit>> getKits() async {
+ final ctx = await _requireCtx();
+ final kits = await ctx.legacyKits();
+ return kits.map(LegacyKit.fromRust).toList(growable: false);
+ }
+
+ Future<LegacyKitCreateResult> createKit({
+ required List<String> partNames,
+ required int noticePeriodInHours,
+ }) async {
+ if (partNames.length != 3) {
+ throw ArgumentError.value(
+ partNames,
+ "partNames",
+ "Legacy kit requires exactly three part names",
+ );
+ }
+ final keyAttributes = _requireConfig().getKeyAttributes();
+ if (keyAttributes == null) {
+ throw StateError("Missing account key attributes");
+ }
+ final ctx = await _requireCtx();
+ final result = await ctx.legacyKitCreate(
+ currentUserKeyAttrs: _toRustKeyAttributes(keyAttributes),
+ partNames: partNames,
+ noticePeriodInHours: noticePeriodInHours,
+ );
+ return LegacyKitCreateResult.fromRust(result);
+ }
+
+ Future<List<LegacyKitShare>> downloadShares(String kitId) async {
+ final ctx = await _requireCtx();
+ final shares = await ctx.legacyKitDownloadShares(kitId: kitId);
+ return shares.map(LegacyKitShare.fromRust).toList(growable: false);
+ }
+
+ Future<LegacyKitOwnerRecoverySessionDetails> getRecoverySession(
+ String kitId,
+ ) async {
+ final ctx = await _requireCtx();
+ final details = await ctx.legacyKitRecoverySession(kitId: kitId);
+ return LegacyKitOwnerRecoverySessionDetails.fromRust(details);
+ }
+
+ Future<void> updateRecoveryNotice({
+ required String kitId,
+ required int noticePeriodInHours,
+ }) async {
+ final ctx = await _requireCtx();
+ await ctx.legacyKitUpdateRecoveryNotice(
+ kitId: kitId,
+ noticePeriodInHours: noticePeriodInHours,
+ );
+ }
+
+ Future<void> blockRecovery(String kitId) async {
+ final ctx = await _requireCtx();
+ await ctx.legacyKitBlockRecovery(kitId: kitId);
+ }
+
+ Future<void> deleteKit(String kitId) async {
+ final ctx = await _requireCtx();
+ await ctx.legacyKitDelete(kitId: kitId);
+ }
+
+ BaseConfiguration _requireConfig() {
+ final config = _config;
+ if (config == null) {
+ throw StateError("LegacyKitService has not been initialized");
+ }
+ return config;
+ }
+
+ Future<rust.ContactsCtx> _requireCtx() async {
+ final provider = _sessionProvider;
+ if (provider == null) {
+ throw StateError("LegacyKitService has not been initialized");
+ }
+ final session = provider();
+ if (session == null) {
+ throw StateError("Legacy kit session is not available");
+ }
+ final existing = _ctx;
+ if (existing != null &&
+ _ctxBaseUrl == session.baseUrl &&
+ _ctxUserId == session.userId) {
+ if (_ctxAuthToken != session.authToken) {
+ await existing.updateAuthToken(authToken: session.authToken);
+ _ctxAuthToken = session.authToken;
+ }
+ return existing;
+ }
+
+ final accountKey = await session.resolveAccountKey();
+ _logger.info("Opening legacy kit Rust context for user ${session.userId}");
+ final opened = await rust.openContactsCtx(
+ input: rust.OpenContactsCtxInput(
+ baseUrl: session.baseUrl,
+ authToken: session.authToken,
+ userId: session.userId,
+ masterKey: accountKey,
+ userAgent: session.userAgent,
+ clientPackage: session.clientPackage,
+ clientVersion: session.clientVersion,
+ ),
+ );
+ _ctx = opened.ctx;
+ _ctxBaseUrl = session.baseUrl;
+ _ctxUserId = session.userId;
+ _ctxAuthToken = session.authToken;
+ return opened.ctx;
+ }
+
+ rust.AccountKeyAttributes _toRustKeyAttributes(
+ base.KeyAttributes attributes,
+ ) {
+ return rust.AccountKeyAttributes(
+ kekSalt: attributes.kekSalt,
+ encryptedKey: attributes.encryptedKey,
+ keyDecryptionNonce: attributes.keyDecryptionNonce,
+ publicKey: attributes.publicKey,
+ encryptedSecretKey: attributes.encryptedSecretKey,
+ secretKeyDecryptionNonce: attributes.secretKeyDecryptionNonce,
+ memLimit: attributes.memLimit,
+ opsLimit: attributes.opsLimit,
+ masterKeyEncryptedWithRecoveryKey:
+ attributes.masterKeyEncryptedWithRecoveryKey,
+ masterKeyDecryptionNonce: attributes.masterKeyDecryptionNonce,
+ recoveryKeyEncryptedWithMasterKey:
+ attributes.recoveryKeyEncryptedWithMasterKey,
+ recoveryKeyDecryptionNonce: attributes.recoveryKeyDecryptionNonce,
+ );
+ }
+}
diff --git a/mobile/packages/legacy/pubspec.lock b/mobile/packages/legacy/pubspec.lock
index bbd93fa6c8..b701157851 100644
--- a/mobile/packages/legacy/pubspec.lock
+++ b/mobile/packages/legacy/pubspec.lock
@@ -57,6 +57,22 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.13.0"
+ barcode:
+ dependency: transitive
+ description:
+ name: barcode
+ sha256: "7b6729c37e3b7f34233e2318d866e8c48ddb46c1f7ad01ff7bb2a8de1da2b9f4"
+ url: "https://pub.dev"
+ source: hosted
+ version: "2.2.9"
+ bidi:
+ dependency: transitive
+ description:
+ name: bidi
+ sha256: "77f475165e94b261745cf1032c751e2032b8ed92ccb2bf5716036db79320637d"
+ url: "https://pub.dev"
+ source: hosted
+ version: "2.0.13"
bip39:
dependency: transitive
description:
@@ -256,7 +272,7 @@ packages:
source: path
version: "1.0.0"
ente_rust:
- dependency: "direct overridden"
+ dependency: "direct main"
description:
path: "../rust"
relative: true
@@ -339,7 +355,7 @@ packages:
source: hosted
version: "7.0.1"
file_saver:
- dependency: transitive
+ dependency: "direct main"
description:
name: file_saver
sha256: "9d93db09bd4da9e43238f9dd485360fc51a5c138eea5ef5f407ec56e58079ac0"
@@ -544,13 +560,21 @@ packages:
source: hosted
version: "0.1.0"
hugeicons:
- dependency: transitive
+ dependency: "direct main"
description:
name: hugeicons
sha256: d19c0e2b57ccf455dd8ef08b84da40ae6dbba898c92960a0a0ada77df7865b8a
url: "https://pub.dev"
source: hosted
version: "1.1.5"
+ image:
+ dependency: transitive
+ description:
+ name: image
+ sha256: "4e973fcf4caae1a4be2fa0a13157aa38a8f9cb049db6529aa00b4d71abc4d928"
+ url: "https://pub.dev"
+ source: hosted
+ version: "4.5.4"
intl:
dependency: "direct main"
description:
@@ -815,6 +839,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.3.0"
+ pdf:
+ dependency: "direct main"
+ description:
+ name: pdf
+ sha256: "28eacad99bffcce2e05bba24e50153890ad0255294f4dd78a17075a2ba5c8416"
+ url: "https://pub.dev"
+ source: hosted
+ version: "3.11.3"
petitparser:
dependency: transitive
description:
@@ -879,6 +911,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.2.0"
+ qr:
+ dependency: transitive
+ description:
+ name: qr
+ sha256: "5a1d2586170e172b8a8c8470bbbffd5eb0cd38a66c0d77155ea138d3af3a4445"
+ url: "https://pub.dev"
+ source: hosted
+ version: "3.0.2"
screen_retriever:
dependency: transitive
description:
diff --git a/mobile/packages/legacy/pubspec.yaml b/mobile/packages/legacy/pubspec.yaml
index 5b1c99304c..6405ebb1c0 100644
--- a/mobile/packages/legacy/pubspec.yaml
+++ b/mobile/packages/legacy/pubspec.yaml
@@ -24,6 +24,8 @@ dependencies:
path: ../network
ente_pure_utils:
path: ../ente_pure_utils
+ ente_rust:
+ path: ../rust
ente_sharing:
path: ../sharing
ente_strings:
@@ -32,12 +34,15 @@ dependencies:
path: ../ui
ente_utils:
path: ../utils
+ file_saver: 0.3.1
flutter:
sdk: flutter
flutter_svg: 2.2.3
+ hugeicons: 1.1.5
intl: 0.20.2
logging: 1.3.0
password_strength: 0.2.0
+ pdf: ^3.11.3
pointycastle: 3.9.1
uuid: 4.5.2
diff --git a/mobile/packages/legacy/test/legacy_kit_pdf_service_test.dart b/mobile/packages/legacy/test/legacy_kit_pdf_service_test.dart
new file mode 100644
index 0000000000..8812c340a8
--- /dev/null
+++ b/mobile/packages/legacy/test/legacy_kit_pdf_service_test.dart
@@ -0,0 +1,79 @@
+import "dart:convert";
+
+import "package:ente_legacy/models/legacy_kit_models.dart";
+import "package:ente_legacy/services/legacy_kit_pdf_service.dart";
+import "package:flutter_test/flutter_test.dart";
+
+void main() {
+ test("normalizes compact legacy kit payload fields", () {
+ final payload = jsonDecode(
+ const LegacyKitShare(
+ payloadVersion: 1,
+ variant: 1,
+ kitId: " e04efa62-2607-4c8b-b4c7-6c84f08fe162 ",
+ shareIndex: 2,
+ share: "USpH7sFwOXQ/TeSu1BeAJqfeVxwlKXZLnlCZ mOfmQiY=",
+ checksum: " c1T4uxBh7ws= ",
+ partName: "Amit, Brother, 98",
+ ).toQrPayload(),
+ ) as Map<String, dynamic>;
+
+ expect(payload["k"], "e04efa62-2607-4c8b-b4c7-6c84f08fe162");
+ expect(payload["s"], "USpH7sFwOXQ/TeSu1BeAJqfeVxwlKXZLnlCZmOfmQiY=");
+ expect(payload["c"], "c1T4uxBh7ws=");
+ expect(payload["n"], "Amit, Brother, 98");
+ });
+
+ test("encodes compact payload as copy code", () {
+ final share = _share(1, "Mom");
+ expect(
+ utf8.decode(base64Url.decode(base64Url.normalize(share.toCopyCode()))),
+ share.toQrPayload(),
+ );
+ });
+
+ test("builds individual legacy kit recovery sheet PDFs", () async {
+ final shares = [
+ _share(1, "Mom"),
+ _share(2, "Alex"),
+ _share(3, "Lawyer"),
+ ];
+
+ const service = LegacyKitPdfService();
+ final sheets = await Future.wait(
+ shares.map(
+ (share) => service.buildRecoverySheet(
+ accountEmail: "[email protected]",
+ share: share,
+ allShares: shares,
+ ),
+ ),
+ );
+
+ for (var index = 0; index < sheets.length; index++) {
+ expect(String.fromCharCodes(sheets[index].take(4)), "%PDF");
+ expect(
+ _metadataPayload(sheets[index], "ente-legacy-kit-share-v1:"),
+ shares[index].toQrPayload(),
+ );
+ }
+ });
+}
+
+String _metadataPayload(List<int> pdf, String prefix) {
+ final text = String.fromCharCodes(pdf);
+ final encoded = RegExp("$prefix([A-Za-z0-9_-]+)").firstMatch(text)!.group(1)!;
+ return utf8.decode(base64Url.decode(base64Url.normalize(encoded)));
+}
+
+LegacyKitShare _share(int index, String partName) {
+ return LegacyKitShare(
+ payloadVersion: 1,
+ variant: 1,
+ kitId: "kit-id",
+ shareIndex: index,
+ share: "AQEgx7Kp2mNfR4wBzH8vTjYdLnUcXsS6aWe3qFh9iDlOkPr0tMbJ4vG$index",
+ checksum: "checksum",
+ partName: partName,
+ );
+}
diff --git a/mobile/packages/strings/lib/l10n/arb/strings_en.arb b/mobile/packages/strings/lib/l10n/arb/strings_en.arb
index 280f1ab800..5df9dc8832 100644
--- a/mobile/packages/strings/lib/l10n/arb/strings_en.arb
+++ b/mobile/packages/strings/lib/l10n/arb/strings_en.arb
@@ -821,6 +821,102 @@
"legacyPageDesc2": "Trusted contacts can initiate account recovery, and if not blocked within 30 days, reset your password and access your account.",
"legacyAccounts": "Legacy accounts",
"trustedContacts": "Trusted contacts",
+ "legacyKits": "Legacy kits",
+ "legacyKit": "Legacy kit",
+ "createLegacyKit": "Create legacy kit",
+ "createAnotherKit": "Create another kit",
+ "createKit": "Create kit",
+ "legacyKitCreateDescription": "Name the three people who will each hold a part of your recovery key.",
+ "legacyKitContactNameHint": "Contact {index} - e.g. {example}",
+ "@legacyKitContactNameHint": {
+ "placeholders": {
+ "index": {
+ "type": "int",
+ "example": "2"
+ },
+ "example": {
+ "type": "String",
+ "example": "Alex"
+ }
+ }
+ },
+ "legacyKitPartNameHint": "Part {index} name",
+ "@legacyKitPartNameHint": {
+ "placeholders": {
+ "index": {
+ "type": "int",
+ "example": "1"
+ }
+ }
+ },
+ "legacyKitStorageGuidance": "Store each sheet separately. Printed sheets can be disabled later by deleting the kit.",
+ "legacyKitPageDescription": "Name the three people who will each hold a part of your recovery key.",
+ "legacyKitPartOf": "Part {index} of {count}",
+ "@legacyKitPartOf": {
+ "placeholders": {
+ "index": {
+ "type": "int",
+ "example": "1"
+ },
+ "count": {
+ "type": "int",
+ "example": "3"
+ }
+ }
+ },
+ "recoveryWaitTime": "Recovery wait time",
+ "recoverySheets": "Recovery sheets",
+ "downloadAll": "Download all",
+ "legacyKitSheetDownloaded": "Recovery sheet downloaded",
+ "deleteLegacyKit": "Delete legacy kit",
+ "deleteLegacyKitMessage": "All shared sheets will become invalid and can no longer be used for recovery.",
+ "blockLegacyKitRecoveryMessage": "This will stop the active recovery attempt. The sheets can still be used to start a new attempt later.",
+ "legacyKitRecoveryInProgress": "Recovery attempt in progress",
+ "legacyKitRecoveryWindow": "Started on {startedAt}. Recovery will be available on {availableAt}.",
+ "@legacyKitRecoveryWindow": {
+ "placeholders": {
+ "startedAt": {
+ "type": "String",
+ "example": "Apr 8, 2026"
+ },
+ "availableAt": {
+ "type": "String",
+ "example": "Apr 15, 2026"
+ }
+ }
+ },
+ "legacyKitRecoveryAuditHints": "{count} recovery open attempts recorded",
+ "@legacyKitRecoveryAuditHints": {
+ "placeholders": {
+ "count": {
+ "type": "int",
+ "example": "2"
+ }
+ }
+ },
+ "legacyKitDownloaded": "Legacy kit downloaded",
+ "legacyKitMaxReached": "You can create up to 5 legacy kits.",
+ "authToManageLegacyKit": "Authenticate to manage legacy kits",
+ "createdOn": "Created {date}",
+ "@createdOn": {
+ "placeholders": {
+ "date": {
+ "type": "String",
+ "example": "Apr 1, 2026"
+ }
+ }
+ },
+ "immediate": "Immediate",
+ "settings": "Settings",
+ "nHours": "{count} hours",
+ "@nHours": {
+ "placeholders": {
+ "count": {
+ "type": "int",
+ "example": "12"
+ }
+ }
+ },
"legacyInvite": "{email} has invited you to be a trusted contact",
"@legacyInvite": {
"placeholders": {
diff --git a/mobile/packages/ui/lib/components/base_bottom_sheet.dart b/mobile/packages/ui/lib/components/base_bottom_sheet.dart
index 92f810870a..19a1cf281d 100644
--- a/mobile/packages/ui/lib/components/base_bottom_sheet.dart
+++ b/mobile/packages/ui/lib/components/base_bottom_sheet.dart
@@ -12,6 +12,12 @@ Future<T?> showBaseBottomSheet<T>(
Color? backgroundColor,
CrossAxisAlignment crossAxisAlignment = CrossAxisAlignment.start,
EdgeInsets padding = const EdgeInsets.all(16),
+ BorderRadiusGeometry borderRadius = const BorderRadius.only(
+ topLeft: Radius.circular(24),
+ topRight: Radius.circular(24),
+ ),
+ BoxBorder? border,
+ TextStyle? titleTextStyle,
bool isDismissible = true,
bool enableDrag = true,
bool isKeyboardAware = false,
@@ -30,6 +36,9 @@ Future<T?> showBaseBottomSheet<T>(
backgroundColor: backgroundColor,
crossAxisAlignment: crossAxisAlignment,
padding: padding,
+ borderRadius: borderRadius,
+ border: border,
+ titleTextStyle: titleTextStyle,
isKeyboardAware: isKeyboardAware,
child: child,
),
@@ -43,6 +52,9 @@ class BaseBottomSheet extends StatelessWidget {
final VoidCallback? onClose;
final CrossAxisAlignment crossAxisAlignment;
final EdgeInsets padding;
+ final BorderRadiusGeometry borderRadius;
+ final BoxBorder? border;
+ final TextStyle? titleTextStyle;
final Color? backgroundColor;
final double headerSpacing;
final bool isKeyboardAware;
@@ -54,6 +66,12 @@ class BaseBottomSheet extends StatelessWidget {
this.onClose,
this.crossAxisAlignment = CrossAxisAlignment.start,
this.padding = const EdgeInsets.all(16),
+ this.borderRadius = const BorderRadius.only(
+ topLeft: Radius.circular(24),
+ topRight: Radius.circular(24),
+ ),
+ this.border,
+ this.titleTextStyle,
this.backgroundColor,
this.headerSpacing = 0,
this.isKeyboardAware = false,
@@ -70,10 +88,8 @@ class BaseBottomSheet extends StatelessWidget {
return Container(
decoration: BoxDecoration(
color: backgroundColor ?? colorScheme.backgroundElevated2,
- borderRadius: const BorderRadius.only(
- topLeft: Radius.circular(24),
- topRight: Radius.circular(24),
- ),
+ borderRadius: borderRadius,
+ border: border,
),
child: Padding(
padding: EdgeInsets.only(bottom: bottomInset),
@@ -88,7 +104,7 @@ class BaseBottomSheet extends StatelessWidget {
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
- Text(title, style: textTheme.largeBold),
+ Text(title, style: titleTextStyle ?? textTheme.largeBold),
if (showCloseButton)
CloseIconButton(onTap: onClose)
else
diff --git a/mobile/packages/ui/lib/components/captioned_text_widget_v2.dart b/mobile/packages/ui/lib/components/captioned_text_widget_v2.dart
index 259e7f2c1a..5a52ab6949 100644
--- a/mobile/packages/ui/lib/components/captioned_text_widget_v2.dart
+++ b/mobile/packages/ui/lib/components/captioned_text_widget_v2.dart
@@ -8,8 +8,10 @@ class CaptionedTextWidgetV2 extends StatelessWidget {
final bool makeTextBold;
final Color? textColor;
final Color? subTitleColor;
+ final TextStyle? subTitleTextStyle;
final Widget? trailingTitleWidget;
final double trailingTitleGap;
+ final bool subTitleInNewLine;
const CaptionedTextWidgetV2({
required this.title,
@@ -18,8 +20,10 @@ class CaptionedTextWidgetV2 extends StatelessWidget {
this.makeTextBold = false,
this.textColor,
this.subTitleColor,
+ this.subTitleTextStyle,
this.trailingTitleWidget,
this.trailingTitleGap = 8.0,
+ this.subTitleInNewLine = false,
super.key,
});
@@ -35,39 +39,75 @@ class CaptionedTextWidgetV2 extends StatelessWidget {
return Flexible(
child: Padding(
- padding: const EdgeInsets.symmetric(vertical: 8, horizontal: 2),
- child: Row(
- children: [
- Flexible(
- child: trailingTitleWidget != null
- ? Text(
- title,
- style: titleStyle,
- overflow: TextOverflow.ellipsis,
- )
- : RichText(
- text: TextSpan(
- style: titleStyle,
- children: [
- TextSpan(text: title),
- if (subTitle != null)
- TextSpan(
- text: ' \u2022 $subTitle',
- style: enteTextTheme.small.copyWith(
- color:
- subTitleColor ?? enteColorScheme.textMuted,
- ),
- ),
- ],
+ padding: EdgeInsets.symmetric(
+ vertical: subTitleInNewLine ? 0 : 8,
+ horizontal: 2,
+ ),
+ child: subTitleInNewLine
+ ? Column(
+ mainAxisSize: MainAxisSize.min,
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ Row(
+ children: [
+ Flexible(
+ child: Text(
+ title,
+ style: titleStyle,
+ overflow: TextOverflow.ellipsis,
+ ),
),
+ if (trailingTitleWidget != null) ...[
+ SizedBox(width: trailingTitleGap),
+ trailingTitleWidget!,
+ ],
+ ],
+ ),
+ if (subTitle != null) ...[
+ const SizedBox(height: 4),
+ Text(
+ subTitle!,
+ style: subTitleTextStyle ??
+ enteTextTheme.mini.copyWith(
+ color: subTitleColor ?? enteColorScheme.textMuted,
+ ),
+ overflow: TextOverflow.ellipsis,
),
- ),
- if (trailingTitleWidget != null) ...[
- SizedBox(width: trailingTitleGap),
- trailingTitleWidget!,
- ],
- ],
- ),
+ ],
+ ],
+ )
+ : Row(
+ children: [
+ Flexible(
+ child: trailingTitleWidget != null
+ ? Text(
+ title,
+ style: titleStyle,
+ overflow: TextOverflow.ellipsis,
+ )
+ : RichText(
+ text: TextSpan(
+ style: titleStyle,
+ children: [
+ TextSpan(text: title),
+ if (subTitle != null)
+ TextSpan(
+ text: ' \u2022 $subTitle',
+ style: enteTextTheme.small.copyWith(
+ color: subTitleColor ??
+ enteColorScheme.textMuted,
+ ),
+ ),
+ ],
+ ),
+ ),
+ ),
+ if (trailingTitleWidget != null) ...[
+ SizedBox(width: trailingTitleGap),
+ trailingTitleWidget!,
+ ],
+ ],
+ ),
),
);
}
diff --git a/mobile/packages/ui/lib/components/menu_section_title.dart b/mobile/packages/ui/lib/components/menu_section_title.dart
index 1785d14212..9ae485cce9 100644
--- a/mobile/packages/ui/lib/components/menu_section_title.dart
+++ b/mobile/packages/ui/lib/components/menu_section_title.dart
@@ -4,14 +4,26 @@ import 'package:flutter/widgets.dart';
class MenuSectionTitle extends StatelessWidget {
final String title;
final IconData? iconData;
+ final EdgeInsetsGeometry padding;
+ final TextStyle? textStyle;
- const MenuSectionTitle({super.key, required this.title, this.iconData});
+ const MenuSectionTitle({
+ super.key,
+ required this.title,
+ this.iconData,
+ this.padding = const EdgeInsets.only(left: 8, top: 6, bottom: 6),
+ this.textStyle,
+ });
@override
Widget build(BuildContext context) {
final colorScheme = getEnteColorScheme(context);
+ final effectiveTextStyle = textStyle ??
+ getEnteTextTheme(context).small.copyWith(
+ color: colorScheme.textMuted,
+ );
return Padding(
- padding: const EdgeInsets.only(left: 8, top: 6, bottom: 6),
+ padding: padding,
child: Row(
children: [
iconData != null
@@ -24,9 +36,7 @@ class MenuSectionTitle extends StatelessWidget {
iconData != null ? const SizedBox(width: 8) : const SizedBox.shrink(),
Text(
title,
- style: getEnteTextTheme(context).small.copyWith(
- color: colorScheme.textMuted,
- ),
+ style: effectiveTextStyle,
),
],
),