inputText static method

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

Implementation

static Future<String?> inputText({
  String? value,
  required String title,
  String? label,
  String? message,
  String? tips,
  RegExp? allowExp,
  RegExp? denyExp,
  TextInputType? keyboardType,
  List<TextInputFormatter>? inputFormaters,
  TextValidator? validator,
  int? maxLines = 1,
  int minLength = 1,
  int maxLength = 255,
  bool allowEmpty = false,
  bool trim = false,
  bool? password,
  DialogWidth? width,
}) {
  TextValidator lenValid = Valids.length(minLength, maxLength, allowEmpty: allowEmpty, trim: trim);
  TextValidator vs = validator == null ? lenValid : Valids.list([validator, lenValid]);
  return showDialogX((b) {
    if (width != null) b.dialogWidth = width;
    b.title(title.text());
    bool multiLines = maxLines != null && maxLines > 1;
    ListWidget ls = [];
    HareEdit edit = HareEdit(
        value: value?.toString() ?? "",
        helpText: tips,
        label: label,
        allowExp: allowExp,
        denyExp: denyExp,
        keyboardType: keyboardType,
        inputFormaters: inputFormaters,
        validator: vs,
        maxLength: maxLength,
        maxLines: maxLines,
        password: password,
        autofucus: true,
        noClear: multiLines,
        border: !multiLines ? null : OutlineInputBorder(),
        onSubmit: (s) {
          b.setResult(s);
          b.clickOK();
        });
    ls << edit;
    if (multiLines) {
      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);
  });
}