inputText static method

Future<String?> inputText({
  1. String? value,
  2. required String title,
  3. String? label,
  4. String? message,
  5. String? hint,
  6. String? tips,
  7. RegExp? allowExp,
  8. RegExp? denyExp,
  9. TextInputType? keyboardType,
  10. List<TextInputFormatter>? inputFormaters,
  11. TextValidator? validator,
  12. int? maxLines = 1,
  13. int? minLines,
  14. int minLength = 1,
  15. int maxLength = 255,
  16. bool allowEmpty = false,
  17. bool trim = false,
  18. bool? password,
  19. bool clearButton = false,
  20. InputBorder? border,
  21. bool? outlineBorder,
  22. DialogWidth? width,
})

Implementation

static Future<String?> inputText({
  String? value,
  required String title,
  String? label,
  String? message,
  String? hint,
  String? tips,
  RegExp? allowExp,
  RegExp? denyExp,
  TextInputType? keyboardType,
  List<TextInputFormatter>? inputFormaters,
  TextValidator? validator,
  int? maxLines = 1,
  int? minLines,
  int minLength = 1,
  int maxLength = 255,
  bool allowEmpty = false,
  bool trim = false,
  bool? password,
  bool clearButton = false,
  InputBorder? border,
  bool? outlineBorder,
  DialogWidth? width,
}) {
  TextValidator lenValid = LengthValidator(minLength: minLength, maxLength: maxLength, allowEmpty: allowEmpty, trim: trim);
  TextValidator vs = validator == null ? lenValid : ListValidator([validator, lenValid]);
  return showDialogX((b) {
    if (width != null) b.dialogWidth = width;
    b.title(title.text());
    bool multiLines = (maxLines != null && maxLines > 1) || (minLines != null && minLines > 1);
    ListWidget ls = [];
    HareEdit edit = HareEdit(
      value: value?.toString() ?? "",
      hint: hint,
      helpText: tips,
      label: label,
      allowExp: allowExp,
      denyExp: denyExp,
      keyboardType: keyboardType,
      inputFormaters: inputFormaters,
      validator: vs,
      maxLength: maxLength,
      maxLines: maxLines,
      minLines: minLines,
      password: password,
      autofucus: true,
      noClear: multiLines || clearButton,
      border: border ?? (outlineBorder == true || multiLines ? const OutlineInputBorder() : null),
      onSubmit: (s) {
        b.setResult(s);
        b.clickOK();
      },
    );
    ls << edit;
    if (multiLines || clearButton) {
      Widget btn = b.makeAction("清除", () {
        edit.value = "";
      });
      b.actions(ok: true, cancel: true, items: [btn]);
    } else {
      b.actions(ok: true, cancel: true);
    }
    b.okCallback = () {
      if (!edit.validate()) return false;
      String s = trim ? edit.value.trim() : edit.value;
      b.setResult(s);
      return true;
    };
    return b.buildColumn(ls, message: message);
  });
}