using if statements and icons in flutter

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



using if statements and icons in flutter



i have an if statement and I want to set two conditions inside it as the following code shows:


if (subtitle !="you are currently not signed in" && Icon==Icons.bookmark_border) .....



but I cant do so since it is giving the following error "equality operator == invocation with reference of unrelated types".



Any idea about how to implement this





what is the value of "Icon" var ?
– diegoveloper
Aug 10 at 16:22





Use IconData instead of Icon. Also what is your variable here that you are trying to compare to Icons.bookmark_border?
– Vikas Pandey
Aug 10 at 16:22






i have future builder that returns 2 widgets ,one is bookmark and other is bookmark border icon, i want to set them into variables and put them into if statement.@VikasPandey
– serjo macken
Aug 10 at 21:26




2 Answers
2



In your case Icon is a type.

You cannot compare a type with an object (Icons.bookmark_border is an object of type IconData).


Icon


Icons.bookmark_border


IconData



Maybe you have a typo in your code and wanted to write lower case "icon".

If not, you probably firstly need to fetch your icon.





yes my icon is in a widget ubove this if statement that returns icons, ineed to ftch it, how can i do this.
– serjo macken
Aug 10 at 21:17



Can you please post the Code where you get your Icon that you want to compare?

Like @creativecreatorormaybenot already said you're trying to compare the Icon type with an object of type IconData, you need to compare an iconData object to another iconData object.



Note:
IconData is just the class for one of the icons in Icons.[something]

Icon is a flutter widget, used to display Icons for the user.


Icons.[something]



So


final IconData icon = Icons.ac_unit; //icon is just the name of the Object. IconData would be the type.

//replace icon with the object (of type IconData) you get from your FutureBuilder
if (subtitle !="you are currently not signed in" && icon==Icons.bookmark_border) .....



should work.





Thanks I will try it out.
– serjo macken
Aug 12 at 16:30






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

How to determine optimal route across keyboard