如何更改 flutter showAboutDialog 中的文本按钮颜色?

2024-01-20

我正在使用showAboutDialogflutter 中的函数显示我的项目中使用的许可证。我如何坚持改变文本颜色VIEW LICENSES and CLOSE文本按钮。请参阅此图片以进行说明:

这是我的代码:

...
onTap: () {
  showAboutDialog(
    context: context,
    applicationName: 'bla',
    applicationLegalese: 'November 2023',
 );
},

到目前为止我尝试的是寻找内部的色域showAboutDialog我怎么也找不到任何东西。我假设我可以改变我的颜色MaterialApp ThemeData。不幸的是,我无法找到特定的主题来覆盖这些文本按钮的默认样式。

我在我的中尝试了以下操作MaterialApp ThemeData改变颜色VIEW LICENSES and CLOSE变为绿色,但这并没有改变任何东西:

textButtonTheme: TextButtonThemeData(style: ButtonStyle(foregroundColor: MaterialStateProperty.all<Color>(Colors.green))

对此有什么想法吗?


我对这里的答案不满意,因为所有答案都仅显示 MaterialColor 用例,而我想要自定义颜色。但我终于在下面的链接中找到了很好的解释。

https://blog.logrocket.com/new-material-buttons-in-flutter/ https://blog.logrocket.com/new-material-buttons-in-flutter/

基本上,令人困惑的是新设计使用原色而不是 textStyle 属性。您仍然可以应用其他答案来使用 MaterialColor 更改整体主题,并且可以通过在 TextButton.styleFrom 下使用主要颜色来覆盖使用任何颜色的现有颜色主题。

应用程序中任意位置的示例:

TextButton(
      onPressed: () {},
      style: TextButton.styleFrom(
        foregroundColor: Colors.pink,
      ),
      child: Text(
        'TextButton (New)',
        style: TextStyle(fontSize: 30),
      ),
    )

主题示例:

textButtonTheme: TextButtonThemeData(
      style: TextButton.styleFrom(
        primary: kDarkColor, // This is a custom color variable
        textStyle: GoogleFonts.fredokaOne(),
      ),
    ),
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何更改 flutter showAboutDialog 中的文本按钮颜色? 的相关文章

随机推荐