|
|
|
@ -67,11 +67,15 @@ class _ChatDetailsPage extends State<ChatDetailsPage>
|
|
|
|
|
List<Message> messages = []; |
|
|
|
|
|
|
|
|
|
loadMessageList() async { |
|
|
|
|
ImUser imUser = await hxDatabase.queryImUserById(_toUser.mid); |
|
|
|
|
if (imUser == null) { |
|
|
|
|
await hxDatabase.insertOrUpdateImUser(_toUser.toJson()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
selfUserId = (await SharedPreferences.getInstance()).getString("userId"); |
|
|
|
|
// unread msg 2 read state |
|
|
|
|
await hxDatabase.readMessage(selfUserId, _toUser.mid); |
|
|
|
|
messages = await hxDatabase.queryUList(_toUser.mid); |
|
|
|
|
messages = await hxDatabase.queryUList(_toUser.mid, pageSize: 100); |
|
|
|
|
|
|
|
|
|
socketClient.addCallback(_toUser.mid, (Message message) { |
|
|
|
|
messages.add(message); |
|
|
|
@ -98,7 +102,6 @@ class _ChatDetailsPage extends State<ChatDetailsPage>
|
|
|
|
|
commentFocus.addListener(_focusNodeListener); |
|
|
|
|
|
|
|
|
|
loadMessageList(); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void jumpToBottom() { |
|
|
|
@ -344,19 +347,7 @@ class _ChatDetailsPage extends State<ChatDetailsPage>
|
|
|
|
|
child: Column( |
|
|
|
|
children: [ |
|
|
|
|
Text( |
|
|
|
|
"3月08日 上午 12:10", |
|
|
|
|
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), |
|
|
|
|
child: Text( |
|
|
|
|
"在对方未回复或关注你之前,你只能发送一条信息", |
|
|
|
|
"${DateTime.fromMillisecondsSinceEpoch(int.parse(message.time))}", |
|
|
|
|
textAlign: TextAlign.center, |
|
|
|
|
style: TextStyle( |
|
|
|
|
color: Color(0xFFA29E9E), |
|
|
|
@ -364,11 +355,23 @@ class _ChatDetailsPage extends State<ChatDetailsPage>
|
|
|
|
|
fontWeight: MyFontWeight.regular, |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
if (messages.indexOf(message) == (messages.length - 1)) |
|
|
|
|
SizedBox( |
|
|
|
|
height: 16.h, |
|
|
|
|
), |
|
|
|
|
// if (messages.indexOf(message) == (messages.length - 1)) |
|
|
|
|
// Padding( |
|
|
|
|
// padding: EdgeInsets.only(top: 10.h, bottom: 24.h), |
|
|
|
|
// child: Text( |
|
|
|
|
// "在对方未回复或关注你之前,你只能发送一条信息", |
|
|
|
|
// textAlign: TextAlign.center, |
|
|
|
|
// style: TextStyle( |
|
|
|
|
// color: Color(0xFFA29E9E), |
|
|
|
|
// fontSize: 10.sp, |
|
|
|
|
// fontWeight: MyFontWeight.regular, |
|
|
|
|
// ), |
|
|
|
|
// ), |
|
|
|
|
// ), |
|
|
|
|
// if (messages.indexOf(message) == (messages.length - 1)) |
|
|
|
|
// SizedBox( |
|
|
|
|
// height: 16.h, |
|
|
|
|
// ), |
|
|
|
|
if (copyIndex == 1) |
|
|
|
|
Stack( |
|
|
|
|
alignment: Alignment.bottomCenter, |
|
|
|
@ -382,7 +385,8 @@ class _ChatDetailsPage extends State<ChatDetailsPage>
|
|
|
|
|
borderRadius: BorderRadius.circular(6), |
|
|
|
|
), |
|
|
|
|
padding: EdgeInsets.symmetric( |
|
|
|
|
horizontal: 32.w, vertical: 7.5.h, |
|
|
|
|
horizontal: 32.w, |
|
|
|
|
vertical: 7.5.h, |
|
|
|
|
), |
|
|
|
|
child: Row( |
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween, |
|
|
|
@ -454,7 +458,11 @@ class _ChatDetailsPage extends State<ChatDetailsPage>
|
|
|
|
|
), |
|
|
|
|
|
|
|
|
|
/// not self |
|
|
|
|
if (!isSelf && !isText) |
|
|
|
|
if (!isSelf && isText) |
|
|
|
|
SizedBox( |
|
|
|
|
height: 10.h, |
|
|
|
|
), |
|
|
|
|
if (!isSelf && isText) |
|
|
|
|
Padding( |
|
|
|
|
padding: EdgeInsets.only(left: 17.w, right: 39.w), |
|
|
|
|
child: Row( |
|
|
|
@ -472,6 +480,8 @@ class _ChatDetailsPage extends State<ChatDetailsPage>
|
|
|
|
|
width: 12.w, |
|
|
|
|
), |
|
|
|
|
Expanded( |
|
|
|
|
child: Container( |
|
|
|
|
alignment: Alignment.centerLeft, |
|
|
|
|
child: Container( |
|
|
|
|
decoration: BoxDecoration( |
|
|
|
|
borderRadius: BorderRadius.circular(6), |
|
|
|
@ -482,11 +492,13 @@ class _ChatDetailsPage extends State<ChatDetailsPage>
|
|
|
|
|
offset: Offset(0, 4), |
|
|
|
|
blurRadius: 4, |
|
|
|
|
spreadRadius: 0, |
|
|
|
|
) |
|
|
|
|
), |
|
|
|
|
], |
|
|
|
|
), |
|
|
|
|
padding: EdgeInsets.symmetric( |
|
|
|
|
vertical: 8.h, horizontal: 12.w), |
|
|
|
|
vertical: 8.h, |
|
|
|
|
horizontal: 12.w, |
|
|
|
|
), |
|
|
|
|
child: GestureDetector( |
|
|
|
|
onLongPress: () { |
|
|
|
|
setState(() { |
|
|
|
@ -503,14 +515,13 @@ class _ChatDetailsPage extends State<ChatDetailsPage>
|
|
|
|
|
fontWeight: MyFontWeight.medium, |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
))), |
|
|
|
|
], |
|
|
|
|
), |
|
|
|
|
),), |
|
|
|
|
), |
|
|
|
|
], |
|
|
|
|
), |
|
|
|
|
if (!isSelf && isText) |
|
|
|
|
SizedBox( |
|
|
|
|
height: 40.h, |
|
|
|
|
), |
|
|
|
|
|
|
|
|
|
if (copyIndex == 1) |
|
|
|
|
Stack( |
|
|
|
|
alignment: Alignment.bottomCenter, |
|
|
|
@ -595,6 +606,10 @@ class _ChatDetailsPage extends State<ChatDetailsPage>
|
|
|
|
|
), |
|
|
|
|
|
|
|
|
|
/// self |
|
|
|
|
if (isSelf && isText) |
|
|
|
|
SizedBox( |
|
|
|
|
height: 10.h, |
|
|
|
|
), |
|
|
|
|
if (isSelf && isText) |
|
|
|
|
Padding( |
|
|
|
|
padding: EdgeInsets.only(left: 36.w, right: 16.w), |
|
|
|
@ -630,9 +645,19 @@ class _ChatDetailsPage extends State<ChatDetailsPage>
|
|
|
|
|
decoration: BoxDecoration( |
|
|
|
|
borderRadius: BorderRadius.circular(6), |
|
|
|
|
color: Color(0xFF32A060), |
|
|
|
|
boxShadow: [ |
|
|
|
|
BoxShadow( |
|
|
|
|
color: Color(0xFFA8A3A3).withAlpha(12), |
|
|
|
|
offset: Offset(0, 4), |
|
|
|
|
blurRadius: 4, |
|
|
|
|
spreadRadius: 0, |
|
|
|
|
), |
|
|
|
|
], |
|
|
|
|
), |
|
|
|
|
padding: EdgeInsets.symmetric( |
|
|
|
|
vertical: 8.h, |
|
|
|
|
horizontal: 12.w, |
|
|
|
|
), |
|
|
|
|
padding: |
|
|
|
|
EdgeInsets.symmetric(vertical: 8.h, horizontal: 12.w), |
|
|
|
|
child: GestureDetector( |
|
|
|
|
onLongPress: () { |
|
|
|
|
setState(() { |
|
|
|
@ -732,19 +757,19 @@ class _ChatDetailsPage extends State<ChatDetailsPage>
|
|
|
|
|
), |
|
|
|
|
|
|
|
|
|
/// no reply long time |
|
|
|
|
if (messages.indexOf(message) == 0) |
|
|
|
|
Padding( |
|
|
|
|
padding: EdgeInsets.only(left: 17.w, right: 17.w, top: 24.h), |
|
|
|
|
child: Text( |
|
|
|
|
"由于对方没有回复你,你只能发送一条消息,需要对方关注或回复后才能恢复正常聊天", |
|
|
|
|
textAlign: TextAlign.center, |
|
|
|
|
style: TextStyle( |
|
|
|
|
color: Color(0xFFA29E9E), |
|
|
|
|
fontSize: 10.sp, |
|
|
|
|
fontWeight: MyFontWeight.regular, |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
// if (messages.indexOf(message) == 0) |
|
|
|
|
// Padding( |
|
|
|
|
// padding: EdgeInsets.only(left: 17.w, right: 17.w, top: 24.h), |
|
|
|
|
// child: Text( |
|
|
|
|
// "由于对方没有回复你,你只能发送一条消息,需要对方关注或回复后才能恢复正常聊天", |
|
|
|
|
// textAlign: TextAlign.center, |
|
|
|
|
// style: TextStyle( |
|
|
|
|
// color: Color(0xFFA29E9E), |
|
|
|
|
// fontSize: 10.sp, |
|
|
|
|
// fontWeight: MyFontWeight.regular, |
|
|
|
|
// ), |
|
|
|
|
// ), |
|
|
|
|
// ), |
|
|
|
|
], |
|
|
|
|
), |
|
|
|
|
); |
|
|
|
@ -784,14 +809,21 @@ class _ChatDetailsPage extends State<ChatDetailsPage>
|
|
|
|
|
if (commentText.trim() == "") { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
socketClient.sendMessage(_toUser.mid, commentText).then((value) { |
|
|
|
|
socketClient |
|
|
|
|
.sendMessage(_toUser.mid, commentText) |
|
|
|
|
.then((value) { |
|
|
|
|
Message message = value; |
|
|
|
|
messages.insert(0, message); |
|
|
|
|
chatController.clear(); |
|
|
|
|
if (mounted) |
|
|
|
|
setState(() {}); |
|
|
|
|
if (mounted) setState(() {}); |
|
|
|
|
|
|
|
|
|
if (scrollController.position != null) { |
|
|
|
|
double offset = scrollController.position.maxScrollExtent; |
|
|
|
|
debugPrint("offset: $offset"); |
|
|
|
|
scrollController.animateTo(offset + 50, duration: const Duration(milliseconds: 500), curve: Curves.easeIn); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
}); |
|
|
|
|
// widget.queryMemberComment(commentText); |
|
|
|
|
}, |
|
|
|
|
maxLines: 8, |
|
|
|
|
minLines: 1, |
|
|
|
|