gpt4 book ai didi

Flutter DataTable 截断文本

转载 作者:行者123 更新时间:2023-12-02 19:46:30 25 4
gpt4 key购买 nike

我正在编写一个 flutter 应用程序并尝试插入一个数据表。我遇到了文本被截断但没有溢出到新行的问题。它会在我使用的设备上执行 2 行而不是 3 行。我尝试在 Expanded 小部件中添加文本,但这不起作用并抛出“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.'),
];

这是它的外观图片: Truncated DataTable Row

最佳答案

三到四件事要申请-

  1. DataCell 小部件中,您需要使用 ConstrainedBox。在 ConstrainedBox 中指定 maxWidthminWidth 以覆盖高度。

  2. Datacell 小部件的子级中,如果文本小部件溢出:TextOverflow.visible,softWrap:true,

  3. DataTable 小部件中提供 dataRowHeight 属性。

关于Flutter DataTable 截断文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59157799/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com