简体   繁体   English

在颤抖中使用if语句和图标

[英]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语句,我想在其中设置两个条件,如以下代码所示:

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 关于如何实现这一点的任何想法

In your case Icon is a type . 就您而言, Icon是一种类型
You cannot compare a type with an object ( Icons.bookmark_border is an object of type IconData ). 您不能将类型对象进行比较( Icons.bookmark_border是类型为IconData的对象)。

Maybe you have a typo in your code and wanted to write lower case "icon" . 也许您的代码中有错字,并且想写小写的“ icon”
If not, you probably firstly need to fetch your icon. 如果没有,您可能首先需要获取图标。

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 . 就像@creativecreatoror可能尚未说过的那样,您正在尝试将Icon 类型与IconData 类型的对象进行比较,您需要将iconData 对象与另一个iconData 对象进行比较。

Note: IconData is just the class for one of the icons in Icons.[something] 注意:IconData只是Icons.[something]Icons.[something]之一的类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. 应该管用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM