How to return icon to TextFormField's validator as string
357
First of all define a variable
bool isEmailValid = true;
Now in the InputDecoreation
prefixIcon = isEmailValid ?? null : SvgIcon()
Replace SVGIcon with Some code which will render the icon
Edit:
Also in the validate function
validate:(v){
if(emailIsNotValidCondition){
setState(){isEmailValid=false}
}
}
Author by
doğan kısa
Updated on January 04, 2023Comments
-
doğan kısa over 1 year
im trying to trigger an error with textformfield validate.i can trigger only a text but i need to add a icon too. its working;
validate: (value) { if (value == null || value.isEmpty) { return 'Please enter your email address'; } else if (isValid == false) { return "❗Please enter a valid email address."; }
but i need do add a svg icon. when i return svg icon and text in a row, app is crashing. how can i return a svg and text in here? thanks all
-
doğan kısa about 2 yearsi have to add this svg icon instead of exclamation point(in the code exemple)
-
doğan kısa about 2 yearsicon shouldnt be in text field, like prefixIcon
-
Farhan Syedain about 2 yearsReplace SvgIcon with your svg icon.