copyWith method Null safety
- {TextStyle? displayLarge,
- TextStyle? displayMedium,
- TextStyle? displaySmall,
- TextStyle? headlineLarge,
- TextStyle? headlineMedium,
- TextStyle? headlineSmall,
- TextStyle? titleLarge,
- TextStyle? titleMedium,
- TextStyle? titleSmall,
- TextStyle? bodyLarge,
- TextStyle? bodyMedium,
- TextStyle? bodySmall,
- TextStyle? labelLarge,
- TextStyle? labelMedium,
- TextStyle? labelSmall,
- TextStyle? headline1,
- TextStyle? headline2,
- TextStyle? headline3,
- TextStyle? headline4,
- TextStyle? headline5,
- TextStyle? headline6,
- TextStyle? subtitle1,
- TextStyle? subtitle2,
- TextStyle? bodyText1,
- TextStyle? bodyText2,
- TextStyle? button,
- TextStyle? overline}
Creates a copy of this text theme but with the given fields replaced with the new values.
Consider using Typography.black or Typography.white, which implement the typography styles in the Material Design specification, as a starting point.
/// A Widget that sets the ambient theme's title text color for its
/// descendants, while leaving other ambient theme attributes alone.
class TitleColorThemeCopy extends StatelessWidget {
const TitleColorThemeCopy({super.key, required this.titleColor, required this.child});
final Color titleColor;
final Widget child;
@override
Widget build(BuildContext context) {
final ThemeData theme = Theme.of(context);
return Theme(
data: theme.copyWith(
textTheme: theme.textTheme.copyWith(
titleLarge: theme.textTheme.titleLarge!.copyWith(
color: titleColor,
),
),
),
child: child,
);
}
}
See also:
Implementation
TextTheme copyWith({
TextStyle? displayLarge,
TextStyle? displayMedium,
TextStyle? displaySmall,
TextStyle? headlineLarge,
TextStyle? headlineMedium,
TextStyle? headlineSmall,
TextStyle? titleLarge,
TextStyle? titleMedium,
TextStyle? titleSmall,
TextStyle? bodyLarge,
TextStyle? bodyMedium,
TextStyle? bodySmall,
TextStyle? labelLarge,
TextStyle? labelMedium,
TextStyle? labelSmall,
TextStyle? headline1,
TextStyle? headline2,
TextStyle? headline3,
TextStyle? headline4,
TextStyle? headline5,
TextStyle? headline6,
TextStyle? subtitle1,
TextStyle? subtitle2,
TextStyle? bodyText1,
TextStyle? bodyText2,
TextStyle? caption,
TextStyle? button,
TextStyle? overline,
}) {
assert(
(displayLarge == null && displayMedium == null && displaySmall == null && headlineMedium == null &&
headlineSmall == null && titleLarge == null && titleMedium == null && titleSmall == null &&
bodyLarge == null && bodyMedium == null && bodySmall == null && labelLarge == null && labelSmall == null) ||
(headline1 == null && headline2 == null && headline3 == null && headline4 == null &&
headline5 == null && headline6 == null && subtitle1 == null && subtitle2 == null &&
bodyText1 == null && bodyText2 == null && caption == null && button == null && overline == null),
'Cannot mix 2018 and 2021 terms in call to TextTheme() constructor.'
);
return TextTheme(
displayLarge: displayLarge ?? headline1 ?? this.displayLarge,
displayMedium: displayMedium ?? headline2 ?? this.displayMedium,
displaySmall: displaySmall ?? headline3 ?? this.displaySmall,
headlineLarge: headlineLarge ?? this.headlineLarge,
headlineMedium: headlineMedium ?? headline4 ?? this.headlineMedium,
headlineSmall: headlineSmall ?? headline5 ?? this.headlineSmall,
titleLarge: titleLarge ?? headline6 ?? this.titleLarge,
titleMedium: titleMedium ?? subtitle1 ?? this.titleMedium,
titleSmall: titleSmall ?? subtitle2 ?? this.titleSmall,
bodyLarge: bodyLarge ?? bodyText1 ?? this.bodyLarge,
bodyMedium: bodyMedium ?? bodyText2 ?? this.bodyMedium,
bodySmall: bodySmall ?? caption ?? this.bodySmall,
labelLarge: labelLarge ?? button ?? this.labelLarge,
labelMedium: labelMedium ?? this.labelMedium,
labelSmall: labelSmall ?? overline ?? this.labelSmall,
);
}