Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the text color of the button theme in Flutter

If I add a theme to my app like this:

class MyApp extends StatelessWidget {   @override   Widget build(BuildContext context) {     return MaterialApp(       debugShowCheckedModeBanner: false,       theme: ThemeData(         primaryColor: Color(0xff393e46),         primaryColorDark: Color(0xff222831),         accentColor: Color(0xff00adb5),         backgroundColor: Color(0xffeeeeee),         buttonTheme: ButtonThemeData(           buttonColor: Color(0xff00adb5),         )       ),       home: Scaffold(         body: MyHomePage(),       ),     );   } } 

How do I change the text color for the button theme?

like image 440
Suragch Avatar asked May 17 '19 22:05

Suragch


People also ask

How do I change the color of my text buttons?

Use a semi-colon to separate the different style elements in the HTML button tag. Type color: in the quotation marks after "style=". This element is used to change the text color in the button. You can place style elements in any order in the quotation markers after "style=".

How do you change the text color in elevated Button in Flutter?

To change the Elevated Button color in Flutter, simply set the style property of Elevated Button from the ElevatedButton. styleFrom() static method and set the primary property to the appropriate color.

How do you get the theme color in Flutter?

Creating an app theme To share a Theme across an entire app, provide a ThemeData to the MaterialApp constructor. If no theme is provided, Flutter creates a default theme for you. MaterialApp( title: appName, theme: ThemeData( // Define the default brightness and colors. brightness: Brightness.


1 Answers

If you use ButtonTextTheme.primary Flutter will automatically select the right color for you.

For example, if you make the buttonColor dark like this

  ThemeData(     . . .      buttonTheme: ButtonThemeData(       buttonColor: Colors.deepPurple,     //  <-- dark color       textTheme: ButtonTextTheme.primary, //  <-- this auto selects the right color     )   ), 

enter image description here

The text is automatically light. And if you make the buttonColor light, then the text is dark.

  ThemeData(     . . .      buttonTheme: ButtonThemeData(       buttonColor: Colors.yellow,         //  <-- light color       textTheme: ButtonTextTheme.primary, //  <-- dark text for light background     )   ), 

enter image description here

like image 193
Suragch Avatar answered Sep 28 '22 04:09

Suragch