inputText method
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,
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,
);
}