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

Viewed 548

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.

2 Answers

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)),
  ),
return MaterialApp(
  theme: ThemeData(
    textButtonTheme: TextButtonThemeData(
      style: TextButton.styleFrom(primary: Colors.black)
    )
  ),
  home: MyWidget(),
);

Migrate FlatButton to TextButton

return MaterialApp(
  theme: ThemeData(
    textButtonTheme: TextButtonThemeData(
      style: TextButton.styleFrom(
        primary: Colors.black87,
        minimumSize: Size(88, 36),
        padding: EdgeInsets.symmetric(horizontal: 16.0),
        shape: const RoundedRectangleBorder(
          borderRadius: BorderRadius.all(Radius.circular(2.0)),
        ),
      )
    )
  ),
  home: MyWidget(),
);
Related