首页 > 解决方案 > 如何仅在 TableWidget 的 colmun 中设置 backgroundColor?

问题描述

我只想在表格的左侧添加颜色,但我尝试了各种方法,但它们都不起作用,如下图所示。我怎样才能做到这一点?

final informations = [
    {"title": "e-mail", "text": "xxxxxx@xxxx"},
    {"title": "phone number", "text": "111111111111"},
    {"title": "other", "text": "nothingnothingnothingnothingnothingnothingnothingnothingnothingnothingnothing"}
  ];

List<TableRow> getWidgets(List<Map<String, String>> infos) {
  final List<TableRow> listed = <TableRow>[];
  for (int i = 0; i < infos.length; i++) {
    listed.add(TableRow(children: [
      Container(color: Colors.blue.shade400,child: Text(infos[i]["title"])),
      Container(child: Text(infos[i]["text"]),)
    ]));
  }
  return listed;
}

截屏

谢谢。

标签: flutterflutter-layout

解决方案


你可以尝试这样的事情:

final List<Map<String, String>> informations = [
    {"title": "e-mail", "text": "xxxxxx@xxxx"},
    {"title": "phone number", "text": "111111111111"},
    {
      "title": "other",
      "text":
          "nothingnothingnothingnothingnothingnothingnothingnothingnothingnothingnothing"
    }
  ];
  List<TableRow> getWidgets(List<Map<String, String>> infos) {
    final List<TableRow> listed = <TableRow>[];
    for (int i = 0; i < infos.length; i++) {
      listed.add(TableRow(children: [
        TableCell(
            verticalAlignment: TableCellVerticalAlignment.fill,
            child: Container(
                color: Colors.blue.shade400, child: Text(infos[i]["title"]))),
        TableCell(
          child: Container(child: Text(infos[i]["text"])),
        )
      ]));
    }
    return listed;
  }

推荐阅读