Skip to content

Commit b9b3360

Browse files
committed
修改Cell布局溢出问题
1 parent c126ab3 commit b9b3360

6 files changed

Lines changed: 69 additions & 33 deletions

File tree

tdesign-component/example/assets/code/cell._buildTestContent.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ Widget _buildTestContent(BuildContext context) {
33
return const TDCell(
44
title: '这是标题,非常长的标题',
55
note: '这是一个很长很长的note字段,测试长内容,你说这内容长不长!',
6+
noteMaxLine: 2,
7+
noteMaxWidth: 200,
68
arrow: true,
79
);
810
}

tdesign-component/example/assets/code/popover._buildNCustomPopover.txt

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11

22
Widget _buildNCustomPopover(BuildContext context) {
3+
var textStyle = TextStyle(
4+
color: theme == TDPopoverTheme.light
5+
? TDTheme.of(context).fontGyColor1
6+
: TDTheme.of(context).fontWhColor1);
37
return LayoutBuilder(
48
builder: (_, constrains) {
59
return TDButton(
@@ -12,8 +16,25 @@
1216
padding: const EdgeInsets.all(0),
1317
theme: theme,
1418
width: 108,
15-
height: 148,
16-
contentWidget: _buildPopoverList(context),
19+
height: 152,
20+
contentWidget: Column(
21+
children: [
22+
Container(
23+
padding: const EdgeInsets.symmetric(vertical: 12, horizontal: 24),
24+
child: TDText('选项1', style: textStyle),
25+
),
26+
const TDDivider(height: 0.5),
27+
Container(
28+
padding: const EdgeInsets.symmetric(vertical: 12, horizontal: 24),
29+
child: TDText('选项2', style: textStyle),
30+
),
31+
const TDDivider(height: 0.5),
32+
Container(
33+
padding: const EdgeInsets.symmetric(vertical: 12, horizontal: 24),
34+
child: TDText('选项3', style: textStyle),
35+
),
36+
],
37+
),
1738
);
1839
},
1940
);

tdesign-component/example/lib/page/td_cell_page.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class TDCellPage extends StatelessWidget {
2323
],
2424
test: const [
2525
ExampleItem(desc: '自定义内边距-padding', builder: _buildPadding),
26-
ExampleItem(desc: '长标题、内容', builder: _buildTestContent),
26+
ExampleItem(desc: '长标题、内容,指定note宽度', builder: _buildTestContent),
2727
],
2828
);
2929
}
@@ -167,6 +167,8 @@ Widget _buildTestContent(BuildContext context) {
167167
return const TDCell(
168168
title: '这是标题,非常长的标题',
169169
note: '这是一个很长很长的note字段,测试长内容,你说这内容长不长!',
170+
noteMaxLine: 2,
171+
noteMaxWidth: 200,
170172
arrow: true,
171173
);
172174
}

tdesign-component/example/lib/page/td_popover_page.dart

Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -235,35 +235,12 @@ class _TDPopoverPage extends State<TDPopoverPage> {
235235
);
236236
}
237237

238-
// @todo
239-
Widget _buildPopoverList(BuildContext context) {
238+
@Demo(group: 'popover')
239+
Widget _buildNCustomPopover(BuildContext context) {
240240
var textStyle = TextStyle(
241241
color: theme == TDPopoverTheme.light
242242
? TDTheme.of(context).fontGyColor1
243243
: TDTheme.of(context).fontWhColor1);
244-
245-
return Column(
246-
children: [
247-
Container(
248-
padding: const EdgeInsets.symmetric(vertical: 12, horizontal: 24),
249-
child: TDText('选项1', style: textStyle),
250-
),
251-
const TDDivider(height: 0.5),
252-
Container(
253-
padding: const EdgeInsets.symmetric(vertical: 12, horizontal: 24),
254-
child: TDText('选项2', style: textStyle),
255-
),
256-
const TDDivider(height: 0.5),
257-
Container(
258-
padding: const EdgeInsets.symmetric(vertical: 12, horizontal: 24),
259-
child: TDText('选项3', style: textStyle),
260-
),
261-
],
262-
);
263-
}
264-
265-
@Demo(group: 'popover')
266-
Widget _buildNCustomPopover(BuildContext context) {
267244
return LayoutBuilder(
268245
builder: (_, constrains) {
269246
return TDButton(
@@ -276,8 +253,25 @@ class _TDPopoverPage extends State<TDPopoverPage> {
276253
padding: const EdgeInsets.all(0),
277254
theme: theme,
278255
width: 108,
279-
height: 148,
280-
contentWidget: _buildPopoverList(context),
256+
height: 152,
257+
contentWidget: Column(
258+
children: [
259+
Container(
260+
padding: const EdgeInsets.symmetric(vertical: 12, horizontal: 24),
261+
child: TDText('选项1', style: textStyle),
262+
),
263+
const TDDivider(height: 0.5),
264+
Container(
265+
padding: const EdgeInsets.symmetric(vertical: 12, horizontal: 24),
266+
child: TDText('选项2', style: textStyle),
267+
),
268+
const TDDivider(height: 0.5),
269+
Container(
270+
padding: const EdgeInsets.symmetric(vertical: 12, horizontal: 24),
271+
child: TDText('选项3', style: textStyle),
272+
),
273+
],
274+
),
281275
);
282276
},
283277
);

tdesign-component/lib/src/components/cell/td_cell.dart

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ class TDCell extends StatefulWidget {
2424
this.leftIconWidget,
2525
this.note,
2626
this.noteWidget,
27+
this.noteMaxWidth,
28+
this.noteMaxLine = 1,
2729
this.required = false,
2830
this.title,
2931
this.titleWidget,
@@ -80,6 +82,12 @@ class TDCell extends StatefulWidget {
8082
/// 说明文字组件
8183
final Widget? noteWidget;
8284

85+
/// 说明文字组件 最大宽度,超过部分显示省略号,防止文字溢出
86+
final double? noteMaxWidth;
87+
88+
/// 说明文字组件 最大行数
89+
final int noteMaxLine;
90+
8391
/// 是否显示表单必填星号
8492
final bool? required;
8593

@@ -211,12 +219,21 @@ class _TDCellState extends State<TDCell> {
211219
),
212220
Wrap(
213221
spacing: theme.spacer4,
214-
// crossAxisAlignment: WrapCrossAlignment.center,
222+
crossAxisAlignment: WrapCrossAlignment.center,
215223
children: [
216224
if (widget.noteWidget != null)
217225
widget.noteWidget!
218226
else if (widget.note?.isNotEmpty ?? false)
219-
TDText(widget.note!, style: style.noteStyle),
227+
ConstrainedBox(
228+
constraints: BoxConstraints(
229+
maxWidth: widget.noteMaxWidth ??
230+
MediaQuery.of(context).size.width - 84),
231+
child: TDText(
232+
widget.note!,
233+
style: style.noteStyle,
234+
overflow: TextOverflow.ellipsis,
235+
maxLines: widget.noteMaxLine,
236+
)),
220237
if (widget.rightIconWidget != null)
221238
widget.rightIconWidget!
222239
else if (widget.rightIcon != null)

tdesign-component/lib/src/components/upload/td_upload.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,7 @@ class _TDUploadState extends State<TDUpload> {
498498
color: Colors.white,
499499
)),
500500
Padding(
501-
padding: const EdgeInsets.only(top: 4),
501+
padding: const EdgeInsets.only(top: 2),
502502
child: TDText(
503503
displayText,
504504
textColor: Colors.white,

0 commit comments

Comments
 (0)