바로 코드
class _DiaryFilterInputState extends State<DiaryFilterInput> {
bool isValid = false;
final GlobalKey<FormState> _formKey = GlobalKey<FormState>();
String? _validate(String? value) {
if (value == null || value.isEmpty) {
return '';
}
final tags = value.split(':');
if (tags.length != 2 || tags[1].isEmpty) {
return '태그 형식이 잘못 됐습니다.';
}
return null;
}
@override
Widget build(BuildContext context) {
return Form(
key: _formKey,
child: TextFormField(
validator: _validate,
onChanged: (String value) {
setState(() {
isValid = _formKey.currentState!.validate();
});
},
controller: textEditingController,
decoration: InputDecoration(
border: const OutlineInputBorder(),
suffixIcon: isValid
? IconButton(
onPressed: () {},
icon: const Icon(Icons.add_circle_rounded),
)
: const Icon(Icons.warning),
),
),
);
}
}