Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I change the textbutton color in the flutter showAboutDialog?

Tags:

I'm using the showAboutDialog function from flutter to show used licences in my project. How ever I'm stuck with changing the text color of the VIEW LICENSES and CLOSE textbuttons. See this image for clarification:

about dialog

This is my code:

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

What I tried so far is looking for a color field inside the showAboutDialog how ever I could not find anything. I'm assuming that I could change the color in my MaterialApp ThemeData. Unfortunately I was not able to find the specific theme to override the default styling of those textbuttons.

I tried the following in my MaterialApp ThemeData to change the color of VIEW LICENSES and CLOSE to green but that did not change anything:

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

Any ideas about this?

like image 239
LOLWTFasdasd asdad Avatar asked Nov 11 '20 11:11

LOLWTFasdasd asdad


People also ask

How do you change the color of TextButton in Flutter?

To change the Text Button color in Flutter, simply add the style parameter inside the Text Button and assign the TextButton. styleFrom() with the primary property set to any color of your choice.

How do you style TextButton in Flutter?

Creating a ButtonStyle for a TextButton can be done using TextButton. styleFrom . For defining a style for a specific button, you can pass ButtonStyle as style parameter in the constructor of TextButton . You can pass ButtonStyle as both ThemeData 's textButtonTheme and TextButton 's style parameters.

How do you change the click color in Flutter?

To change the Elevated Button color in Flutter, simply set the style property of Elevated Button from the ElevatedButton. styleFrom() static method and set the primary property to the appropriate color.

How do I change the color of my RaisedButton Flutter?

What you can do is create a "color" property (not required to set any value for it) in Zone class. Then set the color property of RaisedButton to zone.


2 Answers

I was not satisfied with the answers here because all were showing only MaterialColor use-cases and I wanted a custom color. But I finally found something explaining it well on the following link.

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

Basically, what is confusing is that the new design uses the primary color instead of the textStyle property. You can still apply the other answers to change the overall theme using a MaterialColor, and you can override the existing color theme using any color by using primary under TextButton.styleFrom.

Example for anywhere in the app:

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

Example for the theme:

textButtonTheme: TextButtonThemeData(       style: TextButton.styleFrom(         primary: kDarkColor, // This is a custom color variable         textStyle: GoogleFonts.fredokaOne(),       ),     ), 
like image 192
Hyung Tae Carapeto Figur Avatar answered Sep 21 '22 02:09

Hyung Tae Carapeto Figur


You can use this:

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

MaterialStateProperty.resolveWith takes a function, you can specify the color based on states, such as

MaterialState.pressed, MaterialState.hovered, MaterialState.focused, 

More info on this.

like image 42
Riwen Avatar answered Sep 21 '22 02:09

Riwen