redesign for settings page
This commit is contained in:
@@ -2,6 +2,7 @@ import 'package:flutter/widgets.dart';
|
||||
|
||||
import 'package:fancy_password_field/fancy_password_field.dart';
|
||||
|
||||
import 'package:pweb/models/state/control_state.dart';
|
||||
import 'package:pweb/widgets/password/hint/error.dart';
|
||||
import 'package:pweb/widgets/password/hint/short.dart';
|
||||
import 'package:pweb/widgets/password/password.dart';
|
||||
@@ -12,7 +13,7 @@ import 'package:pweb/generated/i18n/app_localizations.dart';
|
||||
class PasswordVeirificationRule extends ValidationRule {
|
||||
final String ruleName;
|
||||
final TextEditingController externalPasswordController;
|
||||
|
||||
|
||||
PasswordVeirificationRule({
|
||||
required this.ruleName,
|
||||
required this.externalPasswordController,
|
||||
@@ -32,12 +33,16 @@ class VerifyPasswordField extends StatefulWidget {
|
||||
final ValueChanged<bool>? onValid;
|
||||
final TextEditingController controller;
|
||||
final TextEditingController externalPasswordController;
|
||||
final String? labelText;
|
||||
final ControlState state;
|
||||
|
||||
const VerifyPasswordField({
|
||||
super.key,
|
||||
super.key,
|
||||
this.onValid,
|
||||
required this.controller,
|
||||
required this.externalPasswordController,
|
||||
this.labelText,
|
||||
this.state = ControlState.enabled,
|
||||
});
|
||||
|
||||
@override
|
||||
@@ -55,7 +60,8 @@ class _VerifyPasswordFieldState extends State<VerifyPasswordField> {
|
||||
}
|
||||
|
||||
void _validatePassword() {
|
||||
final isValid = widget.controller.text == widget.externalPasswordController.text;
|
||||
final isValid =
|
||||
widget.controller.text == widget.externalPasswordController.text;
|
||||
|
||||
// Only call onValid if the validity state has changed to prevent infinite loops
|
||||
if (isValid != _isCurrentlyValid) {
|
||||
@@ -68,21 +74,31 @@ class _VerifyPasswordFieldState extends State<VerifyPasswordField> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final isEnabled = widget.state == ControlState.enabled;
|
||||
final rule = PasswordVeirificationRule(
|
||||
ruleName: AppLocalizations.of(context)!.passwordsDoNotMatch,
|
||||
externalPasswordController: widget.externalPasswordController,
|
||||
);
|
||||
|
||||
return defaulRulesPasswordField(
|
||||
context,
|
||||
controller: widget.controller,
|
||||
key: widget.key,
|
||||
labelText: AppLocalizations.of(context)!.confirmPassword,
|
||||
additionalRules: { rule },
|
||||
validationRuleBuilder: (rules, value) => rule.validate(value)
|
||||
? shortValidation(context, rules, value)
|
||||
: PasswordValidationErrorLabel(labelText: AppLocalizations.of(context)!.passwordsDoNotMatch),
|
||||
onValid: widget.onValid,
|
||||
return IgnorePointer(
|
||||
ignoring: !isEnabled,
|
||||
child: Opacity(
|
||||
opacity: isEnabled ? 1 : 0.6,
|
||||
child: defaulRulesPasswordField(
|
||||
context,
|
||||
controller: widget.controller,
|
||||
key: widget.key,
|
||||
labelText:
|
||||
widget.labelText ?? AppLocalizations.of(context)!.confirmPassword,
|
||||
additionalRules: {rule},
|
||||
validationRuleBuilder: (rules, value) => rule.validate(value)
|
||||
? shortValidation(context, rules, value)
|
||||
: PasswordValidationErrorLabel(
|
||||
labelText: AppLocalizations.of(context)!.passwordsDoNotMatch,
|
||||
),
|
||||
onValid: widget.onValid,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user