TextTheme
TextTheme is a way to define consistent text styles across an app. It contains a set of text styles that can be applied to Text widgets in Flutter.
Here are some common examples of TextTheme usage:
- Defining a default text style for an app:
final ThemeData themeData = ThemeData(
textTheme: TextTheme(
bodyText2: TextStyle(fontSize: 16.0, fontWeight: FontWeight.w500),
),
);In this example, we define a default text style for the app's bodyText2 Text widget. This style will be used throughout the app unless explicitly overridden.
- Overriding a specific text style for a widget:
Text(
'Hello, world!',
style: Theme.of(context).textTheme.headline1,
);In this example, we override the default text style for the Text widget by using the headline1 style from the app's textTheme.
Overall, TextTheme provides a convenient way to maintain consistent text styles throughout an app, making it easier to manage and update text styles as needed.
Parameters
headline1: The largest style in the text theme hierarchy. Typically used for large headings.
headline2: A slightly smaller style thanheadline1. Used for subheadings or secondary headings.
headline3: A smaller style thanheadline2. Used for tertiary headings or other similar purposes.
headline4: A smaller style thanheadline3. Used for quaternary headings or other similar purposes.
headline5: A smaller style thanheadline4. Used for quinary headings or other similar purposes.
headline6: A smaller style thanheadline5. Used for senary headings or other similar purposes.
subtitle1: A style for longer titles or subtitles.
subtitle2: A style for shorter titles or subtitles.
bodyText1: A style for large bodies of text.
bodyText2: A style for small bodies of text.
caption: A style for captions or other small, auxiliary pieces of text.
button: A style for text used in buttons or other similar interactive elements.
overline: A style for overlined text.