|
|
|
@ -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() { |
|
|
|
@ -259,21 +262,21 @@ class _ChatDetailsPage extends State<ChatDetailsPage>
|
|
|
|
|
leading: true, |
|
|
|
|
leadingColor: Colors.black, |
|
|
|
|
action: GestureDetector( |
|
|
|
|
behavior: HitTestBehavior.opaque, |
|
|
|
|
onTap: () { |
|
|
|
|
setState(() { |
|
|
|
|
Navigator.of(context).pushNamed('/router/chat_setting'); |
|
|
|
|
copyIndex = 0; |
|
|
|
|
}); |
|
|
|
|
}, |
|
|
|
|
child: Container( |
|
|
|
|
alignment: Alignment.center, |
|
|
|
|
child: Icon( |
|
|
|
|
Icons.more_horiz, |
|
|
|
|
color: Colors.black, |
|
|
|
|
size: 30, |
|
|
|
|
), |
|
|
|
|
behavior: HitTestBehavior.opaque, |
|
|
|
|
onTap: () { |
|
|
|
|
setState(() { |
|
|
|
|
Navigator.of(context).pushNamed('/router/chat_setting'); |
|
|
|
|
copyIndex = 0; |
|
|
|
|
}); |
|
|
|
|
}, |
|
|
|
|
child: Container( |
|
|
|
|
alignment: Alignment.center, |
|
|
|
|
child: Icon( |
|
|
|
|
Icons.more_horiz, |
|
|
|
|
color: Colors.black, |
|
|
|
|
size: 30, |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
body: Container( |
|
|
|
@ -286,17 +289,17 @@ class _ChatDetailsPage extends State<ChatDetailsPage>
|
|
|
|
|
child: Column( |
|
|
|
|
children: [ |
|
|
|
|
GestureDetector( |
|
|
|
|
behavior: HitTestBehavior.translucent, |
|
|
|
|
onTap: () { |
|
|
|
|
setState(() { |
|
|
|
|
emojiShowing = false; |
|
|
|
|
isKeyBoardShow = emojiShowing; |
|
|
|
|
moreShow = false; |
|
|
|
|
isKeyBoardShow = moreShow; |
|
|
|
|
FocusScope.of(context).requestFocus(FocusNode()); |
|
|
|
|
}); |
|
|
|
|
}, |
|
|
|
|
child: chatDetailsList(), |
|
|
|
|
behavior: HitTestBehavior.translucent, |
|
|
|
|
onTap: () { |
|
|
|
|
setState(() { |
|
|
|
|
emojiShowing = false; |
|
|
|
|
isKeyBoardShow = emojiShowing; |
|
|
|
|
moreShow = false; |
|
|
|
|
isKeyBoardShow = moreShow; |
|
|
|
|
FocusScope.of(context).requestFocus(FocusNode()); |
|
|
|
|
}); |
|
|
|
|
}, |
|
|
|
|
child: chatDetailsList(), |
|
|
|
|
), |
|
|
|
|
], |
|
|
|
|
), |
|
|
|
@ -344,7 +347,7 @@ class _ChatDetailsPage extends State<ChatDetailsPage>
|
|
|
|
|
child: Column( |
|
|
|
|
children: [ |
|
|
|
|
Text( |
|
|
|
|
"3月08日 上午 12:10", |
|
|
|
|
"${DateTime.fromMillisecondsSinceEpoch(int.parse(message.time))}", |
|
|
|
|
textAlign: TextAlign.center, |
|
|
|
|
style: TextStyle( |
|
|
|
|
color: Color(0xFFA29E9E), |
|
|
|
@ -352,23 +355,23 @@ class _ChatDetailsPage extends State<ChatDetailsPage>
|
|
|
|
|
fontWeight: MyFontWeight.regular, |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
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 (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,13 +458,17 @@ 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( |
|
|
|
|
children: [ |
|
|
|
|
MImage( |
|
|
|
|
_toUser.avatar, |
|
|
|
|
_toUser.avatar, |
|
|
|
|
isCircle: true, |
|
|
|
|
height: 44.h, |
|
|
|
|
width: 44.h, |
|
|
|
@ -472,45 +480,48 @@ class _ChatDetailsPage extends State<ChatDetailsPage>
|
|
|
|
|
width: 12.w, |
|
|
|
|
), |
|
|
|
|
Expanded( |
|
|
|
|
child: Container( |
|
|
|
|
alignment: Alignment.centerLeft, |
|
|
|
|
child: Container( |
|
|
|
|
decoration: BoxDecoration( |
|
|
|
|
borderRadius: BorderRadius.circular(6), |
|
|
|
|
color: Color(0xFFFFFFFF), |
|
|
|
|
boxShadow: [ |
|
|
|
|
BoxShadow( |
|
|
|
|
color: Color(0xFFA8A3A3).withAlpha(12), |
|
|
|
|
offset: Offset(0, 4), |
|
|
|
|
blurRadius: 4, |
|
|
|
|
spreadRadius: 0, |
|
|
|
|
) |
|
|
|
|
], |
|
|
|
|
decoration: BoxDecoration( |
|
|
|
|
borderRadius: BorderRadius.circular(6), |
|
|
|
|
color: Color(0xFFFFFFFF), |
|
|
|
|
boxShadow: [ |
|
|
|
|
BoxShadow( |
|
|
|
|
color: Color(0xFFA8A3A3).withAlpha(12), |
|
|
|
|
offset: Offset(0, 4), |
|
|
|
|
blurRadius: 4, |
|
|
|
|
spreadRadius: 0, |
|
|
|
|
), |
|
|
|
|
padding: EdgeInsets.symmetric( |
|
|
|
|
vertical: 8.h, horizontal: 12.w), |
|
|
|
|
child: GestureDetector( |
|
|
|
|
onLongPress: () { |
|
|
|
|
setState(() { |
|
|
|
|
copyIndex = 1; |
|
|
|
|
}); |
|
|
|
|
}, |
|
|
|
|
child: Text( |
|
|
|
|
tex = message.content, |
|
|
|
|
textAlign: TextAlign.left, |
|
|
|
|
style: TextStyle( |
|
|
|
|
height: 1.2.h, |
|
|
|
|
color: Color(0XFF0D0D0D), |
|
|
|
|
fontSize: 17.sp, |
|
|
|
|
fontWeight: MyFontWeight.medium, |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
))), |
|
|
|
|
], |
|
|
|
|
), |
|
|
|
|
padding: EdgeInsets.symmetric( |
|
|
|
|
vertical: 8.h, |
|
|
|
|
horizontal: 12.w, |
|
|
|
|
), |
|
|
|
|
child: GestureDetector( |
|
|
|
|
onLongPress: () { |
|
|
|
|
setState(() { |
|
|
|
|
copyIndex = 1; |
|
|
|
|
}); |
|
|
|
|
}, |
|
|
|
|
child: Text( |
|
|
|
|
tex = message.content, |
|
|
|
|
textAlign: TextAlign.left, |
|
|
|
|
style: TextStyle( |
|
|
|
|
height: 1.2.h, |
|
|
|
|
color: Color(0XFF0D0D0D), |
|
|
|
|
fontSize: 17.sp, |
|
|
|
|
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, |
|
|
|
|