List flift/Dart/Firestore-在动画列表中按天分组文档
如何按天在用户之间分组消息?到目前为止,它只是添加到列表中并按天排序,但我似乎无法在过去几天发送的消息之间添加间隔。列表显示在List flift/Dart/Firestore-在动画列表中按天分组文档,list,dart,flutter,google-cloud-firestore,grouping,List,Dart,Flutter,Google Cloud Firestore,Grouping,如何按天在用户之间分组消息?到目前为止,它只是添加到列表中并按天排序,但我似乎无法在过去几天发送的消息之间添加间隔。列表显示在AnimatedList()中 代码: List<Message> _messages = []; ... _initMessages() { // Being called in the initState APIs().chats.messages( chatID: widget.chat.chatID, onEmpty: ()
AnimatedList()中
代码:
List<Message> _messages = [];
...
_initMessages() { // Being called in the initState
APIs().chats.messages(
chatID: widget.chat.chatID,
onEmpty: () {
if (mounted)
setState(() {
this._isLoading = false;
});
},
onAdded: (m) {
if (mounted)
setState(() {
if (m.type == 'Image') {
m.message = NetworkImage(m.message);
}
this._messages.add(m);
this._messages.sort((a, b) => a.createdAt.compareTo(b.createdAt));
if (mounted) this._listKey.currentState.insertItem(this._messages.length, duration: Duration(milliseconds: 500));
this._isLoading = false;
});
},
onModified: (m) {
int i = this._messages.indexWhere((message) => message.messageID == m.messageID);
if (mounted)
setState(() {
this._messages[i] = m;
this._messages.sort((a, b) => a.createdAt.compareTo(b.createdAt));
this._isLoading = false;
});
},
onRemoved: (m) {
int i = this._messages.indexWhere((message) => message.messageID == m.messageID);
if (mounted)
setState(() {
this._messages.removeAt(i);
this._messages.sort((a, b) => a.createdAt.compareTo(b.createdAt));
this._isLoading = false;
});
},
onFailure: (e) {
print(e);
});
}
这是一个分为两部分的问题,将文档按天分组,并尝试使其在动画列表中工作。日期为Firestore时间戳类型
[VERBOSE-2:ui_dart_state.cc(148)] Unhandled Exception: 'package:flutter/src/widgets/animated_list.dart': Failed assertion: line 279 pos 12: 'itemIndex >= 0 && itemIndex <= _itemsCount': is not true.