Skip to content

armgit / ente

Public Imported from GitHub
0

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

refactor: Rename bottom sheet classes for consistency and clarity

AmanRajSinghMourya4fb05c76ec1c
diff --git a/mobile/apps/locker/lib/ui/sharing/add_email_bottom_sheet.dart b/mobile/apps/locker/lib/ui/sharing/add_email_bottom_sheet.dart
index 68291f4755..970b4871f0 100644
--- a/mobile/apps/locker/lib/ui/sharing/add_email_bottom_sheet.dart
+++ b/mobile/apps/locker/lib/ui/sharing/add_email_bottom_sheet.dart
@@ -30,28 +30,28 @@ Future<void> showAddEmailSheet(
title: context.l10n.addNewEmail,
headerSpacing: 20,
isKeyboardAware: true,
- child: AddEmailBottomSheet(
+ child: AddEmailSheet(
collection: collection,
onShareAdded: onShareAdded,
),
);
}
-class AddEmailBottomSheet extends StatefulWidget {
+class AddEmailSheet extends StatefulWidget {
final Collection collection;
final VoidCallback onShareAdded;
- const AddEmailBottomSheet({
+ const AddEmailSheet({
super.key,
required this.collection,
required this.onShareAdded,
});
@override
- State<AddEmailBottomSheet> createState() => _AddEmailBottomSheetState();
+ State<AddEmailSheet> createState() => _AddEmailSheetState();
}
-class _AddEmailBottomSheetState extends State<AddEmailBottomSheet> {
+class _AddEmailSheetState extends State<AddEmailSheet> {
bool _shareLater = false;
String _email = "";
bool _emailIsValid = false;
diff --git a/mobile/apps/locker/lib/ui/sharing/share_collection_bottom_sheet.dart b/mobile/apps/locker/lib/ui/sharing/share_collection_bottom_sheet.dart
index 81887f360c..13ec779ae0 100644
--- a/mobile/apps/locker/lib/ui/sharing/share_collection_bottom_sheet.dart
+++ b/mobile/apps/locker/lib/ui/sharing/share_collection_bottom_sheet.dart
@@ -25,25 +25,23 @@ Future<void> showShareCollectionSheet(
context,
title: context.l10n.sharedWith,
headerSpacing: 20,
- child: ShareCollectionBottomSheet(collection: collection),
+ child: ShareCollectionSheet(collection: collection),
);
}
-class ShareCollectionBottomSheet extends StatefulWidget {
+class ShareCollectionSheet extends StatefulWidget {
final Collection collection;
- const ShareCollectionBottomSheet({
+ const ShareCollectionSheet({
super.key,
required this.collection,
});
@override
- State<ShareCollectionBottomSheet> createState() =>
- _ShareCollectionBottomSheetState();
+ State<ShareCollectionSheet> createState() => _ShareCollectionSheetState();
}
-class _ShareCollectionBottomSheetState
- extends State<ShareCollectionBottomSheet> {
+class _ShareCollectionSheetState extends State<ShareCollectionSheet> {
late CollectionActions _collectionActions;
final ScrollController _scrollController = ScrollController();
diff --git a/mobile/packages/legacy/lib/components/trusted_contact_bottom_sheet.dart b/mobile/packages/legacy/lib/components/trusted_contact_bottom_sheet.dart
index cd63559b1a..91c4d34dd6 100644
--- a/mobile/packages/legacy/lib/components/trusted_contact_bottom_sheet.dart
+++ b/mobile/packages/legacy/lib/components/trusted_contact_bottom_sheet.dart
@@ -2,20 +2,20 @@ import "package:ente_legacy/components/gradient_button.dart";
import "package:ente_legacy/components/recovery_date_selector.dart";
import "package:ente_legacy/models/emergency_models.dart";
import "package:ente_strings/ente_strings.dart";
-import "package:ente_ui/components/close_icon_button.dart";
-import "package:ente_ui/theme/colors.dart";
+import "package:ente_ui/components/base_bottom_sheet.dart";
import "package:ente_ui/theme/ente_theme.dart";
-import "package:ente_ui/theme/text_style.dart";
import "package:flutter/material.dart";
-Future<TrustedContactResult?> showTrustedContactBottomSheet(
+Future<TrustedContactResult?> showTrustedContactSheet(
BuildContext context, {
required EmergencyContact contact,
}) {
- return showModalBottomSheet<TrustedContactResult>(
- context: context,
- isScrollControlled: true,
- builder: (context) => TrustedContactBottomSheet(contact: contact),
+ final email = contact.emergencyContact.email;
+ return showBaseBottomSheet<TrustedContactResult>(
+ context,
+ title: email,
+ headerSpacing: 20,
+ child: TrustedContactSheet(contact: contact),
);
}
@@ -34,20 +34,19 @@ class TrustedContactResult {
});
}
-class TrustedContactBottomSheet extends StatefulWidget {
+class TrustedContactSheet extends StatefulWidget {
final EmergencyContact contact;
- const TrustedContactBottomSheet({
+ const TrustedContactSheet({
required this.contact,
super.key,
});
@override
- State<TrustedContactBottomSheet> createState() =>
- _TrustedContactBottomSheetState();
+ State<TrustedContactSheet> createState() => _TrustedContactSheetState();
}
-class _TrustedContactBottomSheetState extends State<TrustedContactBottomSheet> {
+class _TrustedContactSheetState extends State<TrustedContactSheet> {
late int _selectedRecoveryDays;
late int _originalRecoveryDays;
@@ -67,131 +66,66 @@ class _TrustedContactBottomSheetState extends State<TrustedContactBottomSheet> {
final isPending = widget.contact.isPendingInvite();
final email = widget.contact.emergencyContact.email;
- return Container(
- decoration: BoxDecoration(
- color: colorScheme.backgroundElevated2,
- borderRadius: const BorderRadius.only(
- topLeft: Radius.circular(24),
- topRight: Radius.circular(24),
- ),
- ),
- child: SafeArea(
- top: false,
- child: Padding(
- padding: const EdgeInsets.all(16),
- child: Column(
- mainAxisSize: MainAxisSize.min,
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- _buildHeader(colorScheme, textTheme, email),
- const SizedBox(height: 12),
- _buildDescription(colorScheme, textTheme, email, isPending),
- const SizedBox(height: 20),
- _buildRecoveryTimeSection(),
- const SizedBox(height: 20),
- _buildUpdateTimeButton(colorScheme, textTheme),
- const SizedBox(height: 20),
- _buildRevokeButton(colorScheme, textTheme, isPending),
- ],
- ),
- ),
- ),
- );
- }
-
- Widget _buildHeader(
- EnteColorScheme colorScheme,
- EnteTextTheme textTheme,
- String email,
- ) {
- return Row(
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- children: [
- Expanded(
- child: Text(
- email,
- style: textTheme.largeBold,
- overflow: TextOverflow.ellipsis,
- ),
- ),
- const CloseIconButton(),
- ],
- );
- }
-
- Widget _buildDescription(
- EnteColorScheme colorScheme,
- EnteTextTheme textTheme,
- String email,
- bool isPending,
- ) {
final String description = isPending
? context.strings.trustedContactInvitePending(email)
: context.strings.trustedContactAccepted(email);
- return Text(
- description,
- style: textTheme.small.copyWith(color: colorScheme.textMuted),
- );
- }
-
- Widget _buildRecoveryTimeSection() {
- return RecoveryDateSelector(
- selectedDays: _selectedRecoveryDays,
- onDaysChanged: (days) {
- setState(() {
- _selectedRecoveryDays = days;
- });
- },
- );
- }
-
- Widget _buildUpdateTimeButton(
- EnteColorScheme colorScheme,
- EnteTextTheme textTheme,
- ) {
- return GradientButton(
- text: context.strings.updateTime,
- onTap: _hasChanges
- ? () {
- Navigator.of(context).pop(
- TrustedContactResult(
- action: TrustedContactAction.updateTime,
- selectedDays: _selectedRecoveryDays,
- ),
- );
- }
- : null,
- );
- }
-
- Widget _buildRevokeButton(
- EnteColorScheme colorScheme,
- EnteTextTheme textTheme,
- bool isPending,
- ) {
final String label =
isPending ? context.strings.revokeInvite : context.strings.remove;
- return GestureDetector(
- onTap: () {
- Navigator.of(context).pop(
- TrustedContactResult(action: TrustedContactAction.revoke),
- );
- },
- child: SizedBox(
- width: double.infinity,
- child: Center(
- child: Text(
- label,
- style: textTheme.bodyBold.copyWith(
- color: colorScheme.warning400,
- decoration: TextDecoration.underline,
- decorationColor: colorScheme.warning400,
+ return Column(
+ mainAxisSize: MainAxisSize.min,
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ Text(
+ description,
+ style: textTheme.small.copyWith(color: colorScheme.textMuted),
+ ),
+ const SizedBox(height: 20),
+ RecoveryDateSelector(
+ selectedDays: _selectedRecoveryDays,
+ onDaysChanged: (days) {
+ setState(() {
+ _selectedRecoveryDays = days;
+ });
+ },
+ ),
+ const SizedBox(height: 20),
+ GradientButton(
+ text: context.strings.updateTime,
+ onTap: _hasChanges
+ ? () {
+ Navigator.of(context).pop(
+ TrustedContactResult(
+ action: TrustedContactAction.updateTime,
+ selectedDays: _selectedRecoveryDays,
+ ),
+ );
+ }
+ : null,
+ ),
+ const SizedBox(height: 20),
+ GestureDetector(
+ onTap: () {
+ Navigator.of(context).pop(
+ TrustedContactResult(action: TrustedContactAction.revoke),
+ );
+ },
+ child: SizedBox(
+ width: double.infinity,
+ child: Center(
+ child: Text(
+ label,
+ style: textTheme.bodyBold.copyWith(
+ color: colorScheme.warning400,
+ decoration: TextDecoration.underline,
+ decorationColor: colorScheme.warning400,
+ ),
+ ),
),
),
),
- ),
+ ],
);
}
}
diff --git a/mobile/packages/legacy/lib/pages/emergency_page.dart b/mobile/packages/legacy/lib/pages/emergency_page.dart
index 257e9e0833..5e29b9b7da 100644
--- a/mobile/packages/legacy/lib/pages/emergency_page.dart
+++ b/mobile/packages/legacy/lib/pages/emergency_page.dart
@@ -6,8 +6,7 @@ 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/pages/other_contact_page.dart";
-import "package:ente_legacy/pages/select_contact_page.dart"
- show showAddContactBottomSheet;
+import "package:ente_legacy/pages/select_contact_page.dart";
import "package:ente_legacy/services/emergency_service.dart";
import "package:ente_sharing/user_avator_widget.dart";
import "package:ente_strings/ente_strings.dart";
@@ -266,7 +265,7 @@ class _EmergencyPageState extends State<EmergencyPage> {
GradientButton(
text: context.strings.addTrustedContact,
onTap: () async {
- final result = await showAddContactBottomSheet(
+ final result = await showAddContactSheet(
context,
emergencyInfo: info!,
config: widget.config,
@@ -285,7 +284,7 @@ class _EmergencyPageState extends State<EmergencyPage> {
GradientButton(
text: context.strings.addTrustedContact,
onTap: () async {
- final result = await showAddContactBottomSheet(
+ final result = await showAddContactSheet(
context,
emergencyInfo: info!,
config: widget.config,
@@ -410,7 +409,7 @@ class _EmergencyPageState extends State<EmergencyPage> {
BuildContext context,
EmergencyContact contact,
) async {
- final result = await showTrustedContactBottomSheet(
+ final result = await showTrustedContactSheet(
context,
contact: contact,
);
diff --git a/mobile/packages/legacy/lib/pages/select_contact_page.dart b/mobile/packages/legacy/lib/pages/select_contact_page.dart
index 82cb55ec4d..372ba8944a 100644
--- a/mobile/packages/legacy/lib/pages/select_contact_page.dart
+++ b/mobile/packages/legacy/lib/pages/select_contact_page.dart
@@ -10,8 +10,8 @@ import "package:ente_sharing/user_avator_widget.dart";
import "package:ente_sharing/verify_identity_dialog.dart";
import "package:ente_strings/ente_strings.dart";
import "package:ente_ui/components/alert_bottom_sheet.dart";
+import "package:ente_ui/components/base_bottom_sheet.dart";
import "package:ente_ui/components/captioned_text_widget_v2.dart";
-import "package:ente_ui/components/close_icon_button.dart";
import "package:ente_ui/components/divider_widget.dart";
import "package:ente_ui/components/menu_item_widget_v2.dart";
import "package:ente_ui/theme/colors.dart";
@@ -22,41 +22,43 @@ import "package:flutter/material.dart";
import "package:logging/logging.dart";
/// Shows the add contact bottom sheet and returns true if a contact was added
-Future<bool?> showAddContactBottomSheet(
+Future<bool?> showAddContactSheet(
BuildContext context, {
required EmergencyInfo emergencyInfo,
required BaseConfiguration config,
}) {
- return showModalBottomSheet<bool>(
- context: context,
- isScrollControlled: true,
- builder: (context) => AddContactBottomSheet(
+ return showBaseBottomSheet<bool>(
+ context,
+ title: context.strings.addTrustedContact,
+ headerSpacing: 20,
+ isKeyboardAware: true,
+ child: AddContactSheet(
emergencyInfo: emergencyInfo,
config: config,
),
);
}
-class AddContactBottomSheet extends StatefulWidget {
+class AddContactSheet extends StatefulWidget {
final EmergencyInfo emergencyInfo;
final BaseConfiguration config;
- const AddContactBottomSheet({
+ const AddContactSheet({
required this.emergencyInfo,
required this.config,
super.key,
});
@override
- State<StatefulWidget> createState() => _AddContactBottomSheetState();
+ State<AddContactSheet> createState() => _AddContactSheetState();
}
-class _AddContactBottomSheetState extends State<AddContactBottomSheet> {
+class _AddContactSheetState extends State<AddContactSheet> {
String selectedEmail = "";
String _email = "";
bool _emailIsValid = false;
int _selectedRecoveryDays = 14;
- late final Logger _logger = Logger("AddContactBottomSheet");
+ late final Logger _logger = Logger("AddContactSheet");
final textFieldFocusNode = FocusNode();
final _textController = TextEditingController();
@@ -75,66 +77,69 @@ class _AddContactBottomSheetState extends State<AddContactBottomSheet> {
final colorScheme = getEnteColorScheme(context);
final textTheme = getEnteTextTheme(context);
final List<User> suggestedUsers = _getSuggestedUser();
- final bottomInset = MediaQuery.of(context).viewInsets.bottom;
+ final bool canAdd = selectedEmail.isNotEmpty || _emailIsValid;
- return Container(
- decoration: BoxDecoration(
- color: colorScheme.backgroundElevated2,
- borderRadius: const BorderRadius.only(
- topLeft: Radius.circular(24),
- topRight: Radius.circular(24),
- ),
- ),
- child: Padding(
- padding: EdgeInsets.only(bottom: bottomInset),
- child: SafeArea(
- top: false,
- child: Padding(
- padding: const EdgeInsets.all(16),
- child: SingleChildScrollView(
- child: Column(
- mainAxisSize: MainAxisSize.min,
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- _buildHeader(colorScheme, textTheme),
- const SizedBox(height: 12),
- _buildEmailInputRow(colorScheme),
- if (suggestedUsers.isNotEmpty) ...[
- const SizedBox(height: 20),
- _buildExistingContactsSection(
- suggestedUsers,
- colorScheme,
- textTheme,
- ),
- ],
- const SizedBox(height: 20),
- _buildRecoveryTimeSection(textTheme),
- const SizedBox(height: 20),
- _buildAddContactButton(textTheme),
- const SizedBox(height: 12),
- _buildVerifyLink(textTheme),
- ],
+ return SingleChildScrollView(
+ child: Column(
+ mainAxisSize: MainAxisSize.min,
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ _buildEmailInputRow(colorScheme),
+ if (suggestedUsers.isNotEmpty) ...[
+ const SizedBox(height: 20),
+ _buildExistingContactsSection(
+ suggestedUsers,
+ colorScheme,
+ textTheme,
+ ),
+ ],
+ const SizedBox(height: 20),
+ Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ Text(
+ context.strings.chooseARecoveryTime,
+ style: textTheme.bodyMuted,
+ ),
+ const SizedBox(height: 12),
+ RecoveryDateSelector(
+ selectedDays: _selectedRecoveryDays,
+ onDaysChanged: (days) {
+ setState(() {
+ _selectedRecoveryDays = days;
+ });
+ },
+ ),
+ ],
+ ),
+ const SizedBox(height: 20),
+ GradientButton(
+ text: context.strings.addTrustedContact,
+ onTap: canAdd ? _onAddContactTap : null,
+ ),
+ const SizedBox(height: 12),
+ Center(
+ child: GestureDetector(
+ onTap: _onVerifyTap,
+ child: Text(
+ context.strings.verifyIDLabel,
+ style: textTheme.bodyBold.copyWith(
+ color: canAdd
+ ? getEnteColorScheme(context).primary700
+ : getEnteColorScheme(context).textMuted,
+ decoration: TextDecoration.underline,
+ decorationColor: canAdd
+ ? getEnteColorScheme(context).primary700
+ : getEnteColorScheme(context).textMuted,
+ ),
),
),
),
- ),
+ ],
),
);
}
- Widget _buildHeader(EnteColorScheme colorScheme, EnteTextTheme textTheme) {
- return Row(
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- children: [
- Text(
- context.strings.addTrustedContact,
- style: textTheme.largeBold,
- ),
- const CloseIconButton(),
- ],
- );
- }
-
Widget _buildEmailInputRow(EnteColorScheme colorScheme) {
return TextFormField(
controller: _textController,
@@ -319,38 +324,9 @@ class _AddContactBottomSheetState extends State<AddContactBottomSheet> {
);
}
- Widget _buildRecoveryTimeSection(EnteTextTheme textTheme) {
- return Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- Text(
- context.strings.chooseARecoveryTime,
- style: textTheme.bodyMuted,
- ),
- const SizedBox(height: 12),
- RecoveryDateSelector(
- selectedDays: _selectedRecoveryDays,
- onDaysChanged: (days) {
- setState(() {
- _selectedRecoveryDays = days;
- });
- },
- ),
- ],
- );
- }
-
- Widget _buildAddContactButton(EnteTextTheme textTheme) {
- final bool canAdd = selectedEmail.isNotEmpty || _emailIsValid;
- return GradientButton(
- text: context.strings.addTrustedContact,
- onTap: canAdd ? _onAddContactTap : null,
- );
- }
-
Future<void> _onAddContactTap() async {
final emailToAdd = selectedEmail.isNotEmpty ? selectedEmail : _email;
- final confirmed = await _showAddContactConfirmationDialog(
+ final confirmed = await _showAddContactConfirmationSheet(
emailToAdd,
_selectedRecoveryDays,
);
@@ -385,99 +361,27 @@ class _AddContactBottomSheetState extends State<AddContactBottomSheet> {
}
}
- Future<bool?> _showAddContactConfirmationDialog(
+ Future<bool?> _showAddContactConfirmationSheet(
String email,
int recoveryDays,
) {
final colorScheme = getEnteColorScheme(context);
- final textTheme = getEnteTextTheme(context);
- return showModalBottomSheet<bool>(
- context: context,
- isScrollControlled: true,
- isDismissible: true,
- builder: (context) {
- return Container(
- decoration: BoxDecoration(
- color: colorScheme.backgroundElevated2,
- borderRadius: const BorderRadius.only(
- topLeft: Radius.circular(24),
- topRight: Radius.circular(24),
- ),
- ),
- child: SafeArea(
- child: Padding(
- padding: const EdgeInsets.all(16),
- child: Column(
- mainAxisSize: MainAxisSize.min,
- crossAxisAlignment: CrossAxisAlignment.center,
- children: [
- const SizedBox(
- width: double.infinity,
- child: Row(
- mainAxisAlignment: MainAxisAlignment.end,
- children: [
- CloseIconButton(),
- ],
- ),
- ),
- const SizedBox(height: 8),
- Center(
- child: Image.asset("assets/warning-blue.png"),
- ),
- const SizedBox(height: 24),
- Text(
- context.strings.warning,
- style: textTheme.h3Bold,
- ),
- const SizedBox(height: 12),
- Text(
- context.strings.confirmAddingTrustedContact(
- email,
- recoveryDays,
- ),
- textAlign: TextAlign.center,
- style: textTheme.body.copyWith(
- color: colorScheme.textMuted,
- ),
- ),
- const SizedBox(height: 32),
- SizedBox(
- width: double.infinity,
- child: GradientButton(
- onTap: () => Navigator.of(context).pop(true),
- text: context.strings.proceed,
- backgroundColor: colorScheme.warning400,
- ),
- ),
- ],
- ),
- ),
- ),
- );
- },
- );
- }
-
- Widget _buildVerifyLink(EnteTextTheme textTheme) {
- final bool canAdd = selectedEmail.isNotEmpty || _emailIsValid;
-
- return Center(
- child: GestureDetector(
- onTap: _onVerifyTap,
- child: Text(
- context.strings.verifyIDLabel,
- style: textTheme.bodyBold.copyWith(
- color: canAdd
- ? getEnteColorScheme(context).primary700
- : getEnteColorScheme(context).textMuted,
- decoration: TextDecoration.underline,
- decorationColor: canAdd
- ? getEnteColorScheme(context).primary700
- : getEnteColorScheme(context).textMuted,
- ),
- ),
+ return showAlertBottomSheet<bool>(
+ context,
+ title: context.strings.warning,
+ message: context.strings.confirmAddingTrustedContact(
+ email,
+ recoveryDays,
),
+ assetPath: "assets/warning-blue.png",
+ buttons: [
+ GradientButton(
+ onTap: () => Navigator.of(context).pop(true),
+ text: context.strings.proceed,
+ backgroundColor: colorScheme.warning400,
+ ),
+ ],
);
}