我正在编写一个flutter应用程序,并试图插入一个DataTable。我有问题的文本得到截断虽然没有溢出到一个新的一行。它会做2行,但不是3在我的设备上。我尝试在扩展的小部件中添加文本,但这不起作用,并引发“ParentDataWidget的使用不正确”。有什么方法可以让很长的文本跨越3,4,或5+行?下面是代码。
import 'package:flutter/material.dart';
class ClaimTypeTable extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Container(
child: new DataTableWidgetExtract(),
);
}
}
class DataTableWidgetExtract extends StatelessWidget {
const DataTableWidgetExtract({
Key key,
}) : super(key: key);
@override
Widget build(BuildContext context) {
return DataTable(
columnSpacing: 10.0,
horizontalMargin: 5,
columns: <DataColumn>[
DataColumn(label: Text('Type')),
DataColumn(label: Text('Description',)),
],
rows: claimTypesList
.map(
(itemRow) => DataRow(
cells: [
DataCell(Text(itemRow.shortName),
showEditIcon: false, placeholder: false, onTap: () {
print('We tapped it - ${itemRow.shortName}');
}),
DataCell(
Padding(
padding: const EdgeInsets.all(8.0),
child: Text(itemRow.description,),
),
showEditIcon: false,
placeholder: false,
),
],
),
)
.toList(),
);
}
}
class ClaimType {
String shortName;
String description;
ClaimType({
this.shortName,
this.description,
});
}
var claimTypesList = <ClaimType>[
ClaimType(
shortName: 'Fire',
description:
'There was a fire. The fire department may or may not have been called, but shit got burnt up.',
),
ClaimType(
shortName: 'Water',
description:
'Water damage. Examples of typical water damage include: burst pipe, broken water heater, or faulty toilet.',
),
ClaimType(
shortName: 'Wind',
description:
'There is non-hurricane wind damage to your residence. If it is related to a hurricane, please select Hurricane as the claim type instead. This one is really long and gets truncated.',
),
ClaimType(
shortName: 'Crime',
description:
'Vandalism, theft, or other criminal behavior that resulted in a loss.'),
];
这是它的样子:
3条答案
按热度按时间cgvd09ve1#
三到四件事适用-
1.在
DataCell
小部件中,您需要使用ConstrainedBox
。在ConstrainedBox
中,指定maxWidth
和minWidth
以覆盖高度。1.在
Datacell
小部件的子部件中,如果文本小部件给予溢出:TextOverflow
.visible,softWrap:真的,1.在
DataTable
小部件中给予dataRowHeight
属性。qybjjes12#
数据表很难处理。我只是结束了使用带有分隔符的列表视图。
4si2a6ki3#
这就是我在右边一栏中所做的,右边一栏有很长的文字。如果
maxRows
允许,该行现在将显示所有文本。我使用媒体查询将右列maxWidth
设置为屏幕宽度的75%。