diff --git a/lib/im/chat_details_page.dart b/lib/im/chat_details_page.dart index 98eb5086..d7e4a85d 100644 --- a/lib/im/chat_details_page.dart +++ b/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 // SmartDialog.showToast("聊天 $txt", alignment: Alignment.center); } + RefreshController refreshController = RefreshController(); List messages = []; + int page = 0; loadMessageList() async { ImUser imUser = await hxDatabase.queryImUserById(_toUser.mid); @@ -75,7 +80,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); @@ -97,6 +102,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; + } + refreshState() { if (mounted) setState(() {}); } @@ -292,7 +309,25 @@ class _ChatDetailsPage extends State child: Column( children: [ Expanded( - child: SingleChildScrollView( + 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, child: Column( @@ -313,6 +348,7 @@ class _ChatDetailsPage extends State ], ), ), + ), flex: 1, ), input() @@ -326,6 +362,7 @@ class _ChatDetailsPage extends State Widget chatDetailsList() { return Container( margin: EdgeInsets.only(bottom: 48.h), + alignment: Alignment.bottomCenter, child: ListView.builder( itemCount: messages.length, shrinkWrap: true,