mirror of
https://github.com/bggRGjQaUbCoE/PiliPlus.git
synced 2026-05-29 12:38:34 +00:00
refactor: reply
This commit is contained in:
@@ -488,7 +488,7 @@ class VideoIntroController extends GetxController {
|
||||
final VideoReplyController videoReplyCtr =
|
||||
Get.find<VideoReplyController>(tag: heroTag);
|
||||
videoReplyCtr.aid = aid;
|
||||
videoReplyCtr.queryReplyList(type: 'init');
|
||||
videoReplyCtr.queryData();
|
||||
} catch (_) {}
|
||||
this.bvid = bvid;
|
||||
lastPlayCid.value = cid;
|
||||
|
||||
@@ -74,11 +74,8 @@ class _RelatedVideoPanelState extends State<RelatedVideoPanel>
|
||||
: loadingState is Error
|
||||
? HttpError(
|
||||
errMsg: '出错了',
|
||||
fn: () {
|
||||
_relatedController.loadingState.value =
|
||||
LoadingState.loading();
|
||||
_relatedController.queryData();
|
||||
})
|
||||
fn: _relatedController.onReload,
|
||||
)
|
||||
: SliverGrid(
|
||||
gridDelegate: SliverGridDelegateWithExtentAndRatio(
|
||||
mainAxisSpacing: StyleString.safeSpace,
|
||||
|
||||
@@ -1,142 +1,26 @@
|
||||
import 'package:PiliPalaX/utils/extension.dart';
|
||||
import 'package:easy_debounce/easy_throttle.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:hive/hive.dart';
|
||||
import 'package:PiliPalaX/http/loading_state.dart';
|
||||
import 'package:PiliPalaX/pages/common/reply_controller.dart';
|
||||
import 'package:PiliPalaX/http/reply.dart';
|
||||
import 'package:PiliPalaX/models/common/reply_sort_type.dart';
|
||||
import 'package:PiliPalaX/models/common/reply_type.dart';
|
||||
import 'package:PiliPalaX/models/video/reply/item.dart';
|
||||
import 'package:PiliPalaX/utils/feed_back.dart';
|
||||
import 'package:PiliPalaX/utils/storage.dart';
|
||||
|
||||
class VideoReplyController extends GetxController {
|
||||
class VideoReplyController extends ReplyController {
|
||||
VideoReplyController(
|
||||
this.aid,
|
||||
this.rpid,
|
||||
this.replyLevel,
|
||||
);
|
||||
final ScrollController scrollController = ScrollController();
|
||||
// 视频aid 请求时使用的oid
|
||||
int? aid;
|
||||
// 层级 2为楼中楼
|
||||
String? replyLevel;
|
||||
// rpid 请求楼中楼回复
|
||||
String? rpid;
|
||||
RxList<ReplyItemModel> replyList = <ReplyItemModel>[].obs;
|
||||
String nextOffset = "";
|
||||
bool isLoadingMore = false;
|
||||
RxString noMore = ''.obs;
|
||||
RxInt count = (-1).obs;
|
||||
// 当前回复的回复
|
||||
ReplyItemModel? currentReplyItem;
|
||||
|
||||
ReplySortType _sortType = ReplySortType.time;
|
||||
RxString sortTypeTitle = ReplySortType.time.titles.obs;
|
||||
RxString sortTypeLabel = ReplySortType.time.labels.obs;
|
||||
|
||||
Box setting = GStorage.setting;
|
||||
|
||||
Future? futureBuilderFuture;
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
int defaultReplySortIndex =
|
||||
setting.get(SettingBoxKey.replySortType, defaultValue: 1) as int;
|
||||
if (defaultReplySortIndex == 2) {
|
||||
setting.put(SettingBoxKey.replySortType, 0);
|
||||
defaultReplySortIndex = 0;
|
||||
}
|
||||
_sortType = ReplySortType.values[defaultReplySortIndex];
|
||||
sortTypeTitle.value = _sortType.titles;
|
||||
sortTypeLabel.value = _sortType.labels;
|
||||
}
|
||||
|
||||
Future queryReplyList({type = 'init'}) async {
|
||||
if (isLoadingMore) {
|
||||
return;
|
||||
}
|
||||
if (type == 'init') {
|
||||
nextOffset = '';
|
||||
noMore.value = '';
|
||||
}
|
||||
if (noMore.value == '没有更多了') return;
|
||||
isLoadingMore = true;
|
||||
final res = await ReplyHttp.replyList(
|
||||
oid: aid!,
|
||||
nextOffset: nextOffset,
|
||||
type: ReplyType.video.index,
|
||||
sort: _sortType.index,
|
||||
);
|
||||
isLoadingMore = false;
|
||||
if (res['status']) {
|
||||
final List<ReplyItemModel> replies = res['data'].replies;
|
||||
nextOffset = res['data'].cursor.paginationReply.nextOffset ?? "";
|
||||
if (replies.isNotEmpty) {
|
||||
noMore.value = '加载中...';
|
||||
|
||||
/// 第一页回复数小于20
|
||||
if (res['data'].cursor.isEnd == true) {
|
||||
noMore.value = '没有更多了';
|
||||
}
|
||||
} else {
|
||||
// 未登录状态replies可能返回null
|
||||
noMore.value = nextOffset == "" && type == 'init' ? '还没有评论' : '没有更多了';
|
||||
}
|
||||
if (type == 'init') {
|
||||
// 添加置顶回复
|
||||
if (res['data'].upper.top != null) {
|
||||
final bool flag = res['data'].topReplies.any((ReplyItemModel reply) =>
|
||||
reply.rpid == res['data'].upper.top.rpid) as bool;
|
||||
if (!flag) {
|
||||
replies.insert(0, res['data'].upper.top);
|
||||
}
|
||||
}
|
||||
replies.insertAll(0, res['data'].topReplies);
|
||||
count.value = res['data'].cursor.allCount ?? 0;
|
||||
replyList.value = replies;
|
||||
} else {
|
||||
replyList.addAll(replies);
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
// 上拉加载
|
||||
Future onLoad() async {
|
||||
queryReplyList(type: 'onLoad');
|
||||
}
|
||||
|
||||
// 排序搜索评论
|
||||
queryBySort() {
|
||||
EasyThrottle.throttle('queryBySort', const Duration(seconds: 1), () {
|
||||
feedBack();
|
||||
switch (_sortType) {
|
||||
case ReplySortType.time:
|
||||
_sortType = ReplySortType.like;
|
||||
break;
|
||||
case ReplySortType.like:
|
||||
_sortType = ReplySortType.time;
|
||||
break;
|
||||
default:
|
||||
}
|
||||
sortTypeTitle.value = _sortType.titles;
|
||||
sortTypeLabel.value = _sortType.labels;
|
||||
nextOffset = "";
|
||||
noMore.value = '';
|
||||
replyList.clear();
|
||||
queryReplyList(type: 'init');
|
||||
});
|
||||
}
|
||||
|
||||
void animToTop() {
|
||||
scrollController.animToTop();
|
||||
}
|
||||
|
||||
@override
|
||||
void onClose() {
|
||||
scrollController.dispose();
|
||||
super.onClose();
|
||||
}
|
||||
Future<LoadingState> customGetData() => ReplyHttp.replyList(
|
||||
oid: aid!,
|
||||
nextOffset: nextOffset,
|
||||
type: ReplyType.video.index,
|
||||
sort: sortType.index,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import 'package:PiliPalaX/common/widgets/http_error.dart';
|
||||
import 'package:PiliPalaX/http/loading_state.dart';
|
||||
import 'package:PiliPalaX/pages/video/detail/reply_new/reply_page.dart';
|
||||
import 'package:easy_debounce/easy_throttle.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
@@ -74,7 +75,6 @@ class _VideoReplyPanelState extends State<VideoReplyPanel>
|
||||
void dispose() {
|
||||
_videoReplyController.scrollController.removeListener(() {});
|
||||
fabAnimationCtr.dispose();
|
||||
// _videoReplyController.scrollController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@@ -86,7 +86,7 @@ class _VideoReplyPanelState extends State<VideoReplyPanel>
|
||||
300) {
|
||||
EasyThrottle.throttle('replylist', const Duration(milliseconds: 200),
|
||||
() {
|
||||
_videoReplyController.onLoad();
|
||||
_videoReplyController.onLoadMore();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -136,7 +136,7 @@ class _VideoReplyPanelState extends State<VideoReplyPanel>
|
||||
super.build(context);
|
||||
return RefreshIndicator(
|
||||
onRefresh: () async {
|
||||
await _videoReplyController.queryReplyList(type: 'init');
|
||||
await _videoReplyController.onRefresh();
|
||||
},
|
||||
child: Stack(
|
||||
children: [
|
||||
@@ -181,175 +181,7 @@ class _VideoReplyPanelState extends State<VideoReplyPanel>
|
||||
),
|
||||
),
|
||||
),
|
||||
FutureBuilder(
|
||||
future: _videoReplyController.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,
|
||||
onReply: () {
|
||||
dynamic oid = _videoReplyController
|
||||
.replyList[index].oid;
|
||||
dynamic root = _videoReplyController
|
||||
.replyList[index].rpid;
|
||||
dynamic parent = _videoReplyController
|
||||
.replyList[index].rpid;
|
||||
dynamic key = oid + root + parent;
|
||||
Navigator.of(context)
|
||||
.push(
|
||||
GetDialogRoute(
|
||||
pageBuilder: (buildContext,
|
||||
animation,
|
||||
secondaryAnimation) {
|
||||
return ReplyPage(
|
||||
oid: oid,
|
||||
root: root,
|
||||
parent: parent,
|
||||
replyType: ReplyType.video,
|
||||
replyItem:
|
||||
_videoReplyController
|
||||
.replyList[index],
|
||||
savedReply:
|
||||
_savedReplies[key],
|
||||
onSaveReply: (reply) {
|
||||
_savedReplies[key] = reply;
|
||||
},
|
||||
);
|
||||
},
|
||||
transitionDuration:
|
||||
const Duration(
|
||||
milliseconds: 500),
|
||||
transitionBuilder: (context,
|
||||
animation,
|
||||
secondaryAnimation,
|
||||
child) {
|
||||
const begin = Offset(0.0, 1.0);
|
||||
const end = Offset.zero;
|
||||
const curve = Curves.linear;
|
||||
|
||||
var tween = Tween(
|
||||
begin: begin, end: end)
|
||||
.chain(CurveTween(
|
||||
curve: curve));
|
||||
|
||||
return SlideTransition(
|
||||
position:
|
||||
animation.drive(tween),
|
||||
child: child,
|
||||
);
|
||||
},
|
||||
),
|
||||
)
|
||||
.then((value) {
|
||||
// 完成评论,数据添加
|
||||
if (value != null &&
|
||||
value['data'] != null) {
|
||||
_savedReplies[key] = null;
|
||||
}
|
||||
});
|
||||
},
|
||||
onDelete: (rpid, frpid) {
|
||||
_videoReplyController.replyList.value =
|
||||
frpid == null
|
||||
? _videoReplyController
|
||||
.replyList
|
||||
.where((item) =>
|
||||
item.rpid != rpid)
|
||||
.toList()
|
||||
: _videoReplyController
|
||||
.replyList
|
||||
.map((item) {
|
||||
if (item.rpid == frpid) {
|
||||
return item
|
||||
..replies = item
|
||||
.replies
|
||||
?.where((reply) =>
|
||||
reply.rpid !=
|
||||
rpid)
|
||||
.toList();
|
||||
} else {
|
||||
return item;
|
||||
}
|
||||
}).toList();
|
||||
},
|
||||
);
|
||||
}
|
||||
},
|
||||
childCount:
|
||||
_videoReplyController.replyList.length +
|
||||
1,
|
||||
),
|
||||
),
|
||||
);
|
||||
} else {
|
||||
// 请求错误
|
||||
return HttpError(
|
||||
errMsg: data['msg'],
|
||||
fn: () {
|
||||
setState(() {
|
||||
_videoReplyController.futureBuilderFuture =
|
||||
_videoReplyController.queryReplyList();
|
||||
});
|
||||
},
|
||||
);
|
||||
}
|
||||
} else {
|
||||
// 骨架屏
|
||||
return SliverList(
|
||||
delegate: SliverChildBuilderDelegate(
|
||||
(BuildContext context, index) {
|
||||
return const VideoReplySkeleton();
|
||||
}, childCount: 5),
|
||||
);
|
||||
}
|
||||
},
|
||||
),
|
||||
Obx(() => _buildBody(_videoReplyController.loadingState.value)),
|
||||
],
|
||||
),
|
||||
Positioned(
|
||||
@@ -407,8 +239,15 @@ class _VideoReplyPanelState extends State<VideoReplyPanel>
|
||||
// 完成评论,数据添加
|
||||
if (value != null && value['data'] != null) {
|
||||
_savedReplies[oid] = null;
|
||||
_videoReplyController.replyList
|
||||
.insert(0, value['data']);
|
||||
List list =
|
||||
_videoReplyController.loadingState.value is Success
|
||||
? (_videoReplyController.loadingState.value
|
||||
as Success)
|
||||
.response
|
||||
: [];
|
||||
list.insert(0, value['data']);
|
||||
_videoReplyController.loadingState.value =
|
||||
LoadingState.success(list);
|
||||
}
|
||||
},
|
||||
);
|
||||
@@ -444,6 +283,121 @@ class _VideoReplyPanelState extends State<VideoReplyPanel>
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildBody(LoadingState loadingState) {
|
||||
return loadingState is Success
|
||||
? SliverList(
|
||||
delegate: SliverChildBuilderDelegate(
|
||||
(BuildContext context, index) {
|
||||
double bottom = MediaQuery.of(context).padding.bottom;
|
||||
if (index == loadingState.response.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: loadingState.response[index],
|
||||
showReplyRow: true,
|
||||
replyLevel: replyLevel,
|
||||
replyReply: (replyItem) => replyReply(replyItem),
|
||||
replyType: ReplyType.video,
|
||||
onReply: () {
|
||||
dynamic oid = loadingState.response[index].oid;
|
||||
dynamic root = loadingState.response[index].rpid;
|
||||
dynamic parent = loadingState.response[index].rpid;
|
||||
dynamic key = oid + root + parent;
|
||||
Navigator.of(context)
|
||||
.push(
|
||||
GetDialogRoute(
|
||||
pageBuilder:
|
||||
(buildContext, animation, secondaryAnimation) {
|
||||
return ReplyPage(
|
||||
oid: oid,
|
||||
root: root,
|
||||
parent: parent,
|
||||
replyType: ReplyType.video,
|
||||
replyItem: loadingState.response[index],
|
||||
savedReply: _savedReplies[key],
|
||||
onSaveReply: (reply) {
|
||||
_savedReplies[key] = reply;
|
||||
},
|
||||
);
|
||||
},
|
||||
transitionDuration: const Duration(milliseconds: 500),
|
||||
transitionBuilder:
|
||||
(context, animation, secondaryAnimation, child) {
|
||||
const begin = Offset(0.0, 1.0);
|
||||
const end = Offset.zero;
|
||||
const curve = Curves.linear;
|
||||
|
||||
var tween = Tween(begin: begin, end: end)
|
||||
.chain(CurveTween(curve: curve));
|
||||
|
||||
return SlideTransition(
|
||||
position: animation.drive(tween),
|
||||
child: child,
|
||||
);
|
||||
},
|
||||
),
|
||||
)
|
||||
.then((value) {
|
||||
// 完成评论,数据添加
|
||||
if (value != null && value['data'] != null) {
|
||||
_savedReplies[key] = null;
|
||||
}
|
||||
});
|
||||
},
|
||||
onDelete: (rpid, frpid) {
|
||||
List list =
|
||||
(_videoReplyController.loadingState.value as Success)
|
||||
.response;
|
||||
list = frpid == null
|
||||
? list.where((item) => item.rpid != rpid).toList()
|
||||
: list.map((item) {
|
||||
if (item.rpid == frpid) {
|
||||
return item
|
||||
..replies = item.replies
|
||||
?.where((reply) => reply.rpid != rpid)
|
||||
.toList();
|
||||
} else {
|
||||
return item;
|
||||
}
|
||||
}).toList();
|
||||
_videoReplyController.loadingState.value =
|
||||
LoadingState.success(list);
|
||||
},
|
||||
);
|
||||
}
|
||||
},
|
||||
childCount: loadingState.response.length + 1,
|
||||
),
|
||||
)
|
||||
: loadingState is Error
|
||||
? HttpError(
|
||||
errMsg: loadingState.errMsg,
|
||||
fn: _videoReplyController.onReload,
|
||||
)
|
||||
: SliverList(
|
||||
delegate: SliverChildBuilderDelegate(
|
||||
(BuildContext context, index) {
|
||||
return const VideoReplySkeleton();
|
||||
},
|
||||
childCount: 5,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _MySliverPersistentHeaderDelegate extends SliverPersistentHeaderDelegate {
|
||||
|
||||
@@ -1,21 +1,19 @@
|
||||
import 'package:PiliPalaX/http/loading_state.dart';
|
||||
import 'package:PiliPalaX/pages/common/common_controller.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:PiliPalaX/http/reply.dart';
|
||||
import 'package:PiliPalaX/models/common/reply_type.dart';
|
||||
import 'package:PiliPalaX/models/video/reply/item.dart';
|
||||
|
||||
class VideoReplyReplyController extends GetxController {
|
||||
class VideoReplyReplyController extends CommonController {
|
||||
VideoReplyReplyController(this.aid, this.rpid, this.replyType);
|
||||
final ScrollController scrollController = ScrollController();
|
||||
// 视频aid 请求时使用的oid
|
||||
int? aid;
|
||||
// rpid 请求楼中楼回复
|
||||
String? rpid;
|
||||
ReplyType replyType; // = ReplyType.video;
|
||||
RxList<ReplyItemModel> replyList = <ReplyItemModel>[].obs;
|
||||
// 当前页
|
||||
int currentPage = 0;
|
||||
bool isLoadingMore = false;
|
||||
RxString noMore = ''.obs;
|
||||
// 当前回复的回复
|
||||
ReplyItemModel? currentReplyItem;
|
||||
@@ -24,54 +22,42 @@ class VideoReplyReplyController extends GetxController {
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
currentPage = 0;
|
||||
}
|
||||
|
||||
Future queryReplyList({type = 'init'}) async {
|
||||
if (type == 'init') {
|
||||
currentPage = 0;
|
||||
}
|
||||
if (isLoadingMore) {
|
||||
return;
|
||||
}
|
||||
isLoadingMore = true;
|
||||
final res = await ReplyHttp.replyReplyList(
|
||||
oid: aid!,
|
||||
root: rpid!,
|
||||
pageNum: currentPage + 1,
|
||||
type: replyType.index,
|
||||
);
|
||||
if (res['status']) {
|
||||
if (res['data'].root != null) root = res['data'].root;
|
||||
final List<ReplyItemModel> replies = res['data'].replies;
|
||||
if (replies.isNotEmpty) {
|
||||
noMore.value = '加载中...';
|
||||
if (replies.length == res['data'].page.count) {
|
||||
noMore.value = '没有更多了';
|
||||
}
|
||||
currentPage++;
|
||||
} else {
|
||||
// 未登录状态replies可能返回null
|
||||
noMore.value = currentPage == 0 ? '还没有评论' : '没有更多了';
|
||||
}
|
||||
if (type == 'init') {
|
||||
replyList.value = replies;
|
||||
} else {
|
||||
// 每次回复之后,翻页请求有且只有相同的一条回复数据
|
||||
if (replies.length == 1 && replies.last.rpid == replyList.last.rpid) {
|
||||
return;
|
||||
}
|
||||
replyList.addAll(replies);
|
||||
// res['data'].replies.addAll(replyList);
|
||||
}
|
||||
}
|
||||
isLoadingMore = false;
|
||||
return res;
|
||||
queryData();
|
||||
}
|
||||
|
||||
@override
|
||||
void onClose() {
|
||||
currentPage = 0;
|
||||
super.onClose();
|
||||
bool customHandleResponse(Success response) {
|
||||
if (response.response.root != null) root = response.response.root;
|
||||
List<ReplyItemModel> replies = response.response.replies;
|
||||
if (replies.isNotEmpty) {
|
||||
noMore.value = '加载中...';
|
||||
if (replies.length == response.response.page.count) {
|
||||
noMore.value = '没有更多了';
|
||||
}
|
||||
} else {
|
||||
// 未登录状态replies可能返回null
|
||||
noMore.value = currentPage == 1 ? '还没有评论' : '没有更多了';
|
||||
}
|
||||
if (currentPage != 1) {
|
||||
List<ReplyItemModel> list = loadingState.value is Success
|
||||
? (loadingState.value as Success).response
|
||||
: <ReplyItemModel>[];
|
||||
// 每次回复之后,翻页请求有且只有相同的一条回复数据
|
||||
if (replies.length == 1 && replies.last.rpid == list.last.rpid) {
|
||||
return true;
|
||||
} else {
|
||||
replies.insertAll(0, list);
|
||||
}
|
||||
}
|
||||
loadingState.value = LoadingState.success(replies);
|
||||
return true;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<LoadingState> customGetData() => ReplyHttp.replyReplyList(
|
||||
oid: aid!,
|
||||
root: rpid!,
|
||||
pageNum: currentPage,
|
||||
type: replyType.index,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import 'package:PiliPalaX/http/loading_state.dart';
|
||||
import 'package:PiliPalaX/pages/video/detail/reply_new/reply_page.dart';
|
||||
import 'package:easy_debounce/easy_throttle.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
@@ -37,7 +38,6 @@ class VideoReplyReplyPanel extends StatefulWidget {
|
||||
|
||||
class _VideoReplyReplyPanelState extends State<VideoReplyReplyPanel> {
|
||||
late VideoReplyReplyController _videoReplyReplyController;
|
||||
Future? _futureBuilderFuture;
|
||||
late final _savedReplies = {};
|
||||
|
||||
@override
|
||||
@@ -57,13 +57,11 @@ class _VideoReplyReplyPanelState extends State<VideoReplyReplyPanel> {
|
||||
300) {
|
||||
EasyThrottle.throttle('replylist', const Duration(milliseconds: 200),
|
||||
() {
|
||||
_videoReplyReplyController.queryReplyList(type: 'onLoad');
|
||||
_videoReplyReplyController.onLoadMore();
|
||||
});
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
_futureBuilderFuture = _videoReplyReplyController.queryReplyList();
|
||||
}
|
||||
|
||||
void replyReply(replyItem) {}
|
||||
@@ -71,7 +69,6 @@ class _VideoReplyReplyPanelState extends State<VideoReplyReplyPanel> {
|
||||
@override
|
||||
void dispose() {
|
||||
_videoReplyReplyController.scrollController.removeListener(() {});
|
||||
_videoReplyReplyController.scrollController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@@ -95,7 +92,6 @@ class _VideoReplyReplyPanelState extends State<VideoReplyReplyPanel> {
|
||||
tooltip: '关闭',
|
||||
icon: const Icon(Icons.close, size: 20),
|
||||
onPressed: () {
|
||||
_videoReplyReplyController.currentPage = 0;
|
||||
widget.closePanel!();
|
||||
Navigator.pop(context);
|
||||
},
|
||||
@@ -110,9 +106,7 @@ class _VideoReplyReplyPanelState extends State<VideoReplyReplyPanel> {
|
||||
Expanded(
|
||||
child: RefreshIndicator(
|
||||
onRefresh: () async {
|
||||
setState(() {});
|
||||
_videoReplyReplyController.currentPage = 0;
|
||||
return await _videoReplyReplyController.queryReplyList();
|
||||
await _videoReplyReplyController.onRefresh();
|
||||
},
|
||||
child: CustomScrollView(
|
||||
controller: _videoReplyReplyController.scrollController,
|
||||
@@ -126,7 +120,7 @@ class _VideoReplyReplyPanelState extends State<VideoReplyReplyPanel> {
|
||||
replyLevel: '2',
|
||||
showReplyRow: false,
|
||||
addReply: (replyItem) {
|
||||
_videoReplyReplyController.replyList.add(replyItem);
|
||||
// _videoReplyReplyController.replyList.add(replyItem);
|
||||
},
|
||||
replyType: widget.replyType,
|
||||
replyReply: replyReply,
|
||||
@@ -144,129 +138,8 @@ class _VideoReplyReplyPanelState extends State<VideoReplyReplyPanel> {
|
||||
),
|
||||
),
|
||||
],
|
||||
FutureBuilder(
|
||||
future: _futureBuilderFuture,
|
||||
builder: (BuildContext context, snapshot) {
|
||||
if (snapshot.connectionState == ConnectionState.done &&
|
||||
snapshot.hasData) {
|
||||
final Map data = snapshot.data as Map;
|
||||
if (data['status']) {
|
||||
// 请求成功
|
||||
return SliverMainAxisGroup(
|
||||
slivers: <Widget>[
|
||||
if (widget.firstFloor == null &&
|
||||
_videoReplyReplyController.root != null) ...[
|
||||
SliverToBoxAdapter(
|
||||
child: ReplyItem(
|
||||
replyItem: _videoReplyReplyController.root,
|
||||
replyLevel: '2',
|
||||
showReplyRow: false,
|
||||
addReply: (replyItem) {
|
||||
_videoReplyReplyController.replyList
|
||||
.add(replyItem);
|
||||
},
|
||||
replyType: widget.replyType,
|
||||
replyReply: replyReply,
|
||||
needDivider: false,
|
||||
onReply: () {
|
||||
_onReply(_videoReplyReplyController.root);
|
||||
},
|
||||
),
|
||||
),
|
||||
SliverToBoxAdapter(
|
||||
child: Divider(
|
||||
height: 20,
|
||||
color: Theme.of(context)
|
||||
.dividerColor
|
||||
.withOpacity(0.1),
|
||||
thickness: 6,
|
||||
),
|
||||
),
|
||||
],
|
||||
Obx(
|
||||
() => SliverList(
|
||||
delegate: SliverChildBuilderDelegate(
|
||||
(BuildContext context, int index) {
|
||||
if (index ==
|
||||
_videoReplyReplyController
|
||||
.replyList.length) {
|
||||
return Container(
|
||||
padding: EdgeInsets.only(
|
||||
bottom: MediaQuery.of(context)
|
||||
.padding
|
||||
.bottom),
|
||||
height: MediaQuery.of(context)
|
||||
.padding
|
||||
.bottom +
|
||||
100,
|
||||
child: Center(
|
||||
child: Obx(
|
||||
() => Text(
|
||||
_videoReplyReplyController
|
||||
.noMore.value,
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
color: Theme.of(context)
|
||||
.colorScheme
|
||||
.outline,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
} else {
|
||||
return ReplyItem(
|
||||
replyItem: _videoReplyReplyController
|
||||
.replyList[index],
|
||||
replyLevel: '2',
|
||||
showReplyRow: false,
|
||||
addReply: (replyItem) {
|
||||
_videoReplyReplyController.replyList
|
||||
.add(replyItem);
|
||||
},
|
||||
replyType: widget.replyType,
|
||||
onReply: () {
|
||||
_onReply(_videoReplyReplyController
|
||||
.replyList[index]);
|
||||
},
|
||||
onDelete: (rpid, frpid) {
|
||||
_videoReplyReplyController
|
||||
.replyList.value =
|
||||
_videoReplyReplyController
|
||||
.replyList
|
||||
.where((item) =>
|
||||
item.rpid != rpid)
|
||||
.toList();
|
||||
},
|
||||
);
|
||||
}
|
||||
},
|
||||
childCount: _videoReplyReplyController
|
||||
.replyList.length +
|
||||
1,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
} else {
|
||||
// 请求错误
|
||||
return HttpError(
|
||||
errMsg: data['msg'],
|
||||
fn: () => setState(() {}),
|
||||
);
|
||||
}
|
||||
} else {
|
||||
// 骨架屏
|
||||
return SliverList(
|
||||
delegate: SliverChildBuilderDelegate(
|
||||
(BuildContext context, int index) {
|
||||
return const VideoReplySkeleton();
|
||||
}, childCount: 8),
|
||||
);
|
||||
}
|
||||
},
|
||||
)
|
||||
Obx(() => _buildBody(
|
||||
_videoReplyReplyController.loadingState.value)),
|
||||
],
|
||||
),
|
||||
),
|
||||
@@ -320,4 +193,95 @@ class _VideoReplyReplyPanelState extends State<VideoReplyReplyPanel> {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Widget _buildBody(LoadingState loadingState) {
|
||||
return loadingState is Success
|
||||
? SliverMainAxisGroup(
|
||||
slivers: <Widget>[
|
||||
if (widget.firstFloor == null &&
|
||||
_videoReplyReplyController.root != null) ...[
|
||||
SliverToBoxAdapter(
|
||||
child: ReplyItem(
|
||||
replyItem: _videoReplyReplyController.root,
|
||||
replyLevel: '2',
|
||||
showReplyRow: false,
|
||||
addReply: (replyItem) {
|
||||
// _videoReplyReplyController.replyList.add(replyItem);
|
||||
},
|
||||
replyType: widget.replyType,
|
||||
replyReply: replyReply,
|
||||
needDivider: false,
|
||||
onReply: () {
|
||||
_onReply(_videoReplyReplyController.root);
|
||||
},
|
||||
),
|
||||
),
|
||||
SliverToBoxAdapter(
|
||||
child: Divider(
|
||||
height: 20,
|
||||
color: Theme.of(context).dividerColor.withOpacity(0.1),
|
||||
thickness: 6,
|
||||
),
|
||||
),
|
||||
],
|
||||
SliverList(
|
||||
delegate: SliverChildBuilderDelegate(
|
||||
(BuildContext context, int index) {
|
||||
if (index == loadingState.response.length) {
|
||||
return Container(
|
||||
padding: EdgeInsets.only(
|
||||
bottom: MediaQuery.of(context).padding.bottom),
|
||||
height: MediaQuery.of(context).padding.bottom + 100,
|
||||
child: Center(
|
||||
child: Obx(
|
||||
() => Text(
|
||||
_videoReplyReplyController.noMore.value,
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
color: Theme.of(context).colorScheme.outline,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
} else {
|
||||
return ReplyItem(
|
||||
replyItem: loadingState.response[index],
|
||||
replyLevel: '2',
|
||||
showReplyRow: false,
|
||||
addReply: (replyItem) {
|
||||
// _videoReplyReplyController.replyList.add(replyItem);
|
||||
},
|
||||
replyType: widget.replyType,
|
||||
onReply: () {
|
||||
_onReply(loadingState.response[index]);
|
||||
},
|
||||
onDelete: (rpid, frpid) {
|
||||
// _videoReplyReplyController.replyList.value =
|
||||
// _videoReplyReplyController.replyList
|
||||
// .where((item) => item.rpid != rpid)
|
||||
// .toList();
|
||||
},
|
||||
);
|
||||
}
|
||||
},
|
||||
childCount: loadingState.response.length + 1,
|
||||
),
|
||||
),
|
||||
],
|
||||
)
|
||||
: loadingState is Error
|
||||
? HttpError(
|
||||
errMsg: loadingState.errMsg,
|
||||
fn: _videoReplyReplyController.onReload,
|
||||
)
|
||||
: SliverList(
|
||||
delegate: SliverChildBuilderDelegate(
|
||||
(BuildContext context, int index) {
|
||||
return const VideoReplySkeleton();
|
||||
},
|
||||
childCount: 8,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -148,8 +148,7 @@ class _VideoDetailPageState extends State<VideoDetailPage>
|
||||
// 获取视频资源,初始化播放器
|
||||
Future<void> videoSourceInit() async {
|
||||
_futureBuilderFuture = videoDetailController.queryVideoUrl();
|
||||
_videoReplyController.futureBuilderFuture =
|
||||
_videoReplyController.queryReplyList(type: 'init');
|
||||
_videoReplyController.queryData();
|
||||
if (videoDetailController.autoPlay.value) {
|
||||
plPlayerController = videoDetailController.plPlayerController;
|
||||
plPlayerController!.addStatusLister(playerListener);
|
||||
@@ -429,7 +428,7 @@ class _VideoDetailPageState extends State<VideoDetailPage>
|
||||
if (value == 0) {
|
||||
_introController.animToTop();
|
||||
} else {
|
||||
_videoReplyController.animToTop();
|
||||
_videoReplyController.animateToTop();
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user