Skip to content

armgit / ente

Public Imported from GitHub
0

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

[mob][photos] Show password wrong state in TextInputField

ashilknb63bd8951244
diff --git a/mobile/lib/ui/components/text_input_widget.dart b/mobile/lib/ui/components/text_input_widget.dart
index 8edb66ab8f..132af62606 100644
--- a/mobile/lib/ui/components/text_input_widget.dart
+++ b/mobile/lib/ui/components/text_input_widget.dart
@@ -7,6 +7,8 @@ import 'package:photos/ui/common/loading_widget.dart';
import 'package:photos/utils/debouncer.dart';
import 'package:photos/utils/separators_util.dart';
+///To show wrong password state, throw an exception with the message
+///"Incorrect password" in onSubmit.
class TextInputWidget extends StatefulWidget {
final String? label;
final String? message;
@@ -19,7 +21,7 @@ class TextInputWidget extends StatefulWidget {
final double borderRadius;
///TextInputWidget will listen to this notifier and executes onSubmit when
- ///notified.
+ ///notified. Value of this notifier is irrelevant.
final ValueNotifier? submitNotifier;
///TextInputWidget will listen to this notifier and clears and unfocuses the
@@ -87,6 +89,7 @@ class _TextInputWidgetState extends State<TextInputWidget> {
///This is to pass if the TextInputWidget is in a dialog and an error is
///thrown in executing onSubmit by passing it as arg in Navigator.pop()
Exception? _exception;
+ bool _incorrectPassword = false;
@override
void initState() {
@@ -168,7 +171,11 @@ class _TextInputWidgetState extends State<TextInputWidget> {
borderSide: BorderSide.none,
),
focusedBorder: OutlineInputBorder(
- borderSide: BorderSide(color: colorScheme.strokeFaint),
+ borderSide: BorderSide(
+ color: _incorrectPassword
+ ? const Color.fromRGBO(245, 42, 42, 1)
+ : colorScheme.strokeFaint,
+ ),
borderRadius: BorderRadius.circular(8),
),
suffixIcon: Padding(
@@ -263,6 +270,9 @@ class _TextInputWidgetState extends State<TextInputWidget> {
executionState = ExecutionState.error;
_debouncer.cancelDebounce();
_exception = e as Exception;
+ if (e.toString().contains("Incorrect password")) {
+ _surfaceWrongPasswordState();
+ }
if (!widget.popNavAfterSubmission) {
rethrow;
}
@@ -381,6 +391,20 @@ class _TextInputWidgetState extends State<TextInputWidget> {
return formattedValue;
}
+
+ void _surfaceWrongPasswordState() {
+ setState(() {
+ _incorrectPassword = true;
+ HapticFeedback.vibrate();
+ Future.delayed(const Duration(seconds: 1), () {
+ if (mounted) {
+ setState(() {
+ _incorrectPassword = false;
+ });
+ }
+ });
+ });
+ }
}
//todo: Add clear and custom icon for suffic icon
diff --git a/mobile/lib/ui/settings/TEMP/lock_screen_option_confirm_password.dart b/mobile/lib/ui/settings/TEMP/lock_screen_option_confirm_password.dart
index 476eba19d2..9dc51e0746 100644
--- a/mobile/lib/ui/settings/TEMP/lock_screen_option_confirm_password.dart
+++ b/mobile/lib/ui/settings/TEMP/lock_screen_option_confirm_password.dart
@@ -51,8 +51,7 @@ class _LockScreenOptionConfirmPasswordState
Navigator.of(context).pop(true);
return;
}
- await HapticFeedback.vibrate();
- _confirmPasswordController.clear();
+ throw Exception("Incorrect password");
}
@override
@@ -92,8 +91,7 @@ class _LockScreenOptionConfirmPasswordState
buttonText: S.of(context).confirm,
isFormValid: isFormValid,
onPressedFunction: () async {
- await _confirmPasswordMatch();
- FocusScope.of(context).unfocus();
+ _submitNotifier.value = !_submitNotifier.value;
},
);
},
@@ -152,8 +150,11 @@ class _LockScreenOptionConfirmPasswordState
onChange: (p0) {
_isFormValid.value =
_confirmPasswordController.text.isNotEmpty;
- _submitNotifier.value = !_submitNotifier.value;
},
+ onSubmit: (p0) {
+ return _confirmPasswordMatch();
+ },
+ submitNotifier: _submitNotifier,
),
),
],