fix: 评论区加载到底后状态不正确;移除dispose避免崩溃

This commit is contained in:
orz12
2024-02-23 01:33:47 +08:00
parent 03b46bf6df
commit e78cd8b179
2 changed files with 54 additions and 96 deletions

View File

@@ -56,7 +56,6 @@ class VideoReplyController extends GetxController {
if (isLoadingMore) { if (isLoadingMore) {
return; return;
} }
isLoadingMore = true;
if (type == 'init') { if (type == 'init') {
currentPage = 0; currentPage = 0;
noMore.value = ''; noMore.value = '';
@@ -64,6 +63,7 @@ class VideoReplyController extends GetxController {
if (noMore.value == '没有更多了') { if (noMore.value == '没有更多了') {
return; return;
} }
isLoadingMore = true;
final res = await ReplyHttp.replyList( final res = await ReplyHttp.replyList(
oid: aid!, oid: aid!,
pageNum: currentPage + 1, pageNum: currentPage + 1,
@@ -71,6 +71,7 @@ class VideoReplyController extends GetxController {
type: ReplyType.video.index, type: ReplyType.video.index,
sort: _sortType.index, sort: _sortType.index,
); );
isLoadingMore = false;
if (res['status']) { if (res['status']) {
final List<ReplyItemModel> replies = res['data'].replies; final List<ReplyItemModel> replies = res['data'].replies;
if (replies.isNotEmpty) { if (replies.isNotEmpty) {
@@ -105,8 +106,6 @@ class VideoReplyController extends GetxController {
replyList.addAll(replies); replyList.addAll(replies);
} }
} }
isLoadingMore = false;
return res;
} }
// 上拉加载 // 上拉加载

View File

@@ -38,7 +38,6 @@ class _VideoReplyPanelState extends State<VideoReplyPanel>
late AnimationController fabAnimationCtr; late AnimationController fabAnimationCtr;
late ScrollController scrollController; late ScrollController scrollController;
Future? _futureBuilderFuture;
bool _isFabVisible = true; bool _isFabVisible = true;
String replyLevel = '1'; String replyLevel = '1';
late String heroTag; late String heroTag;
@@ -66,7 +65,7 @@ class _VideoReplyPanelState extends State<VideoReplyPanel>
fabAnimationCtr = AnimationController( fabAnimationCtr = AnimationController(
vsync: this, duration: const Duration(milliseconds: 300)); vsync: this, duration: const Duration(milliseconds: 300));
_futureBuilderFuture = _videoReplyController.queryReplyList(); _videoReplyController.queryReplyList();
fabAnimationCtr.forward(); fabAnimationCtr.forward();
scrollListener(); scrollListener();
@@ -121,13 +120,6 @@ class _VideoReplyPanelState extends State<VideoReplyPanel>
} }
} }
@override
void dispose() {
scrollController.removeListener(() {});
fabAnimationCtr.dispose();
// scrollController.dispose();
super.dispose();
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
@@ -135,7 +127,8 @@ class _VideoReplyPanelState extends State<VideoReplyPanel>
return RefreshIndicator( return RefreshIndicator(
onRefresh: () async { onRefresh: () async {
_videoReplyController.currentPage = 0; _videoReplyController.currentPage = 0;
return await _videoReplyController.queryReplyList(); _videoReplyController.noMore.value = '';
await _videoReplyController.queryReplyList();
}, },
child: Stack( child: Stack(
children: [ children: [
@@ -195,90 +188,56 @@ class _VideoReplyPanelState extends State<VideoReplyPanel>
), ),
), ),
), ),
FutureBuilder( Obx(
future: _futureBuilderFuture, () => _videoReplyController.isLoadingMore &&
builder: (BuildContext context, snapshot) { _videoReplyController.replyList.isEmpty
if (snapshot.connectionState == ConnectionState.done) { ? SliverList(
var data = snapshot.data; delegate: SliverChildBuilderDelegate(
if (data['status']) { (BuildContext context, index) {
// 请求成功 return const VideoReplySkeleton();
return Obx( }, childCount: 5),
() => _videoReplyController.isLoadingMore && )
_videoReplyController.replyList.isEmpty : SliverList(
? SliverList( delegate: SliverChildBuilderDelegate(
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(
(BuildContext context, index) { (BuildContext context, index) {
return const VideoReplySkeleton(); double bottom =
}, childCount: 5), 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( Positioned(