Flutter DataTable截断文本

mlnl4t2r  于 2023-10-22  发布在  Flutter
关注(0)|答案(3)|浏览(134)

我正在编写一个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.'),
];

这是它的样子:

cgvd09ve

cgvd09ve1#

三到四件事适用-
1.在DataCell小部件中,您需要使用ConstrainedBox。在ConstrainedBox中,指定maxWidthminWidth以覆盖高度。
1.在Datacell小部件的子部件中,如果文本小部件给予溢出:TextOverflow .visible,softWrap:真的,
1.在DataTable小部件中给予dataRowHeight属性。

qybjjes1

qybjjes12#

数据表很难处理。我只是结束了使用带有分隔符的列表视图。

4si2a6ki

4si2a6ki3#

这就是我在右边一栏中所做的,右边一栏有很长的文字。如果maxRows允许,该行现在将显示所有文本。我使用媒体查询将右列maxWidth设置为屏幕宽度的75%。

final dataTable = DataTable(
      dataRowMaxHeight: double.infinity,
      horizontalMargin: 6,
      columns: const [

------------

DataCell(
              ConstrainedBox(
                constraints: BoxConstraints(
                    maxWidth: rightColumnMaxWidth, maxHeight: double.infinity),
                child: Text(

相关问题