Search code examples
fluttercolorsthemesflutter-appbar

Globally edit color of TextButton widgets in an AppBar actions list?


In my root file I have:

theme: ThemeData(
  appBarTheme: AppBarTheme(
    textTheme: TextTheme(
      button: TextStyle(color: Colors.white),
    ),
  ),
),

and in my custom AppBar file:

return AppBar(
  automaticallyImplyLeading: false,
  backgroundColor: Colors.transparent,
  actions: <Widget>[
    TextButton(
      child: Text('Sign in'),
      onPressed: () {},
    ),
  ],
);

but the text remains the default light blue-ish color.


Solution

  • You are using TextButton in your AppBar but not defining its theme in your code. You need to define the TextButtonTheme in order to change the color of the text of your TextButton. Like this.

    ThemeData(
     textbuttonTheme: TextbuttonThemeData(
       style: Textbutton.styleFrom(primary: Colors.teal)),
      ),