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

468

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)),
  ),
Share:
468
user1087973
Author by

user1087973

Updated on December 27, 2022

Comments

  • user1087973
    user1087973 over 1 year

    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.

  • vietstone
    vietstone over 2 years
    This affects all other TextButton. Is there any way to change the color of TextButton only in AppBar?
  • Usman Akhlaq
    Usman Akhlaq over 2 years
    Yes, The TextButton for which you want to change the color specifically just use its style property. This way the changes will be only for the specific button.