Skip to content

armgit / ente

Public Imported from GitHub
0

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

Implement view/edit mode for info pages with consistent styling

vishnukvmd5854f2221049
diff --git a/mobile/apps/locker/lib/ui/components/form_text_input_widget.dart b/mobile/apps/locker/lib/ui/components/form_text_input_widget.dart
index 7074d305ba..344ed43079 100644
--- a/mobile/apps/locker/lib/ui/components/form_text_input_widget.dart
+++ b/mobile/apps/locker/lib/ui/components/form_text_input_widget.dart
@@ -130,20 +130,17 @@ class _FormTextInputWidgetState extends State<FormTextInputWidget> {
textTheme.body.copyWith(color: colorScheme.textMuted),
filled: true,
fillColor: colorScheme.fillFaint,
- contentPadding: const EdgeInsets.fromLTRB(16, 16, 16, 16),
+ contentPadding: const EdgeInsets.fromLTRB(12, 12, 12, 12),
border: const UnderlineInputBorder(
borderSide: BorderSide.none,
),
enabledBorder: OutlineInputBorder(
- borderSide: BorderSide(
- color: colorScheme.strokeFaint,
- width: 1,
- ),
+ borderSide: BorderSide.none,
borderRadius: BorderRadius.circular(8),
),
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(
- color: colorScheme.primary500,
+ color: colorScheme.strokeFaint,
width: 2,
),
borderRadius: BorderRadius.circular(8),
diff --git a/mobile/apps/locker/lib/ui/components/item_list_view.dart b/mobile/apps/locker/lib/ui/components/item_list_view.dart
index c3ab32b96a..9d6430faea 100644
--- a/mobile/apps/locker/lib/ui/components/item_list_view.dart
+++ b/mobile/apps/locker/lib/ui/components/item_list_view.dart
@@ -19,6 +19,7 @@ import 'package:locker/services/files/sync/models/file.dart';
import 'package:locker/services/info_file_service.dart';
import 'package:locker/ui/components/file_edit_dialog.dart';
import 'package:locker/ui/pages/account_credentials_page.dart';
+import 'package:locker/ui/pages/base_info_page.dart';
import 'package:locker/ui/pages/collection_page.dart';
import 'package:locker/ui/pages/emergency_contact_page.dart';
import 'package:locker/ui/pages/personal_note_page.dart';
@@ -1120,27 +1121,31 @@ class FileRowWidget extends StatelessWidget {
return;
}
- // Navigate to the appropriate page based on info type
+ // Navigate to the appropriate page based on info type in view mode
Widget page;
switch (infoItem.type) {
case InfoType.note:
page = PersonalNotePage(
existingData: infoItem.data as PersonalNoteData,
+ mode: InfoPageMode.view,
);
break;
case InfoType.accountCredential:
page = AccountCredentialsPage(
existingData: infoItem.data as AccountCredentialData,
+ mode: InfoPageMode.view,
);
break;
case InfoType.physicalRecord:
page = PhysicalRecordsPage(
existingData: infoItem.data as PhysicalRecordData,
+ mode: InfoPageMode.view,
);
break;
case InfoType.emergencyContact:
page = EmergencyContactPage(
existingData: infoItem.data as EmergencyContactData,
+ mode: InfoPageMode.view,
);
break;
}
diff --git a/mobile/apps/locker/lib/ui/pages/account_credentials_page.dart b/mobile/apps/locker/lib/ui/pages/account_credentials_page.dart
index 19904d8726..a5170c9d00 100644
--- a/mobile/apps/locker/lib/ui/pages/account_credentials_page.dart
+++ b/mobile/apps/locker/lib/ui/pages/account_credentials_page.dart
@@ -5,7 +5,11 @@ import 'package:locker/ui/components/form_text_input_widget.dart';
import 'package:locker/ui/pages/base_info_page.dart';
class AccountCredentialsPage extends BaseInfoPage<AccountCredentialData> {
- const AccountCredentialsPage({super.key, super.existingData});
+ const AccountCredentialsPage({
+ super.key,
+ super.existingData,
+ super.mode = InfoPageMode.edit,
+ });
@override
State<AccountCredentialsPage> createState() => _AccountCredentialsPageState();
@@ -81,7 +85,6 @@ class _AccountCredentialsPageState
@override
List<Widget> buildFormFields() {
return [
- const SizedBox(height: 20),
FormTextInputWidget(
labelText: context.l10n.credentialName,
hintText: context.l10n.credentialNameHint,
@@ -138,4 +141,33 @@ class _AccountCredentialsPageState
const SizedBox(height: 24),
];
}
+
+ @override
+ List<Widget> buildViewFields() {
+ return [
+ buildViewField(
+ label: context.l10n.credentialName,
+ value: _nameController.text,
+ ),
+ const SizedBox(height: 16),
+ buildViewField(
+ label: context.l10n.username,
+ value: _usernameController.text,
+ ),
+ const SizedBox(height: 16),
+ buildViewField(
+ label: context.l10n.password,
+ value: _passwordController.text,
+ isSecret: true,
+ ),
+ if (_notesController.text.isNotEmpty) ...[
+ const SizedBox(height: 16),
+ buildViewField(
+ label: context.l10n.credentialNotes,
+ value: _notesController.text,
+ maxLines: 3,
+ ),
+ ],
+ ];
+ }
}
diff --git a/mobile/apps/locker/lib/ui/pages/base_info_page.dart b/mobile/apps/locker/lib/ui/pages/base_info_page.dart
index ecff4d1d06..785ad63a91 100644
--- a/mobile/apps/locker/lib/ui/pages/base_info_page.dart
+++ b/mobile/apps/locker/lib/ui/pages/base_info_page.dart
@@ -1,6 +1,9 @@
+import 'dart:io';
+
import 'package:ente_ui/components/buttons/gradient_button.dart';
import 'package:ente_ui/theme/ente_theme.dart';
import 'package:flutter/material.dart';
+import 'package:flutter/services.dart';
import 'package:locker/l10n/l10n.dart';
import 'package:locker/models/info/info_item.dart';
import 'package:locker/services/collections/collections_service.dart';
@@ -9,16 +12,24 @@ import 'package:locker/services/info_file_service.dart';
import 'package:locker/ui/components/collection_selection_widget.dart';
import 'package:locker/ui/pages/home_page.dart';
+enum InfoPageMode { view, edit }
+
abstract class BaseInfoPage<T extends InfoData> extends StatefulWidget {
final T? existingData;
+ final InfoPageMode mode;
- const BaseInfoPage({super.key, this.existingData});
+ const BaseInfoPage({
+ super.key,
+ this.existingData,
+ this.mode = InfoPageMode.edit,
+ });
}
abstract class BaseInfoPageState<T extends InfoData, W extends BaseInfoPage<T>>
extends State<W> {
final _formKey = GlobalKey<FormState>();
bool _isLoading = false;
+ late InfoPageMode _currentMode;
// Collection selection state
List<Collection> _availableCollections = [];
@@ -30,11 +41,13 @@ abstract class BaseInfoPageState<T extends InfoData, W extends BaseInfoPage<T>>
InfoType get infoType;
T createInfoData();
List<Widget> buildFormFields();
+ List<Widget> buildViewFields();
bool validateForm();
@override
void initState() {
super.initState();
+ _currentMode = widget.mode;
_loadCollections();
loadExistingData();
}
@@ -166,51 +179,176 @@ abstract class BaseInfoPageState<T extends InfoData, W extends BaseInfoPage<T>>
}
}
- @override
- Widget build(BuildContext context) {
- return Scaffold(
- appBar: AppBar(
- title: Text(pageTitle),
+ void _toggleMode() {
+ setState(() {
+ _currentMode = _currentMode == InfoPageMode.view
+ ? InfoPageMode.edit
+ : InfoPageMode.view;
+ });
+ }
+
+ void _copyToClipboard(String text, String fieldName) {
+ Clipboard.setData(ClipboardData(text: text));
+ ScaffoldMessenger.of(context).showSnackBar(
+ SnackBar(
+ content: Text('$fieldName copied to clipboard'),
+ duration: const Duration(seconds: 2),
+ backgroundColor: Colors.green,
),
- body: Container(
- padding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 20.0),
- child: Form(
- key: _formKey,
- child: Column(
- children: [
- Expanded(
- child: SingleChildScrollView(
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- // Form fields implemented by subclass
- ...buildFormFields(),
- const SizedBox(height: 24),
- // Collection selection
- Text(
- 'Select collections',
- style: getEnteTextTheme(context).body,
- ),
- const SizedBox(height: 12),
- CollectionSelectionWidget(
- collections: _availableCollections,
- selectedCollectionIds: _selectedCollectionIds,
- onToggleCollection: _onToggleCollection,
- onCollectionsUpdated: _onCollectionsUpdated,
+ );
+ }
+
+ Widget buildViewField({
+ required String label,
+ required String value,
+ bool isSecret = false,
+ int? maxLines,
+ }) {
+ final colorScheme = getEnteColorScheme(context);
+ final textTheme = getEnteTextTheme(context);
+
+ return Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ if (label.isNotEmpty) ...[
+ Text(label), // Use default style to match FormTextInputWidget
+ const SizedBox(height: 4),
+ ],
+ ClipRRect(
+ borderRadius: const BorderRadius.all(Radius.circular(8)),
+ child: Material(
+ color: Colors.transparent,
+ child: Stack(
+ children: [
+ Container(
+ width: double.infinity,
+ padding: const EdgeInsets.fromLTRB(12, 12, 12, 12),
+ decoration: BoxDecoration(
+ color: colorScheme.fillFaint,
+ borderRadius: BorderRadius.circular(8),
+ ),
+ child: Text(
+ isSecret ? 'β€’β€’β€’β€’β€’β€’β€’β€’' : value,
+ style: textTheme.body,
+ maxLines: maxLines,
+ overflow: maxLines != null ? TextOverflow.ellipsis : null,
+ ),
+ ),
+ Positioned(
+ top: 8,
+ right: 8,
+ child: InkWell(
+ onTap: () => _copyToClipboard(value, label),
+ borderRadius: BorderRadius.circular(4),
+ child: Container(
+ padding: const EdgeInsets.all(4),
+ child: Icon(
+ Icons.copy,
+ size: 16,
+ color: colorScheme.textMuted,
),
- ],
+ ),
),
),
- ),
- const SizedBox(height: 20),
- SizedBox(
- width: double.infinity,
- child: GradientButton(
- onTap: _isLoading ? null : _saveRecord,
- text: _isLoading ? context.l10n.pleaseWait : submitButtonText,
+ ],
+ ),
+ ),
+ ),
+ ],
+ );
+ }
+
+ @override
+ Widget build(BuildContext context) {
+ final isViewMode = _currentMode == InfoPageMode.view;
+ final isEditMode = _currentMode == InfoPageMode.edit;
+
+ return PopScope(
+ canPop: isViewMode,
+ onPopInvokedWithResult: (didPop, result) {
+ if (!didPop && isEditMode) {
+ // If in edit mode and trying to go back, switch to view mode instead
+ _toggleMode();
+ }
+ },
+ child: Scaffold(
+ appBar: AppBar(
+ title: Text(pageTitle),
+ leading: isEditMode && widget.existingData != null
+ ? IconButton(
+ icon: Icon(
+ Platform.isIOS ? Icons.arrow_back_ios : Icons.arrow_back,
+ ),
+ onPressed: _toggleMode,
+ tooltip: 'Back to view',
+ )
+ : IconButton(
+ icon: Icon(
+ Platform.isIOS ? Icons.arrow_back_ios : Icons.arrow_back,
+ ),
+ onPressed: () => Navigator.of(context).pop(),
+ tooltip: 'Back',
),
+ automaticallyImplyLeading: false,
+ actions: [
+ if (isViewMode && widget.existingData != null)
+ IconButton(
+ icon: const Icon(Icons.edit),
+ onPressed: _toggleMode,
+ tooltip: 'Edit',
),
- ],
+ ],
+ ),
+ body: Container(
+ padding: const EdgeInsets.symmetric(horizontal: 16.0),
+ child: Form(
+ key: _formKey,
+ child: Column(
+ children: [
+ Expanded(
+ child: SingleChildScrollView(
+ child: Padding(
+ padding: const EdgeInsets.only(top: 20),
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ // Fields based on current mode
+ if (isViewMode)
+ ...buildViewFields()
+ else
+ ...buildFormFields(),
+
+ // Collection selection only in edit mode
+ if (isEditMode) ...[
+ const SizedBox(height: 24),
+ CollectionSelectionWidget(
+ collections: _availableCollections,
+ selectedCollectionIds: _selectedCollectionIds,
+ onToggleCollection: _onToggleCollection,
+ onCollectionsUpdated: _onCollectionsUpdated,
+ ),
+ ],
+ ],
+ ),
+ ),
+ ),
+ ),
+
+ // Save button only in edit mode
+ if (isEditMode) ...[
+ const SizedBox(height: 20),
+ SizedBox(
+ width: double.infinity,
+ child: GradientButton(
+ onTap: _isLoading ? null : _saveRecord,
+ text: _isLoading
+ ? context.l10n.pleaseWait
+ : submitButtonText,
+ ),
+ ),
+ ],
+ ],
+ ),
),
),
),
diff --git a/mobile/apps/locker/lib/ui/pages/emergency_contact_page.dart b/mobile/apps/locker/lib/ui/pages/emergency_contact_page.dart
index f831838896..4c0a96f1f5 100644
--- a/mobile/apps/locker/lib/ui/pages/emergency_contact_page.dart
+++ b/mobile/apps/locker/lib/ui/pages/emergency_contact_page.dart
@@ -5,7 +5,11 @@ import 'package:locker/ui/components/form_text_input_widget.dart';
import 'package:locker/ui/pages/base_info_page.dart';
class EmergencyContactPage extends BaseInfoPage<EmergencyContactData> {
- const EmergencyContactPage({super.key, super.existingData});
+ const EmergencyContactPage({
+ super.key,
+ super.existingData,
+ super.mode = InfoPageMode.edit,
+ });
@override
State<EmergencyContactPage> createState() => _EmergencyContactPageState();
@@ -69,7 +73,6 @@ class _EmergencyContactPageState
@override
List<Widget> buildFormFields() {
return [
- const SizedBox(height: 20),
FormTextInputWidget(
labelText: context.l10n.contactName,
hintText: context.l10n.contactNameHint,
@@ -103,4 +106,27 @@ class _EmergencyContactPageState
const SizedBox(height: 24),
];
}
+
+ @override
+ List<Widget> buildViewFields() {
+ return [
+ buildViewField(
+ label: context.l10n.contactName,
+ value: _nameController.text,
+ ),
+ const SizedBox(height: 16),
+ buildViewField(
+ label: context.l10n.contactDetails,
+ value: _contactDetailsController.text,
+ ),
+ if (_notesController.text.isNotEmpty) ...[
+ const SizedBox(height: 16),
+ buildViewField(
+ label: context.l10n.contactNotes,
+ value: _notesController.text,
+ maxLines: 3,
+ ),
+ ],
+ ];
+ }
}
diff --git a/mobile/apps/locker/lib/ui/pages/personal_note_page.dart b/mobile/apps/locker/lib/ui/pages/personal_note_page.dart
index 155fb172f4..98b1a105b8 100644
--- a/mobile/apps/locker/lib/ui/pages/personal_note_page.dart
+++ b/mobile/apps/locker/lib/ui/pages/personal_note_page.dart
@@ -5,7 +5,11 @@ import 'package:locker/ui/components/form_text_input_widget.dart';
import 'package:locker/ui/pages/base_info_page.dart';
class PersonalNotePage extends BaseInfoPage<PersonalNoteData> {
- const PersonalNotePage({super.key, super.existingData});
+ const PersonalNotePage({
+ super.key,
+ super.existingData,
+ super.mode = InfoPageMode.edit,
+ });
@override
State<PersonalNotePage> createState() => _PersonalNotePageState();
@@ -62,7 +66,6 @@ class _PersonalNotePageState
@override
List<Widget> buildFormFields() {
return [
- const SizedBox(height: 20),
FormTextInputWidget(
labelText: context.l10n.noteName,
hintText: context.l10n.noteNameHint,
@@ -90,4 +93,20 @@ class _PersonalNotePageState
const SizedBox(height: 24),
];
}
+
+ @override
+ List<Widget> buildViewFields() {
+ return [
+ buildViewField(
+ label: context.l10n.noteName,
+ value: _nameController.text,
+ ),
+ const SizedBox(height: 16),
+ buildViewField(
+ label: context.l10n.noteContent,
+ value: _contentController.text,
+ maxLines: 5,
+ ),
+ ];
+ }
}
diff --git a/mobile/apps/locker/lib/ui/pages/physical_records_page.dart b/mobile/apps/locker/lib/ui/pages/physical_records_page.dart
index c9f0e428c5..92159a303a 100644
--- a/mobile/apps/locker/lib/ui/pages/physical_records_page.dart
+++ b/mobile/apps/locker/lib/ui/pages/physical_records_page.dart
@@ -5,7 +5,11 @@ import 'package:locker/ui/components/form_text_input_widget.dart';
import 'package:locker/ui/pages/base_info_page.dart';
class PhysicalRecordsPage extends BaseInfoPage<PhysicalRecordData> {
- const PhysicalRecordsPage({super.key, super.existingData});
+ const PhysicalRecordsPage({
+ super.key,
+ super.existingData,
+ super.mode = InfoPageMode.edit,
+ });
@override
State<PhysicalRecordsPage> createState() => _PhysicalRecordsPageState();
@@ -68,7 +72,6 @@ class _PhysicalRecordsPageState
@override
List<Widget> buildFormFields() {
return [
- const SizedBox(height: 20),
FormTextInputWidget(
labelText: context.l10n.recordName,
hintText: context.l10n.recordNameHint,
@@ -102,4 +105,27 @@ class _PhysicalRecordsPageState
const SizedBox(height: 24),
];
}
+
+ @override
+ List<Widget> buildViewFields() {
+ return [
+ buildViewField(
+ label: context.l10n.recordName,
+ value: _nameController.text,
+ ),
+ const SizedBox(height: 16),
+ buildViewField(
+ label: context.l10n.recordLocation,
+ value: _locationController.text,
+ ),
+ if (_notesController.text.isNotEmpty) ...[
+ const SizedBox(height: 16),
+ buildViewField(
+ label: context.l10n.recordNotes,
+ value: _notesController.text,
+ maxLines: 3,
+ ),
+ ],
+ ];
+ }
}