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),
)
),
);
}
You can try,
icon: icon!=null? Image.asset(
icon,
width: UtilWidget.horizontalBlock(4),
height: UtilWidget.horizontalBlock(4),
):Icon(null)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With