-
-
Notifications
You must be signed in to change notification settings - Fork 54
/
extensions.dart
137 lines (115 loc) · 4.25 KB
/
extensions.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
137
import 'package:flutter/material.dart';
import 'package:flutter_app/bootstrap/helpers.dart';
import 'package:flutter_app/resources/themes/styles/color_styles.dart';
extension NyText on Text {
/// Set the Style to use [displayLarge].
Text displayLarge(BuildContext context) {
return this.setStyle(Theme.of(context).textTheme.displayLarge);
}
/// Set the Style to use [displayMedium].
Text displayMedium(BuildContext context) {
return this.setStyle(Theme.of(context).textTheme.displayMedium);
}
/// Set the Style to use [displaySmall].
Text displaySmall(BuildContext context) {
return this.setStyle(Theme.of(context).textTheme.displaySmall);
}
/// Set the Style to use [headlineLarge].
Text headingLarge(BuildContext context) {
return this.setStyle(Theme.of(context).textTheme.headlineLarge);
}
/// Set the Style to use [headlineMedium].
Text headingMedium(BuildContext context) {
return this.setStyle(Theme.of(context).textTheme.headlineMedium);
}
/// Set the Style to use [headlineSmall].
Text headingSmall(BuildContext context) {
return this.setStyle(Theme.of(context).textTheme.headlineSmall);
}
/// Set the Style to use [titleLarge].
Text titleLarge(BuildContext context) {
return this.setStyle(Theme.of(context).textTheme.titleLarge);
}
/// Set the Style to use [titleMedium].
Text titleMedium(BuildContext context) {
return this.setStyle(Theme.of(context).textTheme.titleMedium);
}
/// Set the Style to use [titleSmall].
Text titleSmall(BuildContext context) {
return this.setStyle(Theme.of(context).textTheme.titleSmall);
}
/// Set the Style to use [bodyLarge].
Text large(BuildContext context) {
return this.setStyle(Theme.of(context).textTheme.bodyLarge);
}
/// Set the Style to use [bodyMedium].
Text medium(BuildContext context) {
return this.setStyle(Theme.of(context).textTheme.bodyMedium);
}
/// Set the Style to use [bodySmall].
Text small(BuildContext context) {
return this.setStyle(Theme.of(context).textTheme.bodySmall);
}
/// Make the font bold.
Text fontWeightBold() {
return copyWith(style: TextStyle(fontWeight: FontWeight.bold));
}
/// Make the font light.
Text fontWeightLight() {
return copyWith(style: TextStyle(fontWeight: FontWeight.w300));
}
/// Change the [style].
Text setStyle(TextStyle? style) => copyWith(style: style);
/// Sets the color from your [ColorStyles] or [Color].
Text setColor(
BuildContext context, Color Function(ColorStyles color) newColor, {String? themeId}) {
return copyWith(style: TextStyle(color: newColor(ThemeColor.get(context, themeId: themeId))));
}
/// Aligns text to the left.
Text alignLeft() {
return copyWith(textAlign: TextAlign.left);
}
/// Aligns text to the right.
Text alignRight() {
return copyWith(textAlign: TextAlign.right);
}
/// Aligns text to the center.
Text alignCenter() {
return copyWith(textAlign: TextAlign.center);
}
/// Aligns text to the center.
Text setMaxLines(int maxLines) {
return copyWith(maxLines: maxLines);
}
/// Change the [fontFamily].
Text setFontFamily(String fontFamily) =>
copyWith(style: TextStyle(fontFamily: fontFamily));
/// Helper to apply changes.
Text copyWith(
{Key? key,
StrutStyle? strutStyle,
TextAlign? textAlign,
TextDirection? textDirection = TextDirection.ltr,
Locale? locale,
bool? softWrap,
TextOverflow? overflow,
double? textScaleFactor,
int? maxLines,
String? semanticsLabel,
TextWidthBasis? textWidthBasis,
TextStyle? style}) {
return Text(this.data ?? "",
key: key ?? this.key,
strutStyle: strutStyle ?? this.strutStyle,
textAlign: textAlign ?? this.textAlign,
textDirection: textDirection ?? this.textDirection,
locale: locale ?? this.locale,
softWrap: softWrap ?? this.softWrap,
overflow: overflow ?? this.overflow,
textScaleFactor: textScaleFactor ?? this.textScaleFactor,
maxLines: maxLines ?? this.maxLines,
semanticsLabel: semanticsLabel ?? this.semanticsLabel,
textWidthBasis: textWidthBasis ?? this.textWidthBasis,
style: style != null ? this.style?.merge(style) ?? style : this.style);
}
}