diff --git a/lib/im/chat_details_page.dart b/lib/im/chat_details_page.dart index b0dee47f..048ea6fb 100644 --- a/lib/im/chat_details_page.dart +++ b/lib/im/chat_details_page.dart @@ -12,9 +12,12 @@ import 'package:huixiang/im/database/message.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'; @@ -69,7 +72,9 @@ class _ChatDetailsPage extends State // SmartDialog.showToast("聊天 $txt", alignment: Alignment.center); } + RefreshController refreshController = RefreshController(); List messages = []; + int page = 0; loadMessageList() async { ImUser imUser = await hxDatabase.queryImUserById(_toUser.mid); @@ -80,7 +85,7 @@ class _ChatDetailsPage extends State 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); @@ -119,6 +124,18 @@ class _ChatDetailsPage extends State }); } + refresh() async { + page += 1; + List messagePage = await hxDatabase.queryUList(_toUser.mid, page: page, pageSize: 10); + if (page == 1) { + messages = messagePage; + } else { + messages.addAll(messagePage); + } + refreshController.refreshCompleted(); + return; + } + ///查询个人信息 queryUser() async { final SharedPreferences value = await SharedPreferences.getInstance();