How do you create a button with an image using Flutter? It seems like the simplest thing to do, but the image does not fill the parent widget completely. This is what I have:
Container(child: ConstrainedBox( constraints: BoxConstraints.expand(), child: FlatButton(onPressed: null, child: Image.asset('path/the_image.png'))))
I followed this post as guidance. My image looks like this:
Notice the padding around the PNG image - it's not in the code. Where does it come from? The PNG itself does not have canvas padding, so this must not be the correct technique.
All I need is a button with an image that fills the entire FlatButton
, or another widget I can add actions to, without distorting the image.
The simplest way to create a button with icon and text in Flutter is to use the new Material button called ElevatedButton with an icon constructor. ElevatedButton. icon() gives you the ability to add the icon and label parameter to the button. The ElevatedButton was introduced with the release of Flutter v1.
You can simply add ElevatedButton. icon() widget, you will get the icon property where you can pass Icon data to add Icon on Elevated Button.
Image widget is an essential widget in Flutter because without image you cannot develop a beautiful app. Images express the content better than text.
IconButton( icon: Image.asset('path/the_image.png'), iconSize: 50, onPressed: () {}, )
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