Flutter: Best way to color text the secondary color of current theme?

Created on 11 May 2016  路  3Comments  路  Source: flutter/flutter

Material design has a concept of a secondary text color: https://www.google.com/design/spec/style/color.html#color-text-background-colors

I can access this color in flutter using the very verbose: Theme.of(context).textTheme.caption.color. I don't want any of the extra styling (weight, fontSize) from from caption or display[1-4]. Using Colors.black54 directly is not ideal since it wouldn't adapt to theme changes. Is there a less verbose way for me to get the secondary text color of the current theme? Currently I made a package level function but it feels like there should be a better way:

Color secondary(BuildContext context) =>
  Theme.of(context).textTheme.caption.color;

This allows me to say

new TextStyle(color: secondary(context))

instead of

new TextStyle(color: Theme.of(context).textTheme.caption.color)
api docs material design framework

Most helpful comment

@Hixie Sounds like ThemeData should have a field for this.

All 3 comments

@Hixie Sounds like ThemeData should have a field for this.

Agreed.

The secondary color is the accent color. There's a field on ThemeData for the accent color; we should point to it from the TextStyle docs or some such.

Was this page helpful?
0 / 5 - 0 ratings