EditPassword function

Widget EditPassword({
  1. required ValueListener<bool> eyeListener,
  2. ValueListener<String>? valueListener,
  3. TextEditingController? controller,
  4. String? initialValue,
  5. int minLength = 1,
  6. int maxLength = 128,
  7. String? label = "密码",
  8. String? errorText,
  9. String? hint,
  10. OnValue<String>? onChanged,
  11. OnValue<String>? onSubmitted,
  12. List<TextInputFormatter>? inputFormatters,
  13. FocusNode? focusNode,
  14. Color? cursorColor,
  15. Widget? prefixIcon = const Icon(Icons.lock),
  16. TextInputAction? textInputAction = TextInputAction.done,
})

Implementation

Widget EditPassword({
  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: 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);
        },
      ),
    ),
  );
}