Skip to content

armgit / ente

Public Imported from GitHub
0

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

[mob][locker] Migrate account credential fields

aman-pilot595cce1e7928
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 7832ffa728..99146f5275 100644
--- a/mobile/apps/locker/lib/ui/pages/account_credentials_page.dart
+++ b/mobile/apps/locker/lib/ui/pages/account_credentials_page.dart
@@ -1,9 +1,7 @@
-import 'package:ente_ui/utils/toast_util.dart';
+import 'package:ente_components/ente_components.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/ui/components/capsule_form_field.dart';
import 'package:locker/ui/pages/base_info_page.dart';
class AccountCredentialsPage extends BaseInfoPage<AccountCredentialData> {
@@ -24,14 +22,10 @@ class _AccountCredentialsPageState
final TextEditingController _usernameController = TextEditingController();
final TextEditingController _passwordController = TextEditingController();
final TextEditingController _notesController = TextEditingController();
- bool _passwordVisible = false;
@override
void initState() {
super.initState();
- _nameController.addListener(_onFieldChanged);
- _usernameController.addListener(_onFieldChanged);
- _passwordController.addListener(_onFieldChanged);
_loadExistingData();
}
@@ -53,9 +47,6 @@ class _AccountCredentialsPageState
@override
void dispose() {
- _nameController.removeListener(_onFieldChanged);
- _usernameController.removeListener(_onFieldChanged);
- _passwordController.removeListener(_onFieldChanged);
_nameController.dispose();
_usernameController.dispose();
_passwordController.dispose();
@@ -98,9 +89,6 @@ class _AccountCredentialsPageState
_passwordController.text.trim().isNotEmpty;
}
- @override
- bool get isSaveEnabled => super.isSaveEnabled && validateForm();
-
@override
AccountCredentialData createInfoData() {
return AccountCredentialData(
@@ -116,69 +104,45 @@ class _AccountCredentialsPageState
@override
List<Widget> buildFormFields() {
return [
- CapsuleFormField(
- labelText: context.l10n.credentialName,
+ TextInputComponent(
+ label: context.l10n.credentialName,
hintText: context.l10n.credentialNameHint,
controller: _nameController,
+ isRequired: true,
textCapitalization: TextCapitalization.sentences,
autofocus: true,
textInputAction: TextInputAction.next,
- validator: (value) {
- if (value == null || value.trim().isEmpty) {
- return context.l10n.pleaseEnterAccountName;
- }
- return null;
- },
+ onChanged: (_) => onFieldChanged(),
),
const SizedBox(height: 24),
- CapsuleFormField(
- labelText: context.l10n.username,
+ TextInputComponent(
+ label: context.l10n.username,
hintText: context.l10n.usernameHint,
controller: _usernameController,
+ isRequired: true,
textInputAction: TextInputAction.next,
- validator: (value) {
- if (value == null || value.trim().isEmpty) {
- return context.l10n.pleaseEnterUsername;
- }
- return null;
- },
+ onChanged: (_) => onFieldChanged(),
),
const SizedBox(height: 24),
- CapsuleFormField(
- labelText: context.l10n.password,
+ TextInputComponent(
+ label: context.l10n.password,
hintText: context.l10n.passwordHint,
controller: _passwordController,
- obscureText: !_passwordVisible,
+ isRequired: true,
+ isPasswordInput: true,
textInputAction: TextInputAction.next,
- trailing: GestureDetector(
- onTap: () {
- setState(() {
- _passwordVisible = !_passwordVisible;
- });
- },
- child: Icon(
- _passwordVisible ? Icons.visibility : Icons.visibility_off,
- semanticLabel: _passwordVisible ? 'hide_password' : 'show_password',
- ),
- ),
- validator: (value) {
- if (value == null || value.trim().isEmpty) {
- return context.l10n.pleaseEnterPassword;
- }
- return null;
- },
+ onChanged: (_) => onFieldChanged(),
),
const SizedBox(height: 24),
- CapsuleFormField(
- labelText: context.l10n.credentialNotes,
+ TextInputComponent(
+ label: context.l10n.credentialNotes,
hintText: context.l10n.credentialNotesHint,
controller: _notesController,
- maxLines: 3,
minLines: 3,
+ maxLines: 12,
textCapitalization: TextCapitalization.sentences,
keyboardType: TextInputType.multiline,
textInputAction: TextInputAction.newline,
- lineHeight: 1.5,
),
];
}
@@ -190,52 +154,26 @@ class _AccountCredentialsPageState
final notesText = _notesController.text;
final fields = <Widget>[
- CapsuleDisplayField(
- labelText: context.l10n.username,
- value: usernameText,
- onCopy: usernameText.trim().isEmpty
- ? null
- : () => _copyValue(usernameText, context.l10n.username),
- ),
+ buildViewField(label: context.l10n.username, value: usernameText),
const SizedBox(height: 24),
- CapsuleDisplayField(
- labelText: context.l10n.password,
+ buildViewField(
+ label: context.l10n.password,
value: passwordText,
isSecret: true,
- onCopy: passwordText.trim().isEmpty
- ? null
- : () => _copyValue(passwordText, context.l10n.password),
),
];
if (notesText.trim().isNotEmpty) {
fields.addAll([
const SizedBox(height: 24),
- CapsuleDisplayField(
- labelText: context.l10n.credentialNotes,
+ buildViewField(
+ label: context.l10n.credentialNotes,
value: notesText,
maxLines: 6,
- lineHeight: 1.5,
- onCopy: () => _copyValue(notesText, context.l10n.credentialNotes),
),
]);
}
return fields;
}
-
- void _onFieldChanged() {
- if (mounted) {
- setState(() {});
- }
- }
-
- void _copyValue(String value, String label) {
- if (value.trim().isEmpty) {
- return;
- }
- Clipboard.setData(ClipboardData(text: value));
- if (!mounted) return;
- showToast(context, context.l10n.copiedToClipboard(label));
- }
}