Browse Source

chat add conversation ,database query change userId to conversationId

wr_202303
zsw 4 months ago
parent
commit
a4206f9b9d
  1. 306
      lib/im/chat_details_page.dart

306
lib/im/chat_details_page.dart

@ -67,7 +67,7 @@ class _ChatDetailsPage extends State<ChatDetailsPage>
int copyIndex = 0; int copyIndex = 0;
String selfUserId = ""; String selfUserId = "";
ImUser _toUser; ImUser _toUser;
String conversation ; String conversation;
@override @override
void onMessage(txt) { void onMessage(txt) {
@ -124,7 +124,8 @@ class _ChatDetailsPage extends State<ChatDetailsPage>
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) { for (var value in messages) {
Message message = messagePages.firstWhere((element) => value.id == element.id, orElse: () => null); Message message = messagePages
.firstWhere((element) => value.id == element.id, orElse: () => null);
value.showTime = message != null; value.showTime = message != null;
} }
} }
@ -142,8 +143,10 @@ class _ChatDetailsPage extends State<ChatDetailsPage>
} }
} }
if (apiService == null) if (apiService == null)
apiService = ApiService(Dio(), context: context, token: value.getString("token")); apiService =
BaseData<UserInfo> baseData = await apiService.queryInfo().catchError((onError) {}); ApiService(Dio(), context: context, token: value.getString("token"));
BaseData<UserInfo> baseData =
await apiService.queryInfo().catchError((onError) {});
if (baseData != null && baseData.isSuccess) { if (baseData != null && baseData.isSuccess) {
setState(() { setState(() {
userInfo = baseData.data; userInfo = baseData.data;
@ -323,83 +326,83 @@ class _ChatDetailsPage extends State<ChatDetailsPage>
} }
} }
return GestureDetector( return GestureDetector(
behavior: HitTestBehavior.translucent, behavior: HitTestBehavior.translucent,
onTap: () { onTap: () {
FocusScope.of(context).requestFocus(FocusNode()); FocusScope.of(context).requestFocus(FocusNode());
setState(() { setState(() {
emojiShowing = false; emojiShowing = false;
isKeyBoardShow = emojiShowing; isKeyBoardShow = emojiShowing;
moreShow = false; moreShow = false;
isKeyBoardShow = moreShow; isKeyBoardShow = moreShow;
}); });
}, },
child: Scaffold( child: Scaffold(
// resizeToAvoidBottomInset: false, // resizeToAvoidBottomInset: false,
backgroundColor: Color(0xFFF6F6F6), backgroundColor: Color(0xFFF6F6F6),
appBar: MyAppBar( appBar: MyAppBar(
title: _toUser.nickname, title: _toUser.nickname,
titleColor: Color(0xFF0D0D0D), titleColor: Color(0xFF0D0D0D),
titleSize: 17.sp, titleSize: 17.sp,
leading: true, leading: true,
leadingColor: Colors.black, leadingColor: Colors.black,
action: GestureDetector( action: GestureDetector(
behavior: HitTestBehavior.opaque, behavior: HitTestBehavior.opaque,
onTap: () async { onTap: () async {
await Navigator.of(context).pushNamed('/router/chat_setting', await Navigator.of(context).pushNamed('/router/chat_setting',
arguments: {"userId": _toUser.mid}); arguments: {"userId": _toUser.mid});
page = 0; page = 0;
refresh().then((value) { refresh().then((value) {
refreshState(); refreshState();
}); });
}, },
child: Container( child: Container(
alignment: Alignment.center, alignment: Alignment.center,
child: Icon( child: Icon(
Icons.more_horiz, Icons.more_horiz,
color: Colors.black, color: Colors.black,
size: 30, size: 30,
),
), ),
), ),
), ),
body: Container( ),
child: Column( body: Container(
children: [ child: Column(
Expanded( children: [
child: SmartRefresher( Expanded(
enablePullDown: false, child: SmartRefresher(
enablePullUp: true, enablePullDown: false,
header: MyHeader(), enablePullUp: true,
reverse: true, header: MyHeader(),
physics: BouncingScrollPhysics(), reverse: true,
footer: CustomFooter( physics: BouncingScrollPhysics(),
loadStyle: LoadStyle.ShowWhenLoading, footer: CustomFooter(
builder: (BuildContext context, LoadStatus mode) { loadStyle: LoadStyle.ShowWhenLoading,
return SizedBox(); builder: (BuildContext context, LoadStatus mode) {
}, return SizedBox();
),
controller: refreshController,
onLoading: () {
refresh().then((value) {
refreshState();
});
}, },
child: Container( ),
alignment: Alignment.topCenter, controller: refreshController,
child: SingleChildScrollView( onLoading: () {
physics: BouncingScrollPhysics(), refresh().then((value) {
controller: scrollController, refreshState();
child: chatDetailsList(), });
), },
child: Container(
alignment: Alignment.topCenter,
child: SingleChildScrollView(
physics: BouncingScrollPhysics(),
controller: scrollController,
child: chatDetailsList(),
), ),
), ),
flex: 1,
), ),
input() flex: 1,
], ),
), input()
],
), ),
), ),
),
); );
} }
@ -444,12 +447,12 @@ class _ChatDetailsPage extends State<ChatDetailsPage>
// position == messages.length-1 // position == messages.length-1
// ? // ?
AppUtils.milliTimeFormatter(DateTime.fromMillisecondsSinceEpoch( AppUtils.milliTimeFormatter(DateTime.fromMillisecondsSinceEpoch(
int.parse(messages[position].time))) int.parse(messages[position].time)))
// : AppUtils.getTimeDisplay( // : AppUtils.getTimeDisplay(
// DateTime.fromMillisecondsSinceEpoch( // DateTime.fromMillisecondsSinceEpoch(
// int.parse(messages[position].time)), // int.parse(messages[position].time)),
// DateTime.fromMillisecondsSinceEpoch( // DateTime.fromMillisecondsSinceEpoch(
// int.parse(messages[position+1].time))) // int.parse(messages[position+1].time)))
, ,
textAlign: TextAlign.center, textAlign: TextAlign.center,
style: TextStyle( style: TextStyle(
@ -1139,84 +1142,83 @@ class _ChatDetailsPage extends State<ChatDetailsPage>
context: context, context: context,
builder: (BuildContext context) { builder: (BuildContext context) {
return AlertDialog( return AlertDialog(
// backgroundColor: Color(0xFF2A2A2A), // backgroundColor: Color(0xFF2A2A2A),
// elevation: 0, // elevation: 0,
contentPadding: EdgeInsets.only( contentPadding: EdgeInsets.only(
top: 8.h, top: 8.h,
bottom: 5.h, bottom: 5.h,
),
content: Container(
width: 160.w,
height:50.h,
decoration: BoxDecoration(
color: Color(0xFF2A2A2A),
borderRadius: BorderRadius.circular(6),
),
padding: EdgeInsets.symmetric(
horizontal: 32.w,
vertical: 7.5.h,
), ),
child: Row( content: Container(
mainAxisAlignment: MainAxisAlignment.spaceBetween, width: 160.w,
crossAxisAlignment: CrossAxisAlignment.center, height: 50.h,
children: [ decoration: BoxDecoration(
GestureDetector( color: Color(0xFF2A2A2A),
onTap: () { borderRadius: BorderRadius.circular(6),
setState(() { ),
copyIndex = 0; padding: EdgeInsets.symmetric(
this.copy(tex); horizontal: 32.w,
}); vertical: 7.5.h,
}, ),
child: Column( child: Row(
children: [ mainAxisAlignment: MainAxisAlignment.spaceBetween,
Image.asset( crossAxisAlignment: CrossAxisAlignment.center,
"assets/image/icon_chat_copy.webp", children: [
height: 16, GestureDetector(
width: 16, onTap: () {
), setState(() {
SizedBox( copyIndex = 0;
height: 2.h, this.copy(tex);
), });
Text( },
"复制", child: Column(
textAlign: TextAlign.center, children: [
style: TextStyle( Image.asset(
color: Colors.white, "assets/image/icon_chat_copy.webp",
fontSize: 12.sp, height: 16,
fontWeight: MyFontWeight.regular, width: 16,
), ),
), SizedBox(
], height: 2.h,
),
),
GestureDetector(
onTap: () {},
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,
), ),
), Text(
], "复制",
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.white,
fontSize: 12.sp,
fontWeight: MyFontWeight.regular,
),
),
],
),
), ),
) GestureDetector(
], onTap: () {},
), 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,
),
),
],
),
)
],
),
));
}); });
} }

Loading…
Cancel
Save