Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create a button with an image in Flutter?

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:

enter image description here

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.

like image 864
Hahnemann Avatar asked Dec 05 '18 21:12

Hahnemann


People also ask

How do I create a button with an icon in Flutter?

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.

How do you add an icon to an elevated button in Flutter?

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.

Is image a widget in Flutter?

Image widget is an essential widget in Flutter because without image you cannot develop a beautiful app. Images express the content better than text.


1 Answers

IconButton(   icon: Image.asset('path/the_image.png'),   iconSize: 50,   onPressed: () {}, ) 
like image 172
Avi Cohen Avatar answered Oct 02 '22 23:10

Avi Cohen