Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I keep icon disabled if the icon value in constructor is null on RaisedButton.icon()?

I have a common widget for buttons that takes icon value as a constructor. Sometimes I would like the widget to have no icon visible. How do I put that logic in a widget looking like this?

const SocialAuthBtn({this.action, this.title, this.textColor, this.bgColor, this.icon});

@override
  Widget build(BuildContext context) {
    return ButtonTheme(
      minWidth: double.infinity,
      height: UtilWidget.verticalBlock(7),
      child: RaisedButton.icon(
          onPressed: action,
          color: bgColor,
          label: Padding(
            padding: EdgeInsets.only(left: UtilWidget.horizontalBlock(2)),
            child: Text(
              title,
              style: TextStyle(
                fontSize: SizeConfig.blockSizeHorizontal + 10,
                color: textColor,
                height: 1,
              ),
            ),
          ),
          icon: Image.asset(
            icon,
            width: UtilWidget.horizontalBlock(4),
            height: UtilWidget.horizontalBlock(4),
          )
      ),
    );
  }
like image 674
Farwa Avatar asked Oct 16 '25 18:10

Farwa


1 Answers

You can try,

icon: icon!=null? Image.asset(
            icon,
            width: UtilWidget.horizontalBlock(4),
            height: UtilWidget.horizontalBlock(4),
          ):Icon(null)
like image 153
Ravinder Kumar Avatar answered Oct 18 '25 09:10

Ravinder Kumar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!