Browse Source

聊天修改

dart3_last
fff 1 week ago
parent
commit
a467c719cb
  1. 351
      lib/im/chat_details_page.dart

351
lib/im/chat_details_page.dart

@ -10,6 +10,7 @@ import 'package:flutter/services.dart';
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.dart';
import 'package:flutter_keyboard_visibility/flutter_keyboard_visibility.dart'; import 'package:flutter_keyboard_visibility/flutter_keyboard_visibility.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
import 'package:huixiang/constant.dart'; import 'package:huixiang/constant.dart';
import 'package:huixiang/data/base_data.dart'; import 'package:huixiang/data/base_data.dart';
@ -20,12 +21,9 @@ import 'package:huixiang/im/out/message.pb.dart';
import 'package:huixiang/main.dart'; import 'package:huixiang/main.dart';
import 'package:huixiang/retrofit/retrofit_api.dart'; import 'package:huixiang/retrofit/retrofit_api.dart';
import 'package:huixiang/utils/shared_preference.dart'; import 'package:huixiang/utils/shared_preference.dart';
import 'package:huixiang/view_widget/classic_header.dart';
import 'package:huixiang/view_widget/my_appbar.dart'; import 'package:huixiang/view_widget/my_appbar.dart';
import 'package:image_pickers/image_pickers.dart'; import 'package:image_pickers/image_pickers.dart';
import 'package:permission_handler/permission_handler.dart'; import 'package:permission_handler/permission_handler.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';
import '../../community/release_dynamic.dart'; import '../../community/release_dynamic.dart';
import '../../generated/l10n.dart'; import '../../generated/l10n.dart';
import '../../utils/font_weight.dart'; import '../../utils/font_weight.dart';
@ -62,7 +60,9 @@ class _ChatDetailsPage extends State<ChatDetailsPage>
UserInfo? userInfo; UserInfo? userInfo;
// final OnChatMessage? _tempOnChatMessage = OnChatMsgInstance.instance.onChatMessage; // final OnChatMessage? _tempOnChatMessage = OnChatMsgInstance.instance.onChatMessage;
final ScrollController scrollController = ScrollController(); final ScrollController scrollController = ScrollController();
GlobalKey<AnimatedListState> animatedListKey = GlobalKey<AnimatedListState>(); GlobalKey<SliverAnimatedListState> newanimatedListKey = GlobalKey<SliverAnimatedListState>();
GlobalKey<SliverAnimatedListState> loadanimatedListKey = GlobalKey<SliverAnimatedListState>();
GlobalKey centerKey = GlobalKey();
String tex = ""; String tex = "";
String selfUserId = ""; String selfUserId = "";
ImUser? _toUser; ImUser? _toUser;
@ -72,8 +72,11 @@ class _ChatDetailsPage extends State<ChatDetailsPage>
double inputWidgetHeight = 95; double inputWidgetHeight = 95;
double dynamicInputHeight = 0; double dynamicInputHeight = 0;
RefreshController refreshController = RefreshController(); late StreamSubscription<bool> keyboardSubscription;
List<Message> messages = []; bool loading = false;
List<Message> newmessages = [];
List<Message> loadmessages = [];
int page = 0; int page = 0;
loadMessageList() async { loadMessageList() async {
@ -91,8 +94,8 @@ class _ChatDetailsPage extends State<ChatDetailsPage>
await refresh(); await refresh();
socketClient.addCallback(_toUser?.mid ?? '', (Message message) { socketClient.addCallback(_toUser?.mid ?? '', (Message message) {
messages.add(message); newmessages.add(message);
animatedListKey.currentState?.insertItem(messages.length - 1); newanimatedListKey.currentState?.insertItem(newmessages.length - 1);
if ((message.msgType == MsgType.VIDEO.value || message.msgType == MsgType.IMAGE.value) && (message.attach?.isNotEmpty ?? false)) { if ((message.msgType == MsgType.VIDEO.value || message.msgType == MsgType.IMAGE.value) && (message.attach?.isNotEmpty ?? false)) {
imageUrl.add(message.attach!); imageUrl.add(message.attach!);
} }
@ -102,7 +105,7 @@ class _ChatDetailsPage extends State<ChatDetailsPage>
}); });
}); });
messageImageUrl(); messageImageUrl(newmessages);
// refreshState(); // refreshState();
// jumpToBottom(); // jumpToBottom();
@ -112,13 +115,15 @@ class _ChatDetailsPage extends State<ChatDetailsPage>
List<Message>? messagePage = await hxDatabase.queryUList(conversation, page: page + 1, pageSize: 10); List<Message>? messagePage = await hxDatabase.queryUList(conversation, page: page + 1, pageSize: 10);
debugPrint("refresh-message-list: ${messagePage?.length ?? ''} page: $page"); debugPrint("refresh-message-list: ${messagePage?.length ?? ''} page: $page");
if (messagePage?.isEmpty ?? true) { if (messagePage?.isEmpty ?? true) {
refreshController.refreshCompleted(); // refreshController.refreshCompleted();
return 0; return 0;
} else { } else {
refreshController.refreshCompleted(); // refreshController.refreshCompleted();
page += 1; page += 1;
} }
double height = 0; double height = 0;
if (page == 1) {
await Future.forEach(messagePage!, (element) async { await Future.forEach(messagePage!, (element) async {
height += await chatDetailsItemHeight(element); height += await chatDetailsItemHeight(element);
}); });
@ -126,26 +131,29 @@ class _ChatDetailsPage extends State<ChatDetailsPage>
debugPrint("refresh-message-height: ${height} page: $page"); debugPrint("refresh-message-height: ${height} page: $page");
scrollController.position.restoreOffset(height, initialRestore: true); scrollController.position.restoreOffset(height, initialRestore: true);
} }
if (page == 1) { newmessages.addAll(messagePage!.reversed.toList());
messages.addAll(messagePage.reversed.toList()); newanimatedListKey.currentState?.insertAllItems(0, messagePage.length);
animatedListKey.currentState?.insertAllItems(0, messagePage.length);
} else { } else {
messages.insertAll(0, messagePage.reversed.toList()); loadmessages.addAll(messagePage!.toList());
animatedListKey.currentState?.insertAllItems(0, messagePage.length, duration: 300.milliseconds); loadanimatedListKey.currentState?.insertAllItems(0, messagePage.length, duration: 300.milliseconds);
} }
await messageShowTime(); await messageShowTime();
return height; return height;
} }
/// ///
messageImageUrl() { messageImageUrl(List<Message> messages) {
imageUrl = messages.where((e) => (e.msgType == MsgType.VIDEO.value || e.msgType == MsgType.IMAGE.value) && (e.attach?.isNotEmpty ?? false)).map((e) => "${e.attach}").toList(); List<String> images = messages.where((e) => (e.msgType == MsgType.VIDEO.value || e.msgType == MsgType.IMAGE.value) && (e.attach?.isNotEmpty ?? false)).map((e) => "${e.attach}").toList();
if (images.isNotEmpty) {
imageUrl.addAll(images);
}
} }
Future messageShowTime() async { Future messageShowTime() async {
List<Message>? messagePages = await hxDatabase.queryTList(conversation); List<Message>? messagePages = await hxDatabase.queryTList(conversation);
for (var value in messages) { List<Message> tempMessages = newmessages + loadmessages;
Message? message = messagePages?.firstWhere((element) => value.id == element.id, orElse: () => messages.first); for (var value in tempMessages) {
Message? message = messagePages?.firstWhere((element) => value.id == element.id, orElse: () => tempMessages.first);
value.showTime = message != null; value.showTime = message != null;
} }
} }
@ -174,8 +182,6 @@ class _ChatDetailsPage extends State<ChatDetailsPage>
if (mounted) setState(() {}); if (mounted) setState(() {});
} }
late StreamSubscription<bool> keyboardSubscription;
@override @override
void initState() { void initState() {
super.initState(); super.initState();
@ -188,15 +194,18 @@ class _ChatDetailsPage extends State<ChatDetailsPage>
queryUser(); queryUser();
loadMessageList(); loadMessageList();
scrollController.addListener(() { // scrollController.addListener(() {
debugPrint("scrollController-onChange: ${scrollController.position.pixels}"); // debugPrint("scrollController-onChange: ${scrollController.position.pixels}");
if (messages.length >= 10 && scrollController.position.pixels < -80) { // if (scrollController.position.pixels < -80) {
if (!loading) { // if (!loading) {
loading = true; // loading = true;
refresh().then((value) => loading = false); // refresh().then((value) {
} // loading = false;
} // messageImageUrl(loadmessages);
}); // });
// }
// }
// });
var keyboardVisibilityController = KeyboardVisibilityController(); var keyboardVisibilityController = KeyboardVisibilityController();
keyboardSubscription = keyboardVisibilityController.onChange.listen((bool visible) { keyboardSubscription = keyboardVisibilityController.onChange.listen((bool visible) {
@ -237,8 +246,6 @@ class _ChatDetailsPage extends State<ChatDetailsPage>
}); });
} }
bool loading = false;
void jumpToBottom() { void jumpToBottom() {
Future.delayed(const Duration(milliseconds: 400), () { Future.delayed(const Duration(milliseconds: 400), () {
if (scrollController.hasClients && scrollController.position.pixels != scrollController.position.maxScrollExtent) { if (scrollController.hasClients && scrollController.position.pixels != scrollController.position.maxScrollExtent) {
@ -295,8 +302,8 @@ class _ChatDetailsPage extends State<ChatDetailsPage>
moreShow = false; moreShow = false;
} }
if (emojiShowing) { if (emojiShowing) {
if (inputWidgetHeight == 95) { if (inputWidgetHeight < 270) {
inputWidgetHeight += (keyboard == -1 ? 270 : keyboard); inputWidgetHeight = 95 + (keyboard == -1 ? 270 : keyboard);
jumpToBottom(); jumpToBottom();
} }
} else { } else {
@ -360,8 +367,8 @@ class _ChatDetailsPage extends State<ChatDetailsPage>
String fileUrl = await qiniu.uploadFile(apiService!, path); String fileUrl = await qiniu.uploadFile(apiService!, path);
socketClient.sendMessage(_toUser?.mid ?? '', fileUrl, attach: path, msgType: galleryMode == GalleryMode.image ? 2 : 4).then((value) { socketClient.sendMessage(_toUser?.mid ?? '', fileUrl, attach: path, msgType: galleryMode == GalleryMode.image ? 2 : 4).then((value) {
Message message = value; Message message = value;
messages.add(message); newmessages.add(message);
animatedListKey.currentState?.insertItem(messages.length - 1); newanimatedListKey.currentState?.insertItem(newmessages.length - 1);
chatController.clear(); chatController.clear();
messageShowTime().then((value) { messageShowTime().then((value) {
refreshState(); refreshState();
@ -391,7 +398,8 @@ class _ChatDetailsPage extends State<ChatDetailsPage>
}, },
heightRatioWithWidth: 0.82, heightRatioWithWidth: 0.82,
); );
}); },
);
} else if (await Permission.camera.isGranted) { } else if (await Permission.camera.isGranted) {
if (await Permission.storage.isPermanentlyDenied) { if (await Permission.storage.isPermanentlyDenied) {
showCupertinoDialog( showCupertinoDialog(
@ -409,7 +417,8 @@ class _ChatDetailsPage extends State<ChatDetailsPage>
}, },
heightRatioWithWidth: 0.82, heightRatioWithWidth: 0.82,
); );
}); },
);
} else if (await Permission.storage.isGranted) { } else if (await Permission.storage.isGranted) {
Media? medias = await ImagePickers.openCamera( Media? medias = await ImagePickers.openCamera(
cameraMimeType: CameraMimeType.photo, cameraMimeType: CameraMimeType.photo,
@ -425,8 +434,8 @@ class _ChatDetailsPage extends State<ChatDetailsPage>
String fileUrl = await qiniu.uploadFile(apiService!, path); String fileUrl = await qiniu.uploadFile(apiService!, path);
socketClient.sendMessage(_toUser?.mid ?? '', fileUrl, attach: path, msgType: 2).then((value) { socketClient.sendMessage(_toUser?.mid ?? '', fileUrl, attach: path, msgType: 2).then((value) {
Message message = value; Message message = value;
messages.add(message); newmessages.add(message);
animatedListKey.currentState?.insertItem(messages.length - 1); newanimatedListKey.currentState?.insertItem(newmessages.length - 1);
chatController.clear(); chatController.clear();
messageShowTime().then((value) { messageShowTime().then((value) {
refreshState(); refreshState();
@ -564,9 +573,11 @@ class _ChatDetailsPage extends State<ChatDetailsPage>
), ),
), ),
), ),
body: Container( body:
height: MediaQuery.of(context).size.height - kToolbarHeight - MediaQuery.of(context).padding.top - MediaQuery.of(context).viewInsets.bottom, // Container(
child: Column( // height: MediaQuery.of(context).size.height - kToolbarHeight - MediaQuery.of(context).padding.top - MediaQuery.of(context).viewInsets.bottom,
// child:
Column(
children: [ children: [
Expanded( Expanded(
child: chatDetailsList(), child: chatDetailsList(),
@ -575,22 +586,54 @@ class _ChatDetailsPage extends State<ChatDetailsPage>
input(), input(),
], ],
), ),
), // ),
), ),
); );
} }
/// ///
Widget chatDetailsList() { Widget chatDetailsList() {
return AnimatedList( return RefreshIndicator(
key: animatedListKey, child: CustomScrollView(
initialItemCount: messages.length, center: centerKey,
controller: scrollController, controller: scrollController,
physics: BouncingScrollPhysics()..frictionFactor(0.8), physics: ClampingScrollPhysics(),
itemBuilder: (context, position, animation) { slivers: [
return chatDetailsItem(position); SliverAnimatedList(
itemBuilder: (context, index, animation) {
Message message = loadmessages[index];
return chatDetailsItem(message, index, loadanimatedListKey);
},
key: loadanimatedListKey,
initialItemCount: loadmessages.length,
),
SliverPadding(
padding: EdgeInsets.zero,
key: centerKey,
),
SliverAnimatedList(
itemBuilder: (context, index, animation) {
Message message = newmessages[index];
return chatDetailsItem(message, index, loadanimatedListKey);
},
key: newanimatedListKey,
initialItemCount: newmessages.length,
),
],
),
onRefresh: () async {
refresh();
}, },
); );
// return AnimatedList(
// key: animatedListKey,
// initialItemCount: messages.length,
// controller: scrollController,
// physics: BouncingScrollPhysics()..frictionFactor(0.8),
// itemBuilder: (context, position, animation) {
// return chatDetailsItem(position);
// },
// );
} }
Future<double> chatDetailsItemHeight(Message message) async { Future<double> chatDetailsItemHeight(Message message) async {
@ -644,10 +687,10 @@ class _ChatDetailsPage extends State<ChatDetailsPage>
return textPainter.height; return textPainter.height;
} }
Widget chatDetailsItem(position) { Widget chatDetailsItem(Message message, index, animationKey) {
bool isSelf = messages[position].fromId == selfUserId; bool isSelf = message.fromId == selfUserId;
bool isText = messages[position].msgType == 1; bool isText = message.msgType == 1;
bool isImage = messages[position].msgType == 2; bool isImage = message.msgType == 2;
GlobalKey _buttonKey = GlobalKey(); GlobalKey _buttonKey = GlobalKey();
return Container( return Container(
padding: EdgeInsets.only( padding: EdgeInsets.only(
@ -656,12 +699,12 @@ class _ChatDetailsPage extends State<ChatDetailsPage>
), ),
child: Column( child: Column(
children: [ children: [
if (messages[position].showTime) if (message.showTime)
Text( Text(
// position == messages.length-1 // position == messages.length-1
// ? // ?
AppUtils.milliTimeFormatter(DateTime.fromMillisecondsSinceEpoch( AppUtils.milliTimeFormatter(DateTime.fromMillisecondsSinceEpoch(
int.parse(messages[position].time))) int.parse(message.time)))
// : AppUtils.getTimeDisplay( // : AppUtils.getTimeDisplay(
// DateTime.fromMillisecondsSinceEpoch( // DateTime.fromMillisecondsSinceEpoch(
// int.parse(messages[position].time)), // int.parse(messages[position].time)),
@ -739,7 +782,7 @@ class _ChatDetailsPage extends State<ChatDetailsPage>
alignment: Alignment.centerLeft, alignment: Alignment.centerLeft,
child: GestureDetector( child: GestureDetector(
onLongPress: () { onLongPress: () {
showMessageMenu(context, _buttonKey, messages[position]); showMessageMenu(context, _buttonKey, message, index, loadanimatedListKey);
}, },
child: Container( child: Container(
decoration: BoxDecoration( decoration: BoxDecoration(
@ -760,7 +803,7 @@ class _ChatDetailsPage extends State<ChatDetailsPage>
horizontal: 12.w, horizontal: 12.w,
), ),
child: Text( child: Text(
tex = messages[position].content, tex = message.content,
textAlign: TextAlign.left, textAlign: TextAlign.left,
style: TextStyle( style: TextStyle(
height: 1.2.h, height: 1.2.h,
@ -789,7 +832,7 @@ class _ChatDetailsPage extends State<ChatDetailsPage>
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
children: [ children: [
if (messages[position].state == 3) if (message.state == 3)
Container( Container(
decoration: BoxDecoration( decoration: BoxDecoration(
borderRadius: BorderRadius.circular(100), borderRadius: BorderRadius.circular(100),
@ -808,7 +851,7 @@ class _ChatDetailsPage extends State<ChatDetailsPage>
), ),
), ),
), ),
if (messages[position].state == 3) if (message.state == 3)
SizedBox( SizedBox(
width: 12.w, width: 12.w,
), ),
@ -817,7 +860,7 @@ class _ChatDetailsPage extends State<ChatDetailsPage>
alignment: Alignment.centerRight, alignment: Alignment.centerRight,
child: InkWell( child: InkWell(
onLongPress: () { onLongPress: () {
showMessageMenu(context, _buttonKey, messages[position]); showMessageMenu(context, _buttonKey, message, index, loadanimatedListKey);
}, },
child: Container( child: Container(
decoration: BoxDecoration( decoration: BoxDecoration(
@ -838,7 +881,7 @@ class _ChatDetailsPage extends State<ChatDetailsPage>
horizontal: 12.w, horizontal: 12.w,
), ),
child: Text( child: Text(
tex = messages[position].content, tex = message.content,
textAlign: TextAlign.left, textAlign: TextAlign.left,
style: TextStyle( style: TextStyle(
height: 1.2, height: 1.2,
@ -901,18 +944,18 @@ class _ChatDetailsPage extends State<ChatDetailsPage>
), ),
GestureDetector( GestureDetector(
onLongPress: () { onLongPress: () {
showMessageMenu(context, _buttonKey, messages[position]); showMessageMenu(context, _buttonKey, message, index, loadanimatedListKey);
}, },
onTap: () { onTap: () {
if (imageUrl.contains(messages[position].attach) && (messages[position].attach?.isNotEmpty ?? false)) { if (imageUrl.contains(message.attach) && (message.attach?.isNotEmpty ?? false)) {
ImagePickers.previewImages(imageUrl, imageUrl.indexOf(messages[position].attach!)); ImagePickers.previewImages(imageUrl, imageUrl.indexOf(message.attach!));
} }
}, },
child: FutureBuilder( child: FutureBuilder(
future: fetchImageSize(messages[position]), future: fetchImageSize(message),
key: _buttonKey, key: _buttonKey,
builder: (BuildContext context, AsyncSnapshot snapshot) { builder: (BuildContext context, AsyncSnapshot snapshot) {
if (messages[position].attach?.isEmpty ?? true) { if (message.attach?.isEmpty ?? true) {
return SizedBox( return SizedBox(
width: 180.w, width: 180.w,
height: 200.h, height: 200.h,
@ -920,7 +963,7 @@ class _ChatDetailsPage extends State<ChatDetailsPage>
} }
if (snapshot.connectionState == ConnectionState.waiting || snapshot.hasError) { if (snapshot.connectionState == ConnectionState.waiting || snapshot.hasError) {
return Image.file( return Image.file(
File(messages[position].attach!), File(message.attach!),
width: 180.w, width: 180.w,
height: 200.h, height: 200.h,
alignment: Alignment.centerLeft, alignment: Alignment.centerLeft,
@ -928,7 +971,7 @@ class _ChatDetailsPage extends State<ChatDetailsPage>
); );
} else { } else {
return Image.file( return Image.file(
File(messages[position].attach!), File(message.attach!),
width: snapshot.data.width, width: snapshot.data.width,
height: snapshot.data.height, height: snapshot.data.height,
alignment: Alignment.centerLeft, alignment: Alignment.centerLeft,
@ -956,18 +999,18 @@ class _ChatDetailsPage extends State<ChatDetailsPage>
Spacer(), Spacer(),
GestureDetector( GestureDetector(
onLongPress: () { onLongPress: () {
showMessageMenu(context, _buttonKey, messages[position]); showMessageMenu(context, _buttonKey, message, index, loadanimatedListKey);
}, },
onTap: () { onTap: () {
if (imageUrl.contains(messages[position].attach) && (messages[position].attach?.isNotEmpty ?? false)) { if (imageUrl.contains(message.attach) && (message.attach?.isNotEmpty ?? false)) {
ImagePickers.previewImages(imageUrl, imageUrl.indexOf(messages[position].attach!)); ImagePickers.previewImages(imageUrl, imageUrl.indexOf(message.attach!));
} }
}, },
child: FutureBuilder ( child: FutureBuilder (
future: fetchImageSize(messages[position]), future: fetchImageSize(message),
key: _buttonKey, key: _buttonKey,
builder: (BuildContext context, AsyncSnapshot snapshot) { builder: (BuildContext context, AsyncSnapshot snapshot) {
if (messages[position].attach?.isEmpty ?? true) { if (message.attach?.isEmpty ?? true) {
return SizedBox( return SizedBox(
width: 180.w, width: 180.w,
height: 200.h, height: 200.h,
@ -975,7 +1018,7 @@ class _ChatDetailsPage extends State<ChatDetailsPage>
} }
if (snapshot.connectionState == ConnectionState.waiting || snapshot.hasError) { if (snapshot.connectionState == ConnectionState.waiting || snapshot.hasError) {
return Image.file( return Image.file(
File(messages[position].attach!), File(message.attach!),
width: 180.w, width: 180.w,
height: 200.h, height: 200.h,
alignment: Alignment.centerRight, alignment: Alignment.centerRight,
@ -983,7 +1026,7 @@ class _ChatDetailsPage extends State<ChatDetailsPage>
); );
} else { } else {
return Image.file( return Image.file(
File(messages[position].attach!), File(message.attach!),
width: snapshot.data.width, width: snapshot.data.width,
height: snapshot.data.height, height: snapshot.data.height,
alignment: Alignment.centerRight, alignment: Alignment.centerRight,
@ -1029,26 +1072,128 @@ class _ChatDetailsPage extends State<ChatDetailsPage>
} }
/// ///
showMessageMenu(context, _buttonKey, message) { showMessageMenu(context, _buttonKey, message, index, animatedListKey) {
RenderBox renderBox = _buttonKey.currentContext.findRenderObject() as RenderBox; RenderBox renderBox = _buttonKey.currentContext.findRenderObject() as RenderBox;
Offset buttonPosition = renderBox.localToGlobal(Offset.zero); Offset buttonPosition = renderBox.localToGlobal(Offset.zero);
Size buttonSize = renderBox.size; Size buttonSize = renderBox.size;
showMenu( // showMenu(
context: context, /// // context: context, ///
elevation: 0, // elevation: 0,
color: Colors.transparent, // color: Colors.transparent,
position: RelativeRect.fromLTRB( // position: RelativeRect.fromLTRB(
buttonPosition.dx + (buttonSize.width - 180.w) / 2, // // buttonPosition.dx + (buttonSize.width - 180.w) / 2, //
buttonPosition.dy - 68, // buttonPosition.dy - 68,
buttonPosition.dx + buttonSize.width, // buttonPosition.dx + buttonSize.width,
buttonPosition.dy, // buttonPosition.dy,
), // ),
/// // ///
items: [ // items: [
PopupMenuItem( // PopupMenuItem(
value: 1, // value: 1,
padding: EdgeInsets.zero, // padding: EdgeInsets.zero,
child: Stack( // child: Stack(
// alignment: Alignment.bottomCenter,
// children: [
// Container(
// padding: EdgeInsets.only(bottom: 13.h),
// child: Container(
// width: 180.w,
// decoration: BoxDecoration(
// color: Color(0xFF2A2A2A),
// borderRadius: BorderRadius.circular(6),
// ),
// padding: EdgeInsets.symmetric(
// horizontal: 32.w,
// vertical: 7.5.h,
// ),
// child: Row(
// mainAxisAlignment: MainAxisAlignment.spaceBetween,
// crossAxisAlignment: CrossAxisAlignment.center,
// children: [
// GestureDetector(
// onTap: () {
// setState(() {
// this.copy(message.content);
// Navigator.pop(context);
// });
// },
// child: Column(
// children: [
// Image.asset(
// "assets/image/icon_chat_copy.webp",
// height: 16,
// width: 16,
// ),
// SizedBox(
// height: 2.h,
// ),
// Text(
// "复制",
// textAlign:
// TextAlign.center,
// style: TextStyle(
// color: Colors.white,
// fontSize: 12.sp,
// fontWeight: MyFontWeight
// .regular,
// ),
// ),
// ],
// ),
// ),
// GestureDetector(
// onTap: () async {
// await hxDatabase.deleteByMsgId("${message.id}");
// if (animatedListKey == loadanimatedListKey) {
// loadmessages.remove(message);
// animatedListKey.currentState?.removeItem(index, (context, animation) {return Container();});
// } else {
// newmessages.remove(message);
// animatedListKey.currentState?.removeItem(index, (context, animation) {return Container();});
// }
// Navigator.pop(context);
// },
// child: Column(
// children: [
// Image.asset(
// "assets/image/icon_chat_delete.webp",
// height: 16,
// width: 16,
// ),
// SizedBox(
// height: 2.h,
// ),
// Text(
// S.of(context).shanchu,
// textAlign: TextAlign.center,
// style: TextStyle(
// color: Colors.white,
// fontSize: 12.sp,
// fontWeight: MyFontWeight.regular,
// ),
// ),
// ],
// ),
// ),
// ],
// ),
// ),
// ),
// Image.asset(
// "assets/image/icon_copy_j.webp",
// height: 17,
// width: 17,
// ),
// ],
// ),
// ),
// ],
// );
SmartDialog.showAttach(
targetContext: _buttonKey.currentContext,
builder: (ctx) {
return Stack(
alignment: Alignment.bottomCenter, alignment: Alignment.bottomCenter,
children: [ children: [
Container( Container(
@ -1101,9 +1246,13 @@ class _ChatDetailsPage extends State<ChatDetailsPage>
GestureDetector( GestureDetector(
onTap: () async { onTap: () async {
await hxDatabase.deleteByMsgId("${message.id}"); await hxDatabase.deleteByMsgId("${message.id}");
int index = messages.indexOf(message); if (animatedListKey == loadanimatedListKey) {
messages.remove(message); loadmessages.remove(message);
animatedListKey.currentState?.removeItem(index, (context, animation) {return Container();});
} else {
newmessages.remove(message);
animatedListKey.currentState?.removeItem(index, (context, animation) {return Container();}); animatedListKey.currentState?.removeItem(index, (context, animation) {return Container();});
}
Navigator.pop(context); Navigator.pop(context);
}, },
child: Column( child: Column(
@ -1138,10 +1287,10 @@ class _ChatDetailsPage extends State<ChatDetailsPage>
width: 17, width: 17,
), ),
], ],
),
),
],
); );
},
);
} }
Future<Size> fetchImageSize(Message message) async { Future<Size> fetchImageSize(Message message) async {
@ -1240,8 +1389,8 @@ class _ChatDetailsPage extends State<ChatDetailsPage>
socketClient.sendMessage(_toUser?.mid ?? '', commentText) socketClient.sendMessage(_toUser?.mid ?? '', commentText)
.then((value) { .then((value) {
Message message = value; Message message = value;
messages.add(message); newmessages.add(message);
animatedListKey.currentState?.insertItem(messages.length - 1); newanimatedListKey.currentState?.insertItem(newmessages.length - 1);
chatController.clear(); chatController.clear();
messageShowTime().then((value) { messageShowTime().then((value) {
refreshState(); refreshState();

Loading…
Cancel
Save