I have a problem here I want to change color of textbutton from themedata but its not working. Here is my code :
darkTheme: ThemeData(
primaryColor:Colors.white,
textButtonTheme: TextButtonThemeData(
style: TextButton.styleFrom(primary: Colors.white),
)
),
and my button code :
TextButton(
style: TextButton.styleFrom(
primary: Theme.of(context).primaryColor,
textStyle: TextStyle(fontSize: 16),),
onPressed: (){}, child: Text("Hellosir",))
I can think of two problems why this is not working.
ThemeDatadefined indarkTheme, but yourthemeModeis not dark. So inMaterialAppaddthemeMode: ThemeMode.darkparameter as well.Theme.of(context).primaryColoris inside same widget as your definition of Theme, and yourcontextstill doesn't have that data. So only context of children of current widget have this data. Solution would be to make a new widget with your button inside it, or wrap your button withBuilderwidget which have context inside its builder.Your problem can be first, second or both.