Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
978 views
in Technique[技术] by (71.8m points)

flutter - 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.

question from:https://stackoverflow.com/questions/65835474/globally-edit-color-of-textbutton-widgets-in-an-appbar-actions-list

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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)),
  ),

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share

2.1m questions

2.1m answers

62 comments

56.6k users

...