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}
   }

}
Share:
357
doğan kısa
Author by

doğan kısa

Updated on January 04, 2023

Comments

  • doğan kısa
    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
    doğan kısa about 2 years
    i have to add this svg icon instead of exclamation point(in the code exemple)
  • doğan kısa
    doğan kısa about 2 years
    icon shouldnt be in text field, like prefixIcon
  • Farhan Syedain
    Farhan Syedain about 2 years
    Replace SvgIcon with your svg icon.