【发布时间】:2020-11-11 11:28:57
【问题描述】:
如您所见,我正在使用 Flutter 的 ReorderableListView 小部件拖动任务。
onReorder 可以上下拖动任务。但是,当我关闭应用程序时,所有任务都会按照默认顺序进行。
这是因为我从 CloudFireStore 获取的数据没有改变它的顺序,而是在我的拖动中更新的方式。
谁能帮帮我,我如何更新存储为 Cloud FireStore 中文档的任务位置,这样当我关闭应用程序并再次打开它时,它会显示新的更新位置而不是旧的任务位置
代码:
child: StreamBuilder(
stream: FirebaseFirestore.instance
.collection("Tasks")
.doc(_email)
.collection("User_Tasks_List")
.snapshots(),
builder: (context, snapshot) {
if (!snapshot.hasData) return const Text("Loading!...");
_docs = snapshot.data.documents;
return Theme(
data: ThemeData(canvasColor: Colors.transparent),
child: ReorderableListView(
children: _docs
.map((e) => InkWell(
key: ObjectKey(e),
onTap: () => _popupDialog(context, e),
onDoubleTap: () => FirebaseFirestore
.instance
.runTransaction(
(transaction) async {
transaction.delete(e.reference);
Fluttertoast.showToast(
msg: "Task has been deleted!");
}),
child: ViewHolder(e)))
.toList(),
onReorder: onReorder),
);
}),
【问题讨论】:
标签: flutter google-cloud-firestore reorderable-list