firebase - Flutter: Only the first item in the Stack is dismissible
问题描述
I am cracking my head over this one. I want all my items in my stack to be dismissible. I am able to show all my items but only the first item is dismissible. Why?
Here is the code snippet:
Widget build(BuildContext context) {
return new StreamBuilder <QuerySnapshot>(
stream: Firestore.instance.collection('records').document(uid).collection("pdrecords").snapshots(),
builder: (BuildContext context, AsyncSnapshot<QuerySnapshot> snapshot) {
if (snapshot.hasData) {
print("snapShot call");
final int recordCount = snapshot.data.documents.length;
print("got data. records: $recordCount");
if (recordCount >0) {
return new Stack (
alignment: listSlideAnimation.value,
children:
snapshot.data.documents.map((DocumentSnapshot document) {
count = count + multiplyFactor; print("count: $count");
index ++;
//print("data: ${document.data}");
return Dismissible(
resizeDuration: null,
dismissThresholds: _dismissThresholds(),
//background: new LeaveBehindView(),
key: ObjectKey(document.documentID) ,
onDismissed: (DismissDirection direction) {
direction == DismissDirection.endToStart
? print("favourite")
: print("remove");
// Do stuff
},
child:
new ListPDRecord(
id: document.documentID,
margin: listSlidePosition.value * count, //new EdgeInsets.only(bottom: 80.0) * count, //listSlidePosition.value * 5.5,
width: listTileWidth.value,
date: document["date"],
),
);
}).toList(),
);
} else {
return NoDataListData();
}
} else {
// No data
return new NoDataListData();
}
});
}
}
I suspect is the KEY and I have tried many variations of different keys such as manually increment of index, etc. but still, only the first item is dismissible.
Any pointers?
解决方案
经过多轮实验,我解决了以下几点:
- 您可以像上面一样在堆栈内生成小部件列表,但是
- 可解雇可能不会起作用,因为堆栈中的每个项目都有不同的边距,而顶部的边距最大。
- 最后,我必须将 Stack 更改为 ListView 并且可解雇现在适用于每个项目。
推荐阅读
- r - 将 for 循环重写为应用程序,除了许多循环之外,它没有一组预定义的值可以循环
- jquery - jQuery Ajax 完成事件响应为空
- d3.js - 带有月份名称的nvd3折线图xaxis不起作用
- r - R根据另一列按组设置值
- angular - Angular CLI 版本和 Angular Core 版本之间的兼容性?
- c# - 动态加载 dll 时找不到由 URI '/mydll;component/subfolder/mainwindow.xaml' 标识的资源
- css - 为什么我的复选框在它的父级中没有垂直对齐?
- reactjs - 当数组的 setState 在承诺链的末尾时,对象作为 React 子项无效
- azure - Add-TeamUser Powershell Teams 不会影响 Teams 应用 [已解决 - 关闭]
- c# - 在鼠标 3d 项目后旋转玩家的 Rigidboy 并创建计时器文本