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?
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=".
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.
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.
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 ) ),
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 ) ),
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