Browse Source

socketclient heartbeat

wr_202303
zsw 4 months ago
parent
commit
b0b2507f84
  1. 67
      lib/im/chat_details_page.dart

67
lib/im/chat_details_page.dart

@ -88,16 +88,9 @@ class _ChatDetailsPage extends State<ChatDetailsPage>
await refresh();
socketClient.addCallback(_toUser.mid, (Message message) {
messages.insert(0, message);
messages.insert(0, message..state = 1);
refreshState();
// if (scrollController.position != null) {
// double offset = scrollController.position.maxScrollExtent;
// debugPrint("offset: $offset");
// Future.delayed(const Duration(milliseconds: 500), () {
// scrollController.animateTo(offset + 108, duration: const Duration(milliseconds: 500), curve: Curves.easeIn);
// });
// }
if (scrollController.position != null) {
double maxScrollExtent = scrollController.position.maxScrollExtent;
double viewportDimensions = scrollController.position.viewportDimension;
@ -107,15 +100,12 @@ class _ChatDetailsPage extends State<ChatDetailsPage>
double offset = maxScrollExtent;
debugPrint("offset: $offset");
Future.delayed(const Duration(milliseconds: 500), () {
scrollController.animateTo(
offset + 108,
scrollController.animateTo(offset + 108,
duration: const Duration(milliseconds: 500),
curve: Curves.easeIn
);
curve: Curves.easeIn);
});
}
}
});
refreshState();
@ -124,16 +114,21 @@ class _ChatDetailsPage extends State<ChatDetailsPage>
});
}
refresh() async {
Future refresh() async {
List<Message> messagePage = await hxDatabase.queryUList(_toUser.mid, page: page + 1, pageSize: 10);
if (messagePage.isEmpty) {
refreshController.loadNoData();
return;
} else {
refreshController.loadComplete();
}
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;
return Future.value();
}
///
@ -144,8 +139,9 @@ class _ChatDetailsPage extends State<ChatDetailsPage>
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<UserInfo> baseData =
await apiService.queryInfo().catchError((onError) {});
if (baseData != null && baseData.isSuccess) {
@ -354,6 +350,26 @@ class _ChatDetailsPage extends State<ChatDetailsPage>
child: Column(
children: [
Expanded(
child: SmartRefresher(
enablePullDown: false,
enablePullUp: true,
header: MyHeader(),
reverse: true,
physics: BouncingScrollPhysics(),
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,
@ -375,6 +391,7 @@ class _ChatDetailsPage extends State<ChatDetailsPage>
],
),
),
),
flex: 1,
),
input()
@ -418,7 +435,8 @@ class _ChatDetailsPage extends State<ChatDetailsPage>
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),
@ -587,7 +605,8 @@ class _ChatDetailsPage extends State<ChatDetailsPage>
),
),
),
),),
),
),
),
],
),
@ -753,7 +772,7 @@ class _ChatDetailsPage extends State<ChatDetailsPage>
width: 12.w,
),
MImage(
userInfo?.headimg??"",
userInfo?.headimg ?? "",
isCircle: true,
height: 44.h,
width: 44.h,
@ -895,7 +914,8 @@ class _ChatDetailsPage extends State<ChatDetailsPage>
// scrollController.animateTo(offset + 108, duration: const Duration(milliseconds: 500), curve: Curves.easeIn);
// });
// }
if (scrollController.position.maxScrollExtent > scrollController.offset) {
if (scrollController.position.maxScrollExtent >
scrollController.offset) {
//
scrollController.animateTo(
scrollController.position.maxScrollExtent,
@ -920,7 +940,6 @@ class _ChatDetailsPage extends State<ChatDetailsPage>
// });
// }
// }
});
},
maxLines: 8,

Loading…
Cancel
Save