using if statements and icons in flutter
2,546
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.
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.
Author by
serjo macken
Updated on December 06, 2022Comments
-
serjo macken over 1 year
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
-
diegoveloper over 5 yearswhat is the value of "Icon" var ?
-
Vikas over 5 yearsUse IconData instead of Icon. Also what is your variable here that you are trying to compare to Icons.bookmark_border?
-
serjo macken over 5 yearsi 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 over 5 yearsThanks I will try it out.