【发布时间】:2021-11-30 13:00:46
【问题描述】:
我正在构建一个健身应用程序(图片在这里:Fitness App example ) 用户可以在其中记录他们的集合。在我的应用程序中使用可关闭的小部件时遇到问题。滑动删除功能会发送以下异常:已关闭的可关闭小部件仍然是树的一部分
滑动删除单个集合时,我仍然需要保留用户放入其他集合的信息。我认为这是密钥的问题,但是我已经尝试过 UniqueKey()(它会重置所有其他输入字段)和下面的示例。
如何使用dismissible 删除单个集合并仍保留其他集合的其余用户数据?谢谢。
late List count = [0];
ListView.builder(
shrinkWrap: true,
itemCount: _count.length,
itemBuilder: (context, index) {
// Create a new variable to display the set
int setNumber = index + 1;
return Dismissible(
key: ValueKey(_count[index]),
background: _swipeStyle(),
onDismissed: (direction) {
// Remove the item from the data source.
setState(() {
_count.removeAt(index);
});
},
child: Row(
children: [
Expanded(flex: 1, child: Text('Set $setNumber')),
Expanded(flex: 2, child: _buildWeight(index)),
const SizedBox(
width: 24.0,
),
Expanded(flex: 2, child: _buildReps(index)),
],
),
);
},
),
【问题讨论】:
-
_count的类型是什么? -
@caiopo 我已经更新了代码。这是一个列表