flutter - 向 TableRow 添加填充
问题描述
我正在尝试向我的表格行添加填充。
这就是我所拥有的:
var list = (report['items'] as List)
.map((item) =>
TableRow(children: [
Text(item['place']),
Text(item['type']),
Text(item['producer']),
Text(item['serial_number']),
Text(formatter.format(DateTime.parse(item['next_check_date']))
.toString()),
Text(item['test_result']),
Text(item['comments']),
]))
.toList();
这就是我试图做的:
var list = (report['items'] as List)
.map((item) =>
Container(
padding: EdgeInsets.only(10.0),
child: TableRow(children: [
Text(item['place']),
Text(item['type']),
Text(item['producer']),
Text(item['serial_number']),
Text(formatter.format(DateTime.parse(item['next_check_date']))
.toString()),
Text(item['test_result']),
Text(item['comments']),
])))
.toList();
但是我收到了这个错误(在添加了带有填充的容器之后):
The argument type 'TableRow' can't be assigned to the parameter type 'Widget'.
如何向我的 Table / TableRows 添加填充?
解决方案
我发现在这种情况下工作(当您想在表格中的行之间添加填充时)是用Text
Widget包装Container
并将padding
属性添加到您的元素之一(这可能是“最高”的元素)并将alignment
属性用于其他容器,其中您需要在行内对齐文本。我的示例将如下所示(抱歉图像模糊):
Padding(
padding: const EdgeInsets.fromLTRB(32.0, 0.0, 32.0, 0.0),
child: Table(
columnWidths: {
0: FractionColumnWidth(.75),
},
children: achievementList
.map(
(achivement) => TableRow(
children: [
Container(
padding: EdgeInsets.only(bottom: 10.0),
child: Text(
achivement.title,
style: TextStyle(
fontSize: 16.0,
),
),
),
Container(
alignment: Alignment.centerRight,
child: Text(
achivement.dateString,
style: TextStyle(
fontSize: 16.0,
),
),
),
],
),
)
.toList(),
),
),
achievementList
我的对象在哪里title
和dateString
。Text
通过首先用Widget包装Container
并赋予第一个Container
属性padding: EgeInsets.only(bottom: 10.0),
,它会为整行提供填充。
推荐阅读
- node.js - 如何在首先需要填充的嵌套对象上使用光标?
- python - formaction 中的插槽验证不起作用
- linux - 使用 Python 通过 Serial 读取不固定数量的字节
- javascript - 在单个文件中为浏览器捆绑 Typescript 3.2.4
- linux - 如何在自定义 linux 上添加启动画面(特别是树莓派)
- ios - 读取 iOS 上文档存储(“将文档和数据存储在”)设置的值
- macos - 如何杀死一个绝对不会死的进程,OSX终端
- php - 如何使用 bitnami/linux 终端为我的 php 应用程序更改 php 版本
- http - sinatra 的 send_file 决定使用什么内容类型的过程是什么?
- r - 在美元符号之前使用减号正确格式化负货币值