【问题标题】:Flutter single `DataCell` color颤动单个`DataCell`颜色
【发布时间】:2022-08-17 19:15:50
【问题描述】:

我正在尝试做类似于 Excel/Google Sheets/etc 可以做的事情,并将背景颜色添加到我的 DataTable 上的一个 DataCell。我只能找到一个参考来设置整个DataRow,而不仅仅是一个单元格。有谁知道怎么做?

API参考:

到目前为止我已经尝试过:

DataCell(
  FittedBox(
    child: test
        ? ColoredBox(
            color: Colors.orange,
            child: Center(
              child: Text(variable),
            ),
          )
        : Center(
            child: Text(variable),
          ),
  ),
),

我得到了什么:

目标:

    标签: flutter dart user-interface


    【解决方案1】:

    我通过从小部件树中删除 FittedBox 解决了这个问题。

    DataCell(
      test
          ? Padding(
              padding: const EdgeInsets.symmetric(vertical: 5),
              child: ColoredBox(
                color: Colors.orange,
                child: Center(
                  child: Text(variable, style: style),
                ),
              ),
            )
          : Center(
              child: Text(variable, style: style),
            ),
    ),
    

    最终结果:

    PS:这里的Padding 只是为了使颜色保持在VerticalDivider 缩进(在侧面)内。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-02-20
      • 1970-01-01
      • 2020-10-23
      • 2020-02-25
      • 2022-10-07
      • 1970-01-01
      • 2021-01-10
      相关资源
      最近更新 更多