how to have a button with text and icon for the flutter
?
I wanted to have a button
which looks like icon with a text that is able to put at the bottom of the screen
For example, the icon is like at here: android-button-with-icon-and-text
Method 2 : Using ClipOvel and Material. body: Center( child: SizedBox. fromSize( size: Size(60, 60), // button width and height child: ClipOval( child: Material( color: Colors. red, // button color child: Column( mainAxisAlignment: MainAxisAlignment. center, children: <Widget>[ Icon(Icons.
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 use RaisedButton and use the child property to do this. You need to add a Row and inside row you can add a Text widget and an Icon Widget to achieve this. If you want to use png image, you can use similar widget to achieve this.
EDIT 1: With Flutter 1.20 release Flutter Team did breaking changes introducing new buttons. So the below mentioned button types are deprecated. Use TextButton instead of FlatButton and ElevatedButton instead of RaisedButton.
TextButton.icon(onPressed: null, icon: null, label: null);
Elevated.icon(onPressed: null, icon: null, label: null);
See breaking changes for buttons and their themes here
Note: FlatButton and RaisedButton is DEPRECATED
You can simply use named constructors for creating different types of buttons with icons. For instance
FlatButton.icon(onPressed: null, icon: null, label: null);
RaisedButton.icon(onPressed: null, icon: null, label: null);
But if you have specfic requirements then you can always create custom button with different layouts or simply wrap a widget in GestureDetector.
Screenshot:
SizedBox.fromSize(
size: Size(56, 56), // button width and height
child: ClipOval(
child: Material(
color: Colors.orange, // button color
child: InkWell(
splashColor: Colors.green, // splash color
onTap: () {}, // button pressed
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Icon(Icons.call), // icon
Text("Call"), // text
],
),
),
),
),
)
You can achieve that by using a FlatButton
that contains a Column
(for showing a text below the icon) or a Row
(for text next to the icon), and then having an Icon
Widget and a Text
widget as children.
Here's an example:
class MyPage extends StatelessWidget {
@override
Widget build(BuildContext context) =>
Scaffold(
appBar: AppBar(
title: Text("Hello world"),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
FlatButton(
onPressed: () => {},
color: Colors.orange,
padding: EdgeInsets.all(10.0),
child: Column( // Replace with a Row for horizontal icon + text
children: <Widget>[
Icon(Icons.add),
Text("Add")
],
),
),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: () => {},
tooltip: 'Increment',
child: Icon(Icons.add),
),
);
}
This will produce the following:
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