我想在flutter中更改ExpansionTile标题,因此当tile展开时,标题为“less”,当tile未展开时,标题为“more”...
我已经尝试使用
ExpansionTileController.isExpanded? "less": "more"
,但出现错误:
Failed assertion: line 49 pos 12: '_state != null': is not true.
在构建小部件上方创建一个 bool var
bool _customTileExpanded = true;
将条件添加到标题文本并使用
onExpansionChanged
属性来更改状态。
ExpansionTile(
title: Text(_customTileExpanded ? 'ExpansionTile more' : 'less'),
subtitle: const Text('Custom expansion arrow icon'),
children: const <Widget>[
ListTile(title: Text('This is tile number 2')),
],
onExpansionChanged: (bool expanded) {
setState(() {
_customTileExpanded = expanded;
});
},
),