-
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hi @maxfrees, thanks for the question. It is an interesting one 😄 You will need to extract the resulting For the correct (same as default) font spacing and height, you will also need to replicate the exact default Here is the basic idea: abstract final class AppTheme {
// The defined light theme.
static ThemeData get light {
// Make a FlexColorScheme data object, without creating a theme or
// ColorScheme from it. This is done to be able to extract the ColorScheme
// from it, to then use it in the custom subThemesData for ListTile, or
// other places where we want to use the created ColorScheme colors, like
// even totally custom component theme overrides on the resulting ThemeData.
final FlexColorScheme fcsData = FlexColorScheme.light(
scheme: FlexScheme.flutterDash,
surfaceMode: FlexSurfaceMode.levelSurfacesLowScaffold,
lightIsWhite: true,
visualDensity: VisualDensity.comfortable,
subThemesData: const FlexSubThemesData(
blendOnLevel: 10,
blendOnColors: false,
// App Bar
appBarBackgroundSchemeColor: SchemeColor.primary,
// Tab Bar
tabBarItemSchemeColor: SchemeColor.onPrimary,
tabBarUnselectedItemSchemeColor: SchemeColor.outlineVariant,
),
);
// Extract the ColorScheme from FlexColorScheme.
final ColorScheme colorScheme = fcsData.toScheme;
// Return ThemeData with custom subThemesData for ListTile, where its
// listTileSubtitleTextStyle is modified to use the
// colorScheme outlineColor. This is just an example of how to use the
// extracted colorScheme to create a custom style for the ListTile
// subtitle text style.
return fcsData
.copyWith(
subThemesData: fcsData.subThemesData!.copyWith(
listTileSubtitleTextStyle: TextStyle(
color: colorScheme.outlineVariant,
fontSize: 14.0,
fontWeight: FontWeight.w400,
letterSpacing: 0.25,
height: 1.43,
textBaseline: TextBaseline.alphabetic,
leadingDistribution: TextLeadingDistribution.even),
),
)
.toTheme;
} To match the default M3 style we have to match the default M3 style for the ListTile subtitle text style. The correct one depends on your locale and is difficult to recreate universally, since different locales have different default styles. In Flutter the default TextStyle sizes, heights and letter spacing are not not set by the ThemeData created by FlexColorScheme, nor even by ThemeData creation in Flutter SDK. They are set by the localization step in The default sizes are thus not available until the context after the If you are using another custom font and not the default, you would need to put that into TextStyle as well. All this Below is a screenshot of the Flutter SDK code behind this from the If you want to use If you have and use only one Typography style that you know it will be, well then you can do what I did above to match the default. Of course your style does not have to be the default exactly either, you can make your own style, with custom height and letter spacing too. Fonts and Typography in Flutter are quite complicated. PS. In your example you set Converting this issue to a discussion. It is yet another good example of using more advanced features in FlexColorScheme, to first extract the ColorScheme and use it for further modifications. Others might find it useful as well. |
Beta Was this translation helpful? Give feedback.
Hi @maxfrees, thanks for the question. It is an interesting one 😄
You will need to extract the resulting
ColorScheme
from yourFlexColorScheme
and use colors from it to define thelistTileSubtitleTextStyle
and itsTextStyle
color.For the correct (same as default) font spacing and height, you will also need to replicate the exact default
TextStyle
ofbodyMedium
that ListTile uses for its subtitle. The default Material3bodyMedium
has a lot of other props in its TextStyle set as well, not just font size 14, more about that later.Here is the basic idea: