1

在我的根文件中,我有:

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

在我的自定义 AppBar 文件中:

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

但文本仍然是默认的浅蓝色。

4

2 回答 2

0

您正在TextButtonAppBar 中使用,但未在代码中定义其主题。您需要定义TextButtonTheme以更改 TextButton 文本的颜色。像这样。

ThemeData(
 textbuttonTheme: TextbuttonThemeData(
   style: Textbutton.styleFrom(primary: Colors.teal)),
  ),
于 2021-01-21T21:01:32.623 回答
0
return MaterialApp(
  theme: ThemeData(
    textButtonTheme: TextButtonThemeData(
      style: TextButton.styleFrom(primary: Colors.black)
    )
  ),
  home: MyWidget(),
);

将 FlatButton 迁移到 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(),
);
于 2021-07-04T12:22:37.360 回答