我正在使用flutter表单生成器,如果名称有效/唯一,我正在尝试从服务器获取一些数据。
我实现了一个额外的FieldValidator:
static FormFieldValidator isUniqueHorseName({
dynamic version,
String errorText = "Horse already exist.",
}) {
return (valueCandidate) {
print(valueCandidate);
Future<bool> isUnique = HorseRepository().isUnique(valueCandidate);
print(isUnique);
return null;
};
}
formbuilder文本字段看起来像:
FormBuilderTextField(
attribute: "name",
decoration: InputDecoration(labelText: "Name"),
validators: [
FormBuilderValidators.required(errorText: "Name is required"),
FormHorseValidators.isUniqueHorseName(errorText: "Horse already exist."),
],
)
当isUnique值为true或false时,如何返回valueCandidate?