EditPassword function
Widget
EditPassword({
- Key? key,
- required ValueListener<
bool> eyeListener, - ValueListener<
String> ? valueListener, - TextEditingController? controller,
- String? initialValue,
- int minLength = 1,
- int maxLength = 128,
- String? label = "密码",
- String? errorText,
- String? hint,
- OnValue<
String> ? onChanged, - OnValue<
String> ? onSubmitted, - List<
TextInputFormatter> ? inputFormatters, - FocusNode? focusNode,
- Color? cursorColor,
- Widget? prefixIcon = const Icon(Icons.lock),
- TextInputAction? textInputAction = TextInputAction.done,
Implementation
Widget EditPassword({
Key? key,
required ValueListener<bool> eyeListener,
ValueListener<String>? valueListener,
TextEditingController? controller,
String? initialValue,
int minLength = 1,
int maxLength = 128,
String? label = "密码",
String? errorText,
String? hint,
OnValue<String>? onChanged,
OnValue<String>? onSubmitted,
List<TextInputFormatter>? inputFormatters,
FocusNode? focusNode,
Color? cursorColor,
Widget? prefixIcon = const Icon(Icons.lock),
TextInputAction? textInputAction = TextInputAction.done,
}) {
TextEditingController c = controller ?? TextEditingController(text: initialValue ?? valueListener?.value);
FocusNode node = focusNode ?? FocusNode();
return TextFormField(
key: key ?? UniqueKey(),
initialValue: null,
controller: c,
cursorColor: cursorColor,
obscureText: eyeListener.value,
maxLength: maxLength,
keyboardType: TextInputType.visiblePassword,
textInputAction: textInputAction,
onChanged: onChanged ?? valueListener?.onChanged,
onFieldSubmitted: onSubmitted ?? valueListener?.onChanged,
validator: LengthValidator(minLength: minLength, maxLength: maxLength, allowEmpty: false),
inputFormatters: inputFormatters,
focusNode: focusNode,
onTapOutside: (e) => node.unfocus(),
decoration: InputDecoration(
prefixIcon: prefixIcon,
labelText: label,
errorText: errorText,
hintText: hint,
counterText: "",
suffixIcon: IconButton(
icon: eyeListener.value ? const Icon(Icons.visibility_off) : const Icon(Icons.visibility),
onPressed: () {
eyeListener.onChanged(!eyeListener.value);
},
),
),
);
}