Can someone help to point how do we define base theme for button and use it on every button? Everywhere I look only found textTheme
but not buttonTheme
Looks like you also need to provide textColor to your button. How about creating your Custom Button?
class MyButton extends StatelessWidget {
final String text;
final Color textColor;
final Color buttonColor;
final Function() onPressed;
MyButton({
@required this.text,
this.buttonColor = const Color(0xFF000000) /** Default buttonColor */,
@required this.onPressed,
this.textColor = const Color(0xFFDDDDDD) /** Default textColor */,
});
@override
Widget build(BuildContext context) {
return MaterialButton(
color: buttonColor,
onPressed: onPressed,
child: Text(text,
style: TextStyle(
color: textColor,
fontSize: 20.0,
)),
);
}
}
You can define your button color like the one in the answer given above/below too.
[UPDATE]
As per request from the comments, this is how you pass a function for onPressed
class Home extends StatelessWidget {
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Button Theme"),
backgroundColor: Colors.green),
body: Center(
child: MyButton( //My custom button
text: "Hit me",
onPressed: () { print("Ouch! Easy pal!! :p ") },
textColor = const Color(SOME CUSTOM COLOUR)
)),
);
}
}