EditPassword function

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