Browse Source

socketclient heartbeat

wr_202303
zsw 4 months ago
parent
commit
d8bd13c4eb
  1. 39
      lib/im/chat_details_page.dart

39
lib/im/chat_details_page.dart

@ -11,9 +11,12 @@ import 'package:huixiang/im/out/message.pb.dart';
import 'package:huixiang/main.dart';
import 'package:huixiang/retrofit/data/im_user.dart';
import 'package:huixiang/retrofit/retrofit_api.dart';
import 'package:huixiang/view_widget/classic_header.dart';
import 'package:huixiang/view_widget/my_appbar.dart';
import 'package:flutter/cupertino.dart';
import 'package:huixiang/view_widget/my_footer.dart';
import 'package:image_pickers/image_pickers.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';
import 'package:shared_preferences/shared_preferences.dart';
import '../../community/release_dynamic.dart';
import '../../generated/l10n.dart';
@ -64,7 +67,9 @@ class _ChatDetailsPage extends State<ChatDetailsPage>
// SmartDialog.showToast("聊天 $txt", alignment: Alignment.center);
}
RefreshController refreshController = RefreshController();
List<Message> messages = [];
int page = 0;
loadMessageList() async {
ImUser imUser = await hxDatabase.queryImUserById(_toUser.mid);
@ -75,7 +80,7 @@ class _ChatDetailsPage extends State<ChatDetailsPage>
selfUserId = (await SharedPreferences.getInstance()).getString("userId");
// unread msg 2 read state
await hxDatabase.readMessage(selfUserId, _toUser.mid);
messages = await hxDatabase.queryUList(_toUser.mid, pageSize: 100);
await refresh();
socketClient.addCallback(_toUser.mid, (Message message) {
messages.insert(0, message);
@ -97,6 +102,18 @@ class _ChatDetailsPage extends State<ChatDetailsPage>
});
}
refresh() async {
page += 1;
List<Message> messagePage = await hxDatabase.queryUList(_toUser.mid, page: page, pageSize: 10);
if (page == 1) {
messages = messagePage;
} else {
messages.addAll(messagePage);
}
refreshController.refreshCompleted();
return;
}
refreshState() {
if (mounted) setState(() {});
}
@ -292,6 +309,24 @@ class _ChatDetailsPage extends State<ChatDetailsPage>
child: Column(
children: [
Expanded(
child: SmartRefresher(
enablePullDown: true,
enablePullUp: false,
header: MyHeader(),
physics: BouncingScrollPhysics(),
footer: CustomFooter(
loadStyle: LoadStyle.ShowWhenLoading,
builder: (BuildContext context, LoadStatus mode) {
return (messages.length == 0) ? Container() : MyFooter(mode);
},
),
controller: refreshController,
onRefresh: () {
refresh().then((){
refreshState();
});
},
onLoading: () {},
child: SingleChildScrollView(
physics: BouncingScrollPhysics(),
controller: scrollController,
@ -313,6 +348,7 @@ class _ChatDetailsPage extends State<ChatDetailsPage>
],
),
),
),
flex: 1,
),
input()
@ -326,6 +362,7 @@ class _ChatDetailsPage extends State<ChatDetailsPage>
Widget chatDetailsList() {
return Container(
margin: EdgeInsets.only(bottom: 48.h),
alignment: Alignment.bottomCenter,
child: ListView.builder(
itemCount: messages.length,
shrinkWrap: true,

Loading…
Cancel
Save