diff --git a/lib/im/chat_details_page.dart b/lib/im/chat_details_page.dart index ddf7aac5..284311f9 100644 --- a/lib/im/chat_details_page.dart +++ b/lib/im/chat_details_page.dart @@ -88,7 +88,7 @@ class _ChatDetailsPage extends State await refresh(); socketClient.addCallback(_toUser.mid, (Message message) { - messages.insert(0, message); + messages.insert(0, message..state = 1); refreshState(); jumpToBottom(); }); @@ -96,16 +96,21 @@ class _ChatDetailsPage extends State jumpToBottom(); } - refresh() async { + Future refresh() async { + List messagePage = await hxDatabase.queryUList(_toUser.mid, page: page + 1, pageSize: 10); + if (messagePage.isEmpty) { + refreshController.loadNoData(); + return; + } else { + refreshController.loadComplete(); + } 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; + return Future.value(); } ///查询个人信息 @@ -116,17 +121,18 @@ class _ChatDetailsPage extends State value.getString('user') != "") { userInfo = UserInfo.fromJson(jsonDecode(value.getString('user'))); } - if(apiService == null) - apiService = ApiService(Dio(), context: context, token: value.getString("token")); + if (apiService == null) + apiService = + ApiService(Dio(), context: context, token: value.getString("token")); BaseData baseData = - await apiService.queryInfo().catchError((onError) {}); + await apiService.queryInfo().catchError((onError) {}); if (baseData != null && baseData.isSuccess) { setState(() { userInfo = baseData.data; }); SharedPreferences.getInstance().then((value) => { - value.setString('user', jsonEncode(baseData.data)), - }); + value.setString('user', jsonEncode(baseData.data)), + }); } } @@ -328,25 +334,46 @@ class _ChatDetailsPage extends State child: Column( children: [ Expanded( - child: SingleChildScrollView( + child: SmartRefresher( + enablePullDown: false, + enablePullUp: true, + header: MyHeader(), + reverse: true, physics: BouncingScrollPhysics(), - controller: scrollController, - child: Column( - children: [ - GestureDetector( - behavior: HitTestBehavior.translucent, - onTap: () { - setState(() { - emojiShowing = false; - isKeyBoardShow = emojiShowing; - moreShow = false; - isKeyBoardShow = moreShow; - FocusScope.of(context).requestFocus(FocusNode()); - }); - }, - child: chatDetailsList(), - ), - ], + footer: CustomFooter( + loadStyle: LoadStyle.ShowWhenLoading, + builder: (BuildContext context, LoadStatus mode) { + return (messages.length == 0) + ? Container() + : MyFooter(mode); + }, + ), + controller: refreshController, + onLoading: () { + refresh().then((value) { + refreshState(); + }); + }, + child: SingleChildScrollView( + physics: BouncingScrollPhysics(), + controller: scrollController, + child: Column( + children: [ + GestureDetector( + behavior: HitTestBehavior.translucent, + onTap: () { + setState(() { + emojiShowing = false; + isKeyBoardShow = emojiShowing; + moreShow = false; + isKeyBoardShow = moreShow; + FocusScope.of(context).requestFocus(FocusNode()); + }); + }, + child: chatDetailsList(), + ), + ], + ), ), ), flex: 1, @@ -392,7 +419,8 @@ class _ChatDetailsPage extends State child: Column( children: [ Text( - AppUtils.timeFormatter(DateTime.fromMillisecondsSinceEpoch(int.parse(message.time))), + AppUtils.timeFormatter( + DateTime.fromMillisecondsSinceEpoch(int.parse(message.time))), textAlign: TextAlign.center, style: TextStyle( color: Color(0xFFA29E9E), @@ -528,40 +556,41 @@ class _ChatDetailsPage extends State child: Container( alignment: Alignment.centerLeft, child: Container( - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(6), - color: Color(0xFFFFFFFF), - boxShadow: [ - BoxShadow( - color: Color(0xFFA8A3A3).withAlpha(12), - offset: Offset(0, 4), - blurRadius: 4, - spreadRadius: 0, - ), - ], - ), - padding: EdgeInsets.symmetric( - vertical: 8.h, - horizontal: 12.w, - ), - child: GestureDetector( - onLongPress: () { - setState(() { - copyIndex = 1; - }); - }, - child: Text( - tex = message.content, - textAlign: TextAlign.left, - style: TextStyle( - height: 1.2.h, - color: Color(0XFF0D0D0D), - fontSize: 17.sp, - fontWeight: MyFontWeight.medium, + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(6), + color: Color(0xFFFFFFFF), + boxShadow: [ + BoxShadow( + color: Color(0xFFA8A3A3).withAlpha(12), + offset: Offset(0, 4), + blurRadius: 4, + spreadRadius: 0, + ), + ], + ), + padding: EdgeInsets.symmetric( + vertical: 8.h, + horizontal: 12.w, + ), + child: GestureDetector( + onLongPress: () { + setState(() { + copyIndex = 1; + }); + }, + child: Text( + tex = message.content, + textAlign: TextAlign.left, + style: TextStyle( + height: 1.2.h, + color: Color(0XFF0D0D0D), + fontSize: 17.sp, + fontWeight: MyFontWeight.medium, + ), ), ), ), - ),), + ), ), ], ), @@ -727,7 +756,7 @@ class _ChatDetailsPage extends State width: 12.w, ), MImage( - userInfo?.headimg??"", + userInfo?.headimg ?? "", isCircle: true, height: 44.h, width: 44.h,