@@ -27,19 +27,21 @@ class ChatState extends AppState {
27
27
String _channelName;
28
28
Query messageQuery;
29
29
30
+ /// Contains list of chat messages on main chat screen
31
+ /// List is sortBy mesage timeStamp
32
+ /// Last message will be display on the bottom of screen
30
33
List <ChatMessage > get messageList {
31
34
if (_messageList == null ) {
32
35
return null ;
33
36
} else {
34
- _messageList.sort ((x, y) => DateTime .parse (x .createdAt)
37
+ _messageList.sort ((x, y) => DateTime .parse (y .createdAt)
35
38
.toLocal ()
36
- .compareTo (DateTime .parse (y.createdAt).toLocal ()));
37
- _messageList.reversed;
38
- _messageList = _messageList.reversed.toList ();
39
- return List .from (_messageList);
39
+ .compareTo (DateTime .parse (x.createdAt).toLocal ()));
40
+ return _messageList;
40
41
}
41
42
}
42
43
44
+ /// Contain list of users who have chat history with logged in user
43
45
List <ChatMessage > get chatUserList {
44
46
if (_chatUserList == null ) {
45
47
return null ;
@@ -86,9 +88,9 @@ class ChatState extends AppState {
86
88
var data = remoteConfig.getString ('FcmServerKey' );
87
89
if (data != null && data.isNotEmpty) {
88
90
serverToken = jsonDecode (data)["key" ];
89
- }
90
- else {
91
- cprint ( "Please configure Remote config in firebase" , errorIn: "getFCMServerKey" );
91
+ } else {
92
+ cprint ( "Please configure Remote config in firebase" ,
93
+ errorIn: "getFCMServerKey" );
92
94
}
93
95
}
94
96
@@ -110,6 +112,19 @@ class ChatState extends AppState {
110
112
_chatUserList.add (model);
111
113
});
112
114
}
115
+ _chatUserList.sort ((x, y) {
116
+ if (x.createdAt != null && y.createdAt != null ) {
117
+ return DateTime .parse (y.createdAt)
118
+ .compareTo (DateTime .parse (x.createdAt));
119
+ } else {
120
+ if (x.createdAt != null ){
121
+ return 0 ;
122
+ }
123
+ else {
124
+ return 1 ;
125
+ }
126
+ }
127
+ });
113
128
} else {
114
129
_chatUserList = null ;
115
130
}
@@ -255,8 +270,9 @@ class ChatState extends AppState {
255
270
_messageList = null ;
256
271
notifyListeners ();
257
272
}
273
+
258
274
/// [Warning] do not call super.dispose() from this method
259
- /// If this method called here it will dipose chat state data
275
+ /// If this method called here it will dipose chat state data
260
276
// super.dispose();
261
277
}
262
278
0 commit comments