I am working with flutter disabled text field, its work with alert which provide some choices when clicked.
I validate the value using stream like code below in my case:
final validateGender =
StreamTransformer<String, String>.fromHandlers(handleData: (text, sink) {
if (text.isEmpty ||
text.toLowerCase() != 'male' ||
text.toLowerCase() != 'female') {
sink.addError('* Not choose yet');
} else {
sink.add(text);
}
});
and i make a textfield that can show errorText:
StreamBuilder<String>(
stream: stream,
builder: (context, snapshot) {
return TextField(
enabled: enable,
autofocus: isAutoFocus ?? false,
onTap: onTap,
controller: controller,
onChanged: onChanged,
keyboardType: TextInputType.text,
decoration: InputDecoration(
errorText: snapshot.error,
border: OutlineInputBorder(
borderRadius: BorderRadius.all(Radius.circular(10.0)),
),
disabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.all(Radius.circular(10.0)),
borderSide: BorderSide(color: Colors.gray, width: 1.0),
),
errorBorder: OutlineInputBorder(
borderRadius: BorderRadius.all(Radius.circular(10.0)),
borderSide: BorderSide(color: Colors.red, width: 1.0),
),
filled: true,
hintStyle: TextStyle(color: Colors.grey),
hintText: hintText,
fillColor: Colors.white,
),
);
},
),
it supposed to be show "* Not choose yet" below of the text field, but it show red border only. the result below:
my stream using rxdart, i think i don't need to put it here,
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…