-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp_text_theme_extension.dart
136 lines (126 loc) · 4.62 KB
/
app_text_theme_extension.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
import 'package:flutter/material.dart';
/// `ThemeExtension` template for custom text styles.
///
/// If your goal is to only change the text color for light/dark mode, I don't see a big benefit from this extension.
/// For the default text style in the Text widget, you can set `textTheme.bodyMedium` in `ThemeData` (example: lib/app_theme.dart).
/// And to set text color for specific widgets, you can use `style: TextStyle(color: Theme.of(context).appColors.error)` or
/// `style: AppTypography.h1.copyWith(color: context.theme.appColors.error)`.
class AppTextThemeExtension extends ThemeExtension<AppTextThemeExtension> {
const AppTextThemeExtension({
required this.displayLarge,
required this.displayMedium,
required this.displaySmall,
required this.headlineLarge,
required this.headlineMedium,
required this.headlineSmall,
required this.titleLarge,
required this.titleMedium,
required this.titleSmall,
required this.bodyLarge,
required this.bodyMedium,
required this.bodySmall,
required this.labelLarge,
});
final TextStyle displayLarge;
final TextStyle displayMedium;
final TextStyle displaySmall;
final TextStyle headlineLarge;
final TextStyle headlineMedium;
final TextStyle headlineSmall;
final TextStyle titleLarge;
final TextStyle titleMedium;
final TextStyle titleSmall;
final TextStyle bodyLarge;
final TextStyle bodyMedium;
final TextStyle bodySmall;
final TextStyle labelLarge;
@override
ThemeExtension<AppTextThemeExtension> 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,
}) {
return AppTextThemeExtension(
displayLarge: displayLarge ?? this.displayLarge,
displayMedium: displayMedium ?? this.displayMedium,
displaySmall: displaySmall ?? this.displaySmall,
headlineLarge: headlineLarge ?? this.headlineLarge,
headlineMedium: headlineMedium ?? this.headlineMedium,
headlineSmall: headlineSmall ?? this.headlineSmall,
titleLarge: titleLarge ?? this.titleLarge,
titleMedium: titleMedium ?? this.titleMedium,
titleSmall: titleSmall ?? this.titleSmall,
bodyLarge: bodyLarge ?? this.bodyLarge,
bodyMedium: bodyMedium ?? this.bodyMedium,
bodySmall: bodySmall ?? this.bodySmall,
labelLarge: labelLarge ?? this.labelLarge,
);
}
@override
ThemeExtension<AppTextThemeExtension> lerp(
covariant ThemeExtension<AppTextThemeExtension>? other,
double t,
) {
if (other is! AppTextThemeExtension) {
return this;
}
return AppTextThemeExtension(
displayLarge: TextStyle.lerp(displayLarge, other.displayLarge, t)!,
displayMedium: TextStyle.lerp(displayMedium, other.displayMedium, t)!,
displaySmall: TextStyle.lerp(displaySmall, other.displaySmall, t)!,
headlineLarge: TextStyle.lerp(headlineLarge, other.headlineLarge, t)!,
headlineMedium: TextStyle.lerp(headlineMedium, other.headlineMedium, t)!,
headlineSmall: TextStyle.lerp(headlineSmall, other.headlineSmall, t)!,
titleLarge: TextStyle.lerp(titleLarge, other.titleLarge, t)!,
titleMedium: TextStyle.lerp(titleMedium, other.titleMedium, t)!,
titleSmall: TextStyle.lerp(titleSmall, other.titleSmall, t)!,
bodyLarge: TextStyle.lerp(bodyLarge, other.bodyLarge, t)!,
bodyMedium: TextStyle.lerp(bodyMedium, other.bodyMedium, t)!,
bodySmall: TextStyle.lerp(bodySmall, other.bodySmall, t)!,
labelLarge: TextStyle.lerp(labelLarge, other.labelLarge, t)!,
);
}
}
/// Small version. Used as an example in lib/app_theme.dart.
class SimpleAppTextThemeExtension
extends ThemeExtension<SimpleAppTextThemeExtension> {
const SimpleAppTextThemeExtension({
required this.body1,
required this.h1,
});
final TextStyle body1;
final TextStyle h1;
@override
ThemeExtension<SimpleAppTextThemeExtension> copyWith({
TextStyle? body1,
TextStyle? h1,
}) {
return SimpleAppTextThemeExtension(
body1: body1 ?? this.body1,
h1: h1 ?? this.h1,
);
}
@override
ThemeExtension<SimpleAppTextThemeExtension> lerp(
covariant ThemeExtension<SimpleAppTextThemeExtension>? other,
double t,
) {
if (other is! SimpleAppTextThemeExtension) {
return this;
}
return SimpleAppTextThemeExtension(
body1: TextStyle.lerp(body1, other.body1, t)!,
h1: TextStyle.lerp(h1, other.h1, t)!,
);
}
}