1
1
import 'package:flutter/material.dart' ;
2
- import 'package:flutter/scheduler.dart' ;
3
2
import 'package:flutter_twitter_clone/helper/constant.dart' ;
4
3
import 'package:flutter_twitter_clone/helper/theme.dart' ;
5
4
import 'package:flutter_twitter_clone/helper/utility.dart' ;
5
+ import 'package:flutter_twitter_clone/model/chatModel.dart' ;
6
6
import 'package:flutter_twitter_clone/model/user.dart' ;
7
- import 'package:flutter_twitter_clone/page/common/sidebar.dart' ;
8
- import 'package:flutter_twitter_clone/page/message/newMessagePage.dart' ;
9
7
import 'package:flutter_twitter_clone/state/authState.dart' ;
10
8
import 'package:flutter_twitter_clone/state/chats/chatState.dart' ;
11
- import 'package:flutter_twitter_clone/state/notificationState.dart' ;
12
9
import 'package:flutter_twitter_clone/state/searchState.dart' ;
13
10
import 'package:flutter_twitter_clone/widgets/customAppBar.dart' ;
14
11
import 'package:flutter_twitter_clone/widgets/customWidgets.dart' ;
@@ -37,6 +34,7 @@ class _ChatListPageState extends State<ChatListPage> {
37
34
38
35
Widget _body () {
39
36
final state = Provider .of <ChatState >(context);
37
+ final searchState = Provider .of <SearchState >(context, listen: false );
40
38
if (state.chatUserList == null ) {
41
39
return Padding (
42
40
padding: EdgeInsets .symmetric (horizontal: 30 ),
@@ -50,7 +48,12 @@ class _ChatListPageState extends State<ChatListPage> {
50
48
return ListView .separated (
51
49
physics: BouncingScrollPhysics (),
52
50
itemCount: state.chatUserList.length,
53
- itemBuilder: (context, index) => _userCard (state.chatUserList[index]),
51
+ itemBuilder: (context, index) => _userCard (
52
+ searchState.userlist.firstWhere (
53
+ (x) => x.userId == state.chatUserList[index].key,
54
+ orElse: () => User (userName: "Unknown" ),
55
+ ),
56
+ state.chatUserList[index]),
54
57
separatorBuilder: (context, index) {
55
58
return Divider (
56
59
height: 0 ,
@@ -60,7 +63,7 @@ class _ChatListPageState extends State<ChatListPage> {
60
63
}
61
64
}
62
65
63
- Widget _userCard (User model) {
66
+ Widget _userCard (User model, ChatMessage lastMessage ) {
64
67
return Container (
65
68
color: Colors .white,
66
69
child: ListTile (
@@ -101,9 +104,14 @@ class _ChatListPageState extends State<ChatListPage> {
101
104
style: onPrimaryTitleText.copyWith (color: Colors .black),
102
105
),
103
106
subtitle: customText (
104
- '@${model .displayName }' ,
107
+ getLastMessage (lastMessage.message) ?? '@${model .displayName }' ,
105
108
style: onPrimarySubTitleText.copyWith (color: Colors .black54),
106
109
),
110
+ trailing: lastMessage == null
111
+ ? SizedBox .shrink ()
112
+ : Text (
113
+ getChatTime (lastMessage.createdAt).toString (),
114
+ ),
107
115
),
108
116
);
109
117
}
@@ -127,6 +135,18 @@ class _ChatListPageState extends State<ChatListPage> {
127
135
Navigator .pushNamed (context, '/DirectMessagesPage' );
128
136
}
129
137
138
+ String getLastMessage (String message) {
139
+ if (message != null && message.isNotEmpty) {
140
+ if (message.length > 100 ) {
141
+ message = message.substring (0 , 80 ) + '...' ;
142
+ return message;
143
+ } else {
144
+ return message;
145
+ }
146
+ }
147
+ return null ;
148
+ }
149
+
130
150
@override
131
151
Widget build (BuildContext context) {
132
152
return Scaffold (
0 commit comments