如果条件为true,则动态添加图标



只有当条件为True时,我才试图在我的应用程序中添加一个图标,而且我希望它能动态添加。下面是我尝试使用的伪代码:

subtitle: Row(
children: <Widget>[
Container(
child: HebrewText(helpRequest.description),
//alignment: Alignment.centerLeft,
padding: const EdgeInsets.only(top: 8, left: 8),
),
Spacer(),
GestureDetector(
onTap: ()=>{
if(helpRequest.handler_id != null) {
_launchCaller(),
},
} ,
child: Padding(
padding: EdgeInsets.all(16.0),
child: Icon(
Icons.call,
size: 20.0,
color: BasicColor.clr,
)),
),
],
),

只有当条件为true时,我才希望将手势检测器添加到此行,尝试在GestureDetector((之前添加if条件,但没有成功,有什么简单的方法可以实现吗?

正如你在我的代码中看到的,我把if条件放在了OnTap中,我想把它放在手势检测器上

试试这个

null != helpRequest.handler_id ? GestureDetector(
onTap: _launchCaller ,
child: Padding(
padding: EdgeInsets.all(16.0),
child: Icon(
Icons.call,
size: 20.0,
color: BasicColor.clr,),
),
) : SizedBox(),

最新更新