From e78cd8b179352ac6b969c9fc2b22186e199741dd Mon Sep 17 00:00:00 2001 From: orz12 Date: Fri, 23 Feb 2024 01:33:47 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=AF=84=E8=AE=BA=E5=8C=BA=E5=8A=A0?= =?UTF-8?q?=E8=BD=BD=E5=88=B0=E5=BA=95=E5=90=8E=E7=8A=B6=E6=80=81=E4=B8=8D?= =?UTF-8?q?=E6=AD=A3=E7=A1=AE=EF=BC=9B=E7=A7=BB=E9=99=A4dispose=E9=81=BF?= =?UTF-8?q?=E5=85=8D=E5=B4=A9=E6=BA=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/pages/video/detail/reply/controller.dart | 5 +- lib/pages/video/detail/reply/view.dart | 145 +++++++------------ 2 files changed, 54 insertions(+), 96 deletions(-) diff --git a/lib/pages/video/detail/reply/controller.dart b/lib/pages/video/detail/reply/controller.dart index 8f59cf89b..22d863399 100644 --- a/lib/pages/video/detail/reply/controller.dart +++ b/lib/pages/video/detail/reply/controller.dart @@ -56,7 +56,6 @@ class VideoReplyController extends GetxController { if (isLoadingMore) { return; } - isLoadingMore = true; if (type == 'init') { currentPage = 0; noMore.value = ''; @@ -64,6 +63,7 @@ class VideoReplyController extends GetxController { if (noMore.value == '没有更多了') { return; } + isLoadingMore = true; final res = await ReplyHttp.replyList( oid: aid!, pageNum: currentPage + 1, @@ -71,6 +71,7 @@ class VideoReplyController extends GetxController { type: ReplyType.video.index, sort: _sortType.index, ); + isLoadingMore = false; if (res['status']) { final List replies = res['data'].replies; if (replies.isNotEmpty) { @@ -105,8 +106,6 @@ class VideoReplyController extends GetxController { replyList.addAll(replies); } } - isLoadingMore = false; - return res; } // 上拉加载 diff --git a/lib/pages/video/detail/reply/view.dart b/lib/pages/video/detail/reply/view.dart index 1acb9e767..30bad39a3 100644 --- a/lib/pages/video/detail/reply/view.dart +++ b/lib/pages/video/detail/reply/view.dart @@ -38,7 +38,6 @@ class _VideoReplyPanelState extends State late AnimationController fabAnimationCtr; late ScrollController scrollController; - Future? _futureBuilderFuture; bool _isFabVisible = true; String replyLevel = '1'; late String heroTag; @@ -66,7 +65,7 @@ class _VideoReplyPanelState extends State fabAnimationCtr = AnimationController( vsync: this, duration: const Duration(milliseconds: 300)); - _futureBuilderFuture = _videoReplyController.queryReplyList(); + _videoReplyController.queryReplyList(); fabAnimationCtr.forward(); scrollListener(); @@ -121,13 +120,6 @@ class _VideoReplyPanelState extends State } } - @override - void dispose() { - scrollController.removeListener(() {}); - fabAnimationCtr.dispose(); - // scrollController.dispose(); - super.dispose(); - } @override Widget build(BuildContext context) { @@ -135,7 +127,8 @@ class _VideoReplyPanelState extends State return RefreshIndicator( onRefresh: () async { _videoReplyController.currentPage = 0; - return await _videoReplyController.queryReplyList(); + _videoReplyController.noMore.value = ''; + await _videoReplyController.queryReplyList(); }, child: Stack( children: [ @@ -195,90 +188,56 @@ class _VideoReplyPanelState extends State ), ), ), - FutureBuilder( - future: _futureBuilderFuture, - builder: (BuildContext context, snapshot) { - if (snapshot.connectionState == ConnectionState.done) { - var data = snapshot.data; - if (data['status']) { - // 请求成功 - return Obx( - () => _videoReplyController.isLoadingMore && - _videoReplyController.replyList.isEmpty - ? SliverList( - delegate: SliverChildBuilderDelegate( - (BuildContext context, index) { - return const VideoReplySkeleton(); - }, childCount: 5), - ) - : SliverList( - delegate: SliverChildBuilderDelegate( - (BuildContext context, index) { - double bottom = - MediaQuery.of(context).padding.bottom; - if (index == - _videoReplyController - .replyList.length) { - return Container( - padding: - EdgeInsets.only(bottom: bottom), - height: bottom + 100, - child: Center( - child: Obx( - () => Text( - _videoReplyController - .noMore.value, - style: TextStyle( - fontSize: 12, - color: Theme.of(context) - .colorScheme - .outline, - ), - ), - ), - ), - ); - } else { - return ReplyItem( - replyItem: _videoReplyController - .replyList[index], - showReplyRow: true, - replyLevel: replyLevel, - replyReply: (replyItem) => - replyReply(replyItem), - replyType: ReplyType.video, - ); - } - }, - childCount: - _videoReplyController.replyList.length + - 1, - ), - ), - ); - } else { - // 请求错误 - return HttpError( - errMsg: data['msg'], - fn: () { - setState(() { - _futureBuilderFuture = - _videoReplyController.queryReplyList(); - }); - }, - ); - } - } else { - // 骨架屏 - return SliverList( - delegate: SliverChildBuilderDelegate( + Obx( + () => _videoReplyController.isLoadingMore && + _videoReplyController.replyList.isEmpty + ? SliverList( + delegate: SliverChildBuilderDelegate( + (BuildContext context, index) { + return const VideoReplySkeleton(); + }, childCount: 5), + ) + : SliverList( + delegate: SliverChildBuilderDelegate( (BuildContext context, index) { - return const VideoReplySkeleton(); - }, childCount: 5), - ); - } - }, - ) + double bottom = + MediaQuery.of(context).padding.bottom; + if (index == + _videoReplyController.replyList.length) { + return Container( + padding: EdgeInsets.only(bottom: bottom), + height: bottom + 100, + child: Center( + child: Obx( + () => Text( + _videoReplyController.noMore.value, + style: TextStyle( + fontSize: 12, + color: Theme.of(context) + .colorScheme + .outline, + ), + ), + ), + ), + ); + } else { + return ReplyItem( + replyItem: + _videoReplyController.replyList[index], + showReplyRow: true, + replyLevel: replyLevel, + replyReply: (replyItem) => + replyReply(replyItem), + replyType: ReplyType.video, + ); + } + }, + childCount: + _videoReplyController.replyList.length + 1, + ), + ), + ), ], ), Positioned(