我想知道如果我有这种状态条件,是否有办法避免将操作设置为空:
appBar: AppBar(
title: provider.appBarTitle,
actions: provider.editState == EditState.inactive
? [
IconButton(
onPressed: provider.activateEditableState,
icon: const Icon(Icons.edit))
]
: null)
如果你返回一个空列表而不是
null
应该没问题。
appBar: AppBar(
title: provider.appBarTitle,
actions: [
if (provider.editState == EditState.inactive)
IconButton(
onPressed: provider.activateEditableState,
icon: const Icon(Icons.edit),
),
],
),
appBar: AppBar(
title: provider.appBarTitle,
actions:[
provider.editState == EditState.inactive
?
IconButton(
onPressed: provider.activateEditableState,
icon: const Icon(Icons.edit))
:
// return a Container instead of null
Container(),
// other actions...
]