-
On demo page like https://rydmike.com/flexcolorscheme4/#/ Thanks |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Hi @wyxcode, If you look in the shared code for the examples that show the theme color boxes and the text on them: You can see that it actually uses 3 different strategies to do this. Let's start with the lowest level that they ultimately all are based on: textColor: ThemeData.estimateBrightnessForColor(color) == Brightness.dark ? Colors.white : Colors.black, The static function Whenever you have a surface or box of a color (pre-defined, random, computed, from a theme), you can use this function to calculate the most suitable color to draw and write things on it for maximum contrast. Here is an example of that: The Flutter SDK The Flutter color theming class FlexColorScheme does the same, depending on selected scheme, or what colors you assigned to You can the refer to this line to see on example of using theme based pre-assigned onColor for the text color: Then the 3rd way is that there is also a primary text theme in Flutter, this text theme always has a color that fits well on the Here you can see an example of that being used: Many theme colors in Flutter do not come with pre-computed "onColors" that you can rely to get the correct text color for it. For example the So for cases like that you will have to rely on the FlexColorScheme's predefined themes always uses Hope this helps! br Mike |
Beta Was this translation helpful? Give feedback.
-
Woo, great! thank you very much. there are a lot of information in the reply, very helpful! |
Beta Was this translation helpful? Give feedback.
Hi @wyxcode,
If you look in the shared code for the examples that show the theme color boxes and the text on them:
https://github.com/rydmike/flex_color_scheme/blob/master/example/lib/shared/show_theme_colors.dart
You can see that it actually uses 3 different strategies to do this.
Let's start with the lowest level that they ultimately all are based on:
The static function
estimateBrightnessForColor(color)
in the Flutter SDK'sThemeData
class returns theenum
valueBrightness.dark
if the passed incolor
is one that is considered dark, which means a light text color, typically white, w…