editPassword method
Widget
editPassword({
- Key? key,
- required String name,
- required VoidCallback onUpdateState,
- String? initialValue,
- int minLength = 1,
- int maxLength = 128,
- String? label = "密码",
- String? errorText,
- String? hint,
- bool allowEmpty = false,
- TextValidator? validator,
- OnValue<
String> ? onChanged, - OnValue<
String> ? onSubmitted, - List<
TextInputFormatter> ? inputFormatters, - Color? cursorColor,
- InputBorder? border,
- Widget? prefixIcon = const Icon(Icons.lock),
- TextInputAction? textInputAction = TextInputAction.done,
Implementation
Widget editPassword({
Key? key,
required String name,
required VoidCallback onUpdateState,
String? initialValue,
int minLength = 1,
int maxLength = 128,
String? label = "密码",
String? errorText,
String? hint,
bool allowEmpty = false,
TextValidator? validator,
OnValue<String>? onChanged,
OnValue<String>? onSubmitted,
List<TextInputFormatter>? inputFormatters,
Color? cursorColor,
InputBorder? border,
Widget? prefixIcon = const Icon(Icons.lock),
TextInputAction? textInputAction = TextInputAction.done,
}) {
_nameControllerMap[name] ??= TextEditingController(text: initialValue);
_focusMap[name] ??= FocusNode();
_eyeMap[name] ??= true;
var lv = LengthValidator(minLength: minLength, maxLength: maxLength, allowEmpty: allowEmpty);
TextValidator tv = validator == null ? lv : ListValidator([validator, lv]);
return TextFormField(
key: key ?? UniqueKey(),
initialValue: null,
controller: _nameControllerMap[name],
cursorColor: cursorColor,
obscureText: _eyeMap[name]!,
maxLength: maxLength,
keyboardType: TextInputType.visiblePassword,
textInputAction: textInputAction,
onChanged: onChanged,
onFieldSubmitted: onSubmitted,
validator: tv,
inputFormatters: inputFormatters,
focusNode: _focusMap[name],
onTapOutside: (e) => _focusMap[name]?.unfocus(),
decoration: InputDecoration(
prefixIcon: prefixIcon,
labelText: label,
errorText: errorText,
hintText: hint,
counterText: "",
border: border,
suffixIcon: IconButton(
icon: _eyeMap[name]! ? const Icon(Icons.visibility_off) : const Icon(Icons.visibility),
onPressed: () {
_eyeMap[name] = !_eyeMap[name]!;
onUpdateState();
},
),
),
);
}