【发布时间】:2019-09-24 00:41:10
【问题描述】:
我正在使用 Flutter Table 小部件。我希望根据某些条件隐藏其中一个表格行。
我在 Tablerow 上尝试过 Visibility 小部件,但它不允许。我还尝试了布尔条件,例如。布尔? Tablerow(...) : Tablerow(),它似乎不能正常工作,因为它给出了 null 异常 - 可能 Tablerow 是空的。
child: Table(
border: TableBorder.all(width: 1.0, color: Colors.black),
children: [
TableRow(
children: [
TableCell(
child: Row(
children: <Widget>[
new Padding(
padding: const EdgeInsets.all(5.0),
child: new Text('ID1'),
),
]
)
),
TableCell(
child: Row(
children: <Widget>[
new Padding(
padding: const EdgeInsets.all(5.0),
child: new Text('Name1'),
),
]
)
)
]
),
TableRow(
children: [
TableCell(
child: Row(
children: <Widget>[
new Padding(
padding: const EdgeInsets.all(5.0),
child: new Text('ID2'),
),
]
)
),
TableCell(
child: Row(
children: <Widget>[
new Padding(
padding: const EdgeInsets.all(5.0),
child: new Text('Name2'),
),
]
)
)
]
),
TableRow(
children: [
TableCell(
child: Row(
children: <Widget>[
new Padding(
padding: const EdgeInsets.all(5.0),
child: new Text('ID3'),
),
]
)
),
TableCell(
child: Row(
children: <Widget>[
new Padding(
padding: const EdgeInsets.all(5.0),
child: new Text('Name3'),
),
]
)
)
]
),
],
)
更新:
bool_row ? TableRow(
children: [
TableCell(
child: Row(
children: <Widget>[
new Padding(
padding: const EdgeInsets.all(5.0),
child: new Text('ID2'),
),
]
)
),
TableCell(
child: Row(
children: <Widget>[
new Padding(
padding: const EdgeInsets.all(5.0),
child: new Text('Name2'),
),
]
)
)
]
) : TableRow(),
使用布尔方法,bool_row 为 false,第二个条件“TableRow()”抛出错误:
: 在 null 上调用了方法 'any'。
:接收者:空
:尝试调用:any(Closure: (Widget) => bool)
我不知道如何产生一个空的不可见的 TableRow。
根据上面的代码,如果我想隐藏或将第二行设置为不可见。我怎样才能实现它?
提前致谢!
【问题讨论】:
-
你是如何使用布尔条件的?你用 setState 了吗?
-
我已经更新了关于如何使用布尔方法的代码。第二个条件,我不知道如何使 TableRow 不可见或为空。它会抛出错误。