Skip to content

Commit

Permalink
fix: 评论区加载到底后状态不正确;移除dispose避免崩溃
Browse files Browse the repository at this point in the history
  • Loading branch information
orz12 committed Feb 22, 2024
1 parent 03b46bf commit e78cd8b
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 96 deletions.
5 changes: 2 additions & 3 deletions lib/pages/video/detail/reply/controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,21 +56,22 @@ class VideoReplyController extends GetxController {
if (isLoadingMore) {
return;
}
isLoadingMore = true;
if (type == 'init') {
currentPage = 0;
noMore.value = '';
}
if (noMore.value == '没有更多了') {
return;
}
isLoadingMore = true;
final res = await ReplyHttp.replyList(
oid: aid!,
pageNum: currentPage + 1,
ps: ps,
type: ReplyType.video.index,
sort: _sortType.index,
);
isLoadingMore = false;
if (res['status']) {
final List<ReplyItemModel> replies = res['data'].replies;
if (replies.isNotEmpty) {
Expand Down Expand Up @@ -105,8 +106,6 @@ class VideoReplyController extends GetxController {
replyList.addAll(replies);
}
}
isLoadingMore = false;
return res;
}

// 上拉加载
Expand Down
145 changes: 52 additions & 93 deletions lib/pages/video/detail/reply/view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ class _VideoReplyPanelState extends State<VideoReplyPanel>
late AnimationController fabAnimationCtr;
late ScrollController scrollController;

Future? _futureBuilderFuture;
bool _isFabVisible = true;
String replyLevel = '1';
late String heroTag;
Expand Down Expand Up @@ -66,7 +65,7 @@ class _VideoReplyPanelState extends State<VideoReplyPanel>
fabAnimationCtr = AnimationController(
vsync: this, duration: const Duration(milliseconds: 300));

_futureBuilderFuture = _videoReplyController.queryReplyList();
_videoReplyController.queryReplyList();

fabAnimationCtr.forward();
scrollListener();
Expand Down Expand Up @@ -121,21 +120,15 @@ class _VideoReplyPanelState extends State<VideoReplyPanel>
}
}

@override
void dispose() {
scrollController.removeListener(() {});
fabAnimationCtr.dispose();
// scrollController.dispose();
super.dispose();
}

@override
Widget build(BuildContext context) {
super.build(context);
return RefreshIndicator(
onRefresh: () async {
_videoReplyController.currentPage = 0;
return await _videoReplyController.queryReplyList();
_videoReplyController.noMore.value = '';
await _videoReplyController.queryReplyList();
},
child: Stack(
children: [
Expand Down Expand Up @@ -195,90 +188,56 @@ class _VideoReplyPanelState extends State<VideoReplyPanel>
),
),
),
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(
Expand Down

0 comments on commit e78cd8b

Please sign in to comment.