'Flutter 2: Button with icon and text

Since RaisedButton, FlatButton, etc. have been deprecated, are there any button widgets that provide text and icons to prevent row creation or other workarounds?



Solution 1:[1]

You can use ElevatedButton.icon

Here the sample button:

enter image description here

Code:

 // Color state for button.
 Color _getTextColor(Set<MaterialState> states) => states.any(<MaterialState>{
    MaterialState.pressed,
    MaterialState.hovered,
    MaterialState.focused,
  }.contains)
      ? Colors.green
      : Colors.blue;

  Widget _myButton() {
     return ElevatedButton.icon(
        onPressed: () {/* do something here */ },
        icon: Icon(Icons.edit),
        style: ButtonStyle(backgroundColor: MaterialStateColor.resolveWith(_getTextColor)),
        label: Text(
          "Update",
          style: TextStyle(color: Colors.white),
        ));
  }

Solution 2:[2]

You can simply use TextButton.icon() constructor.

TextButton.icon(
    icon: Icon(), // Your icon here
    label: Text(), // Your text here
    onPressed: (){},
)

For more information about TextButton.icon() constructor you can visit this site.

Solution 3:[3]

you can add TextButton.icon like this

TextButton.icon(
                icon: Icon(Icons.photo, color:Colors.black ),
                label: Text(
                  "Gallery",
                  style: TextStyle(color: Colors.black),
                ),
                onPressed: () {
                  // call method

                },

            ),

Solution 4:[4]

I have made the class named IconTextButton below:

class IconTextButton extends StatelessWidget {
  IconTextButton({@required this.title,@required this.onPressed, @required this.icon,this.color,this.shape});

  final Icon icon;
  final Color color;
  final Text title;
  final ShapeBorder shape;
  final void Function() onPressed;

  @override
  Widget build(BuildContext context) {
    return new Container(
      margin: const EdgeInsets.symmetric(vertical: 10.0),
      child: MaterialButton(
        shape: shape,
        color: color,
        onPressed: onPressed,
        child: Row(
          mainAxisSize: MainAxisSize.min,
          children: <Widget>[
            icon,
            title
          ],
        ),
      )
    );
  }
}

now use this class in your code like:

IconTextButton(
 onPressed: (){

 },
 color: Colors.red,
 icon: Icon(Icons.home),
 title: new Text("Hello"),
),

Now you are go to code. :)

Solution 5:[5]

Try this:

TextButton.icon(
  onPressed: () {
    print("edit");
  },
  icon: Icon(Icons.edit),
  label: Text("edit"),
),

Solution 6:[6]

you can create that design with many widget the simple way is that add

ElevatedButton.icon(
      icon: Icon(
        Icons.favorite,
        color: Colors.pink,
        size: 24.0,
      ),
      label: Text('Elevated Button'),)

you can replace elevated button with text and rounded button see this link https://www.flutterbeads.com/button-with-icon-and-text-flutter/

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 ישו אוהב אותך
Solution 2 Kishan Dhankecha
Solution 3 ishan weerakoon
Solution 4 Hardik Khatri
Solution 5 My Car
Solution 6 abdelrahman abied