Since RaisedButton, FlatButton, etc. have been deprecated, are there any button widgets that provide text and icons to prevent row creation or other workarounds?
Since RaisedButton, FlatButton, etc. have been deprecated, are there any button widgets that provide text and icons to prevent row creation or other workarounds?
You can use ElevatedButton.icon
Here the sample button:
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),
));
}
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.
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
},
),
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. :)
Try this:
TextButton.icon(
onPressed: () {
print("edit");
},
icon: Icon(Icons.edit),
label: Text("edit"),
),
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/