You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Theme.textTheme.button.color is ignored by RaisedButton & FlatButton #19623
To investigate we would need a minimal runnable reproduction
as a single file so that we can just copy your code into lib/main.dart of a new project and run to reproduce.
import'package:flutter/material.dart';
voidmain() =>runApp(MyApp());
final color =Colors.blue;
classMyAppextendsStatelessWidget {
// This widget is the root of your application.@overrideWidgetbuild(BuildContext context) {
returnMaterialApp(
title:'Flutter Demo',
theme:ThemeData(
primaryColor: color,
buttonColor: color,
buttonTheme:ButtonThemeData(buttonColor: color),
textTheme:constTextTheme(body1:TextStyle(color:Colors.grey), button:TextStyle(color:Colors.red)),
iconTheme:constIconThemeData(color:Colors.white),
),
home:MyHomePage(title:'Flutter Demo Home Page'),
);
}
}
classMyHomePageextendsStatefulWidget {
MyHomePage({Key key, this.title}) :super(key: key);
finalString title;
@override_MyHomePageStatecreateState() =>_MyHomePageState();
}
class_MyHomePageStateextendsState<MyHomePage> {
@overrideWidgetbuild(BuildContext context) {
returnScaffold(
appBar:AppBar(
// Here we take the value from the MyHomePage object that was created by// the App.build method, and use it to set our appbar title.
title:Text(widget.title),
),
body:Center(
child:Column(
mainAxisAlignment:MainAxisAlignment.center,
children:<Widget>[
FlatButton(onPressed: () {}, child:Text('Test')),
RaisedButton(onPressed: () {}, child:Text('Test')),
],
),
),
floatingActionButton:FloatingActionButton(
onPressed: () {},
tooltip:'Increment',
child:Icon(Icons.add),
), // This trailing comma makes auto-formatting nicer for build methods.
);
}
}
I expect the raised and flat button text is red, but is stay black.
Eg. for the DatePicker as well (for the others I can override it)
Reacted by Günter Zöchbauer, Muhammad Adil, DineshTamang, Danilo Valle, SoundConception, Andrew Johnson, AndreBerzun, Christian Mürtz and Muhammad Alif Akbar
If Flutter team is too busy to fix broken theme stuff, can they point us in the right direction for what blockers can be addressed by the community?
Reacted by Oscar Reyes, sckoh, Vivek Kekuda, Giraldi Maggio, Michael Pfaff, Vince Varga, Ryosuke Yokota, enricobenedos, boskokg, Tobe Osakwe and 9 more
enum ButtonTextTheme {
/// Button text is black or white depending on [ThemeData.brightness].
normal,
/// Button text is [ThemeData.accentColor].
accent,
/// Button text is based on [ThemeData.primaryColor].
primary,
}
For normal as well as accentColor, the description is in fact working.
For primary. i have observed the text color to actually be dependent on primarySwatch rather than just primaryColor (resulting in either black or white, according to the programmatically determined brightness of your swatches' colors).
So if you want to colorize your button, you will have to pick the corresponding accentColor and set ButtonTextTheme.accent accordingly. Maybe the "TextTheme..." properties are now legacy ways to achieve the theming which have been preserved for compatibility reasons..?
Reacted by miguelpruivo, Bhavya Latha Bandaru, Yue Yang, leiguang and Andrey Zamogilin
Hello everyone, I have had this issue and it was very fustrating to solve, but I think I found some kind of work around.
It seems that the only way to apply color to the text of FlatButtons using a Theme is by using a ColorScheme like this:
ThemeData yourTheme= ThemeData(
// Your themes
// . . . maybe you could be setting the textTheme
// . . . or the primary & secondary colors
// . . . even set your color scheme
////////////////
buttonTheme: ButtonThemeData(
colorScheme: ColorScheme( // You need to set up a color scheme for your
buttomTheme (even if you already did on your ThemeData)
background: background, // NOT USED
brightness: Brightness.light, // I have tried dark & light and it seems like this workaround only works on ligh
error: errorColor, // NOT USED
onBackground: Colors.black87, // NOT USED
onError: Colors.white, // NOT USED
onSurface: Colors.black87, // NOT USED
onSecondary: Colors.black87, // NOT USED
onPrimary: Colors.black, // NOT USED
primary: secondary700, // IMPORTANT LINES: This sets the text color for FlatButtons
primaryVariant: secondary700,
secondary: Colors.black, // IMPORTANT LINES: This sets the text color for RaisedButtons
secondaryVariant: Colors.black,
surface: Colors.white, // NOT USED
),
buttonColor: secondaryMain, // IMPORTANT LINES: This sets the fill color of your raised buttons
disabledColor: disabledColor,
textTheme: ButtonTextTheme.accent, // IMPORTANT LINES: Makes everything happen
);
);
For some other reason this does not apply to DatePickers, so the workaround for those is to do the same, like this:
FWIW, I just copied the code for the time picker and modified it by explicitly setting the colors of the flat buttons, it took around 5 minutes, so that might be the quickest solution.
Currently, for showDatePicker, I prefer to use primarySwatch to set the buttons' color. This is a relatively simple way that I have found without much more modification.
Hello everyone, I have had this issue and it was very fustrating to solve, but I think I found some kind of work around.
It seems that the only way to apply color to the text of FlatButtons using a Theme is by using a ColorScheme like this:
ThemeData yourTheme= ThemeData(
// Your themes
// . . . maybe you could be setting the textTheme
// . . . or the primary & secondary colors
// . . . even set your color scheme
////////////////
buttonTheme: ButtonThemeData(
colorScheme: ColorScheme( // You need to set up a color scheme for your
buttomTheme (even if you already did on your ThemeData)
background: background, // NOT USED
brightness: Brightness.light, // I have tried dark & light and it seems like this workaround only works on ligh
error: errorColor, // NOT USED
onBackground: Colors.black87, // NOT USED
onError: Colors.white, // NOT USED
onSurface: Colors.black87, // NOT USED
onSecondary: Colors.black87, // NOT USED
onPrimary: Colors.black, // NOT USED
primary: secondary700, // IMPORTANT LINES: This sets the text color for FlatButtons
primaryVariant: secondary700,
secondary: Colors.black, // IMPORTANT LINES: This sets the text color for RaisedButtons
secondaryVariant: Colors.black,
surface: Colors.white, // NOT USED
),
buttonColor: secondaryMain, // IMPORTANT LINES: This sets the fill color of your raised buttons
disabledColor: disabledColor,
textTheme: ButtonTextTheme.accent, // IMPORTANT LINES: Makes everything happen
);
);
For some other reason this does not apply to DatePickers, so the workaround for those is to do the same, like this:
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.
Activity
zoechi commentedon Jan 24, 2019
To investigate we would need a minimal runnable reproduction
as a single file so that we can just copy your code into
lib/main.dartof a new project and run to reproduce.zoechi commentedon Jan 24, 2019
There is no
ThemeData.buttonanymore.You can use
ThemeData.buttonTheme.textThemeto selectaccent,normal,primary.I haven't found a way to globally change button text style besides what I mentioned before.
modulovalue commentedon Jan 24, 2019
ThemeData.textTheme.button.coloris never used with the currently availableButtonTextThemevalues.jaumard commentedon Jan 31, 2019
So here is a small way to reproduce it:
I expect the raised and flat button text is red, but is stay black.
I'm using 1.0.0 stable version of flutter
GiacomoPignoni commentedon Jan 31, 2019
fgatti675 commentedon Feb 4, 2019
pdefuns commentedon Feb 6, 2019
Same here.. Please upvote the first comment
Eg. for the DatePicker as well (for the others I can override it)
5 remaining items
DineshTamang commentedon Jun 20, 2019
I am exactly facing the same problem as mentioned. Please look on this issue asap if possible that would be very helpful.
lukepighetti commentedon Jun 20, 2019
If Flutter team is too busy to fix broken theme stuff, can they point us in the right direction for what blockers can be addressed by the community?
Lootwig commentedon Jul 9, 2019
The docs of ButtonTextTheme states:
For
normalas well asaccentColor, the description is in fact working.For
primary. i have observed the text color to actually be dependent onprimarySwatchrather than justprimaryColor(resulting in either black or white, according to the programmatically determined brightness of your swatches' colors).So if you want to colorize your button, you will have to pick the corresponding
accentColorand setButtonTextTheme.accentaccordingly. Maybe the "TextTheme..." properties are now legacy ways to achieve the theming which have been preserved for compatibility reasons..?ykaito21 commentedon Oct 1, 2019
I also have the same problem. Does someone knows any update or way to solve this problem?I just override my theme with new theme for showDatePicker
migalv commentedon Dec 20, 2019
Hello everyone, I have had this issue and it was very fustrating to solve, but I think I found some kind of work around.
It seems that the only way to apply color to the text of FlatButtons using a Theme is by using a ColorScheme like this:
For some other reason this does not apply to DatePickers, so the workaround for those is to do the same, like this:
Hope it works for you too ;)
Let me know if it did! :P
vincevargadev commentedon Dec 20, 2019
FWIW, I just copied the code for the time picker and modified it by explicitly setting the colors of the flat buttons, it took around 5 minutes, so that might be the quickest solution.
g1eny0ung commentedon Dec 26, 2019
Currently, for
showDatePicker, I prefer to useprimarySwatchto set the buttons' color. This is a relatively simple way that I have found without much more modification.padmanabanSampath commentedon Feb 16, 2020
This Did it...... thanks
HansMuller commentedon Apr 14, 2020
@modulovalue, @jaumard @YAPPDEF @lukepighetti @kolaente @Lootwig @vware @ch-muhammad-adil @fgatti675 @DineshTamang @migalv @ykaito21 @padmanabanSampath There's a rather wide-reaching proposal to remedy the problems that have come up in this issue. Please take a look at #54776. We'd appreciate your feedback.
modulovalue commentedon Apr 14, 2020
@HansMuller Thank you.
For those stumbling across this issue, please check out #54776 where a concrete solution is being proposed.
github-actions commentedon Aug 15, 2021
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of
flutter doctor -vand a minimal reproduction of the issue.