doğan kısa
doğan kısa

Reputation: 43

How to return icon to TextFormField's validator as string

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

Upvotes: 1

Views: 1111

Answers (1)

Farhan Syedain
Farhan Syedain

Reputation: 528

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

}

Upvotes: 1

Related Questions