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

LOL*_*dad 14 flutter

我正在使用showAboutDialogflutter的功能来显示我的项目中使用的许可证。如何过我坚持与改变的文字颜色VIEW LICENSESCLOSEtextbuttons。请参阅此图像以进行澄清:

关于对话框

这是我的代码:

...
onTap: () {
  showAboutDialog(
    context: context,
    applicationName: 'bla',
    applicationLegalese: 'November 2023',
 );
},
Run Code Online (Sandbox Code Playgroud)

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

我想在我的下面MaterialApp ThemeData,以改变颜色VIEW LICENSESCLOSE绿色但这并没有改变什么:

textButtonTheme: TextButtonThemeData(style: ButtonStyle(foregroundColor: MaterialStateProperty.all<Color>(Colors.green))
Run Code Online (Sandbox Code Playgroud)

关于这个的任何想法?

Hyu*_*gur 30

我对这里的答案并不满意,因为所有答案都只显示了 MaterialColor 用例,而我想要自定义颜色。但我终于在以下链接上找到了一些解释得很好的东西。

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

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

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

TextButton(
      onPressed: () {},
      style: TextButton.styleFrom(
        primary: Colors.pink,
      ),
      child: Text(
        'TextButton (New)',
        style: TextStyle(fontSize: 30),
      ),
    )
Run Code Online (Sandbox Code Playgroud)

主题示例:

textButtonTheme: TextButtonThemeData(
      style: TextButton.styleFrom(
        primary: kDarkColor, // This is a custom color variable
        textStyle: GoogleFonts.fredokaOne(),
      ),
    ),
Run Code Online (Sandbox Code Playgroud)


Riw*_*wen 7

你可以使用这个:

return MaterialApp(
      theme: ThemeData.dark().copyWith(
          textButtonTheme: TextButtonThemeData(
              style: ButtonStyle(
                  foregroundColor: MaterialStateProperty.resolveWith(
                      (state) => Colors.orange)))),
      home: MyWidget(),
    );
Run Code Online (Sandbox Code Playgroud)

MaterialStateProperty.resolveWith 带一个函数,你可以根据状态指定颜色,比如

MaterialState.pressed,
MaterialState.hovered,
MaterialState.focused,
Run Code Online (Sandbox Code Playgroud)

更多信息


小智 6

这个怎么样?

@override
Widget build(BuildContext context) {
  return MaterialApp(
    theme: ThemeData(
      primarySwatch: Colors.blue,
      colorScheme: ColorScheme.fromSwatch(
        primarySwatch: Colors.green,
      ).copyWith(),      
    ),
    debugShowCheckedModeBanner: false,
    home: YourScreen(),
  );
}
Run Code Online (Sandbox Code Playgroud)

样本