inputText method

Future<String?> inputText({
  1. required String title,
  2. String? value,
  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,
})

Implementation

Future<String?> inputText({
  required String title,
  String? value,
  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,
}) {
  TextValidator lenValid = LengthValidator(minLength: minLength, maxLength: maxLength, allowEmpty: allowEmpty, trim: trim);
  TextValidator vs = validator == null ? lenValid : ListValidator([validator, lenValid]);

  GlobalKey<FormState> formKey = GlobalKey();
  return showColumn(
    onActions: (uc) {
      return actionPanel(uc, [
        cancelAction("取消"),
        makeAction("清除", () {
          uc.fireAction("clear");
        }),
        okAction(uc, "确定"),
      ]);
    },
    onContent: (uc) {
      bool multiLines = (maxLines != null && maxLines > 1) || (minLines != null && minLines > 1);
      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) {
          uc.setResult(s);
          if (uc.onValidate()) {
            uc.popResult();
          }
        },
      );
      uc.onValidate = () {
        if (formKey.currentState?.validate() != true) return false;
        if (!edit.validate()) return false;
        String s = trim ? edit.value.trim() : edit.value;
        uc.setResult(s);
        return true;
      };
      uc.onAction("clear", () => edit.clear());
      return Form(key: formKey, child: ColumnMinStretch([if (message != null) messageWidget(message), edit]));
    },
    title: title,
  );
}