|
|
|
@ -89,8 +89,10 @@ class _ChatDetailsPage extends State<ChatDetailsPage>
|
|
|
|
|
|
|
|
|
|
socketClient.addCallback(_toUser.mid, (Message message) { |
|
|
|
|
messages.insert(0, message); |
|
|
|
|
refreshState(); |
|
|
|
|
jumpToBottom(); |
|
|
|
|
messageShowTime().then((value) { |
|
|
|
|
refreshState(); |
|
|
|
|
jumpToBottom(); |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
refreshState(); |
|
|
|
|
jumpToBottom(); |
|
|
|
@ -105,6 +107,7 @@ class _ChatDetailsPage extends State<ChatDetailsPage>
|
|
|
|
|
} else { |
|
|
|
|
messages.addAll(messagePage); |
|
|
|
|
} |
|
|
|
|
await messageShowTime(); |
|
|
|
|
if (messagePage.isEmpty) { |
|
|
|
|
refreshController.loadNoData(); |
|
|
|
|
return; |
|
|
|
@ -114,6 +117,14 @@ class _ChatDetailsPage extends State<ChatDetailsPage>
|
|
|
|
|
return Future.value(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Future messageShowTime() async { |
|
|
|
|
List<Message> messagePages = await hxDatabase.queryTList(_toUser.mid); |
|
|
|
|
for (var value in messages) { |
|
|
|
|
Message message = messagePages.firstWhere((element) => value.id == element.id, orElse: () => null); |
|
|
|
|
value.showTime = message != null; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
///查询个人信息 |
|
|
|
|
queryUser() async { |
|
|
|
|
final SharedPreferences value = await SharedPreferences.getInstance(); |
|
|
|
@ -123,10 +134,8 @@ class _ChatDetailsPage extends State<ChatDetailsPage>
|
|
|
|
|
userInfo = UserInfo.fromJson(jsonDecode(value.getString('user'))); |
|
|
|
|
} |
|
|
|
|
if (apiService == null) |
|
|
|
|
apiService = |
|
|
|
|
ApiService(Dio(), context: context, token: value.getString("token")); |
|
|
|
|
BaseData<UserInfo> baseData = |
|
|
|
|
await apiService.queryInfo().catchError((onError) {}); |
|
|
|
|
apiService = ApiService(Dio(), context: context, token: value.getString("token")); |
|
|
|
|
BaseData<UserInfo> baseData = await apiService.queryInfo().catchError((onError) {}); |
|
|
|
|
if (baseData != null && baseData.isSuccess) { |
|
|
|
|
setState(() { |
|
|
|
|
userInfo = baseData.data; |
|
|
|
@ -374,7 +383,8 @@ class _ChatDetailsPage extends State<ChatDetailsPage>
|
|
|
|
|
child: SingleChildScrollView( |
|
|
|
|
physics: BouncingScrollPhysics(), |
|
|
|
|
controller: scrollController, |
|
|
|
|
child: chatDetailsList()), |
|
|
|
|
child: chatDetailsList(), |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
flex: 1, |
|
|
|
|
), |
|
|
|
@ -382,7 +392,8 @@ class _ChatDetailsPage extends State<ChatDetailsPage>
|
|
|
|
|
], |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
)); |
|
|
|
|
), |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
///聊天列表 |
|
|
|
@ -419,24 +430,25 @@ class _ChatDetailsPage extends State<ChatDetailsPage>
|
|
|
|
|
), |
|
|
|
|
child: Column( |
|
|
|
|
children: [ |
|
|
|
|
Text( |
|
|
|
|
// position == messages.length-1 |
|
|
|
|
// ? |
|
|
|
|
AppUtils.milliTimeFormatter(DateTime.fromMillisecondsSinceEpoch( |
|
|
|
|
int.parse(messages[position].time))) |
|
|
|
|
// : AppUtils.getTimeDisplay( |
|
|
|
|
// DateTime.fromMillisecondsSinceEpoch( |
|
|
|
|
// int.parse(messages[position].time)), |
|
|
|
|
// DateTime.fromMillisecondsSinceEpoch( |
|
|
|
|
// int.parse(messages[position+1].time))) |
|
|
|
|
, |
|
|
|
|
textAlign: TextAlign.center, |
|
|
|
|
style: TextStyle( |
|
|
|
|
color: Color(0xFFA29E9E), |
|
|
|
|
fontSize: 10.sp, |
|
|
|
|
fontWeight: MyFontWeight.regular, |
|
|
|
|
if (messages[position].showTime) |
|
|
|
|
Text( |
|
|
|
|
// position == messages.length-1 |
|
|
|
|
// ? |
|
|
|
|
AppUtils.milliTimeFormatter(DateTime.fromMillisecondsSinceEpoch( |
|
|
|
|
int.parse(messages[position].time))) |
|
|
|
|
// : AppUtils.getTimeDisplay( |
|
|
|
|
// DateTime.fromMillisecondsSinceEpoch( |
|
|
|
|
// int.parse(messages[position].time)), |
|
|
|
|
// DateTime.fromMillisecondsSinceEpoch( |
|
|
|
|
// int.parse(messages[position+1].time))) |
|
|
|
|
, |
|
|
|
|
textAlign: TextAlign.center, |
|
|
|
|
style: TextStyle( |
|
|
|
|
color: Color(0xFFA29E9E), |
|
|
|
|
fontSize: 10.sp, |
|
|
|
|
fontWeight: MyFontWeight.regular, |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
// if (messages.indexOf(message) == (messages.length - 1)) |
|
|
|
|
// Padding( |
|
|
|
|
// padding: EdgeInsets.only(top: 10.h, bottom: 24.h), |
|
|
|
|