-
Notifications
You must be signed in to change notification settings - Fork 121
/
Copy pathtd_text_page.dart
188 lines (172 loc) · 5.7 KB
/
td_text_page.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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
import 'package:flutter/material.dart';
import 'package:tdesign_flutter/tdesign_flutter.dart';
import '../../annotation/demo.dart';
import '../../base/example_widget.dart';
class TDTextPage extends StatelessWidget {
const TDTextPage({Key? key}) : super(key: key);
final exampleTxt = '文本Text';
@override
Widget build(BuildContext context) {
// debugPaintBaselinesEnabled = true;
return ExamplePage(
padding: const EdgeInsets.all(8),
title: tdTitle(context),
exampleCodeGroup: 'text',
children: [
ExampleModule(title: '使用示例', children: [
ExampleItem(desc: '系统Text:', builder: _buildSystemText),
ExampleItem(desc: '普通TDText:', builder: _buildNormalTDText),
ExampleItem(desc: '指定常用属性:', builder: _buildGeneralProp),
ExampleItem(
desc: 'style覆盖textColor,不覆盖font:',
builder: _buildStyleCoverColor),
ExampleItem(
desc: 'style覆盖textColor和font:',
builder: _buildStyleCoverColorAndFont),
ExampleItem(desc: 'TDText.rich测试:', builder: _buildRichText),
ExampleItem(desc: '获取系统Text:', builder: _getSystemText),
ExampleItem(
desc: '中文居中:(带有英文可能不居中)', builder: _buildVerticalCenterText),
ExampleItem(desc: '自定义内部padding:', builder: _buildCustomPaddingText),
]),
],
test: [
ExampleItem(
desc: '中文居中-系统字体',
builder: (context){
return Container(
color: TDTheme.of(context).brandFocusColor,
child: Text(exampleTxt),
);
}),
ExampleItem(
desc: '中文居中-TD字体',
builder: (context){
return Container(
color: TDTheme.of(context).brandFocusColor,
child: TDText(exampleTxt, forceVerticalCenter: true,),
);
}),
],
);
}
@Demo(group: 'text')
Widget _buildNormalTDText(BuildContext context) {
return TDText(
exampleTxt,
);
}
@Demo(group: 'text')
Widget _buildSystemText(BuildContext context) {
return Text(
exampleTxt,
);
}
@Demo(group: 'text')
Widget _buildGeneralProp(BuildContext context) {
return TDText(
exampleTxt,
font: TDTheme.of(context).fontHeadlineLarge,
textColor: TDTheme.of(context).brandNormalColor,
backgroundColor: TDTheme.of(context).brandFocusColor,
);
}
@Demo(group: 'text')
Widget _buildStyleCoverColor(BuildContext context) {
return TDText(
exampleTxt,
font: TDTheme.of(context).fontBodyLarge,
textColor: TDTheme.of(context).brandNormalColor,
style: TextStyle(color: TDTheme.of(context).errorNormalColor),
);
}
@Demo(group: 'text')
Widget _buildStyleCoverColorAndFont(BuildContext context) {
return TDText(
exampleTxt,
font: TDTheme.of(context).fontBodyLarge,
textColor: TDTheme.of(context).brandNormalColor,
);
}
@Demo(group: 'text')
Widget _buildRichText(BuildContext context) {
return TDText.rich(
TextSpan(children: [
TDTextSpan(
text: 'TDTextSpan1',
font: TDTheme.of(context).fontTitleExtraLarge,
textColor: TDTheme.of(context).warningNormalColor,
isTextThrough: true,
lineThroughColor: TDTheme.of(context).brandNormalColor,
style: TextStyle(color: TDTheme.of(context).errorNormalColor)),
TextSpan(
text: 'TextSpan2',
style: TextStyle(
fontSize: 14, color: TDTheme.of(context).brandNormalColor)),
const WidgetSpan(
child: Icon(
TDIcons.setting,
size: 24,
)),
]),
font: TDTheme.of(context).fontBodyLarge,
textColor: TDTheme.of(context).brandNormalColor,
style:
TextStyle(color: TDTheme.of(context).errorNormalColor, fontSize: 32),
);
}
@Demo(group: 'text')
Widget _getSystemText(BuildContext context) {
return TDText(
exampleTxt,
backgroundColor: TDTheme.of(context).brandFocusColor,
).getRawText(context: context);
}
@Demo(group: 'text')
Widget _buildVerticalCenterText(BuildContext context) {
return TDText(
'中华人民共和国腾讯科技',
// font: Font(size: 100, lineHeight: 100),
forceVerticalCenter: true,
backgroundColor: TDTheme.of(context).brandFocusColor,
);
}
@Demo(group: 'text')
Widget _buildCustomPaddingText(BuildContext context) {
return TDTextConfiguration(
paddingConfig: CustomTextPaddingConfig(),
child: const CustomPaddingText(),
);
}
}
/// 自定义控件,内部的context可拿到外部TDTextConfiguration的配置信息
class CustomPaddingText extends StatelessWidget {
const CustomPaddingText({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Column(
mainAxisSize: MainAxisSize.min,
children: [
TDText(
'中华人民共和国腾讯科技fgjpqy',
forceVerticalCenter: true,
backgroundColor: TDTheme.of(context).brandFocusColor,
),
TDText(
'English',
font: TDTheme.of(context).fontHeadlineLarge,
forceVerticalCenter: true,
backgroundColor: TDTheme.of(context).brandFocusColor,
),
],
);
}
}
/// 重写内部padding方法
class CustomTextPaddingConfig extends TDTextPaddingConfig {
@override
EdgeInsetsGeometry getPadding(String? data, double fontSize, double height) {
var supperPadding = super.getPadding(data, fontSize, height);
return EdgeInsets.only(left: 30, top: supperPadding.vertical.toDouble());
}
}