mirror of
https://github.com/HChaZZY/PiliPlus.git
synced 2025-12-06 09:13:48 +08:00
refactor: reply
This commit is contained in:
@@ -1,3 +1,5 @@
|
|||||||
|
import 'package:PiliPalaX/http/loading_state.dart';
|
||||||
|
import 'package:PiliPalaX/utils/extension.dart';
|
||||||
import 'package:dio/dio.dart';
|
import 'package:dio/dio.dart';
|
||||||
|
|
||||||
import '../models/video/reply/data.dart';
|
import '../models/video/reply/data.dart';
|
||||||
@@ -8,7 +10,7 @@ import 'init.dart';
|
|||||||
|
|
||||||
class ReplyHttp {
|
class ReplyHttp {
|
||||||
static final _dio = Dio();
|
static final _dio = Dio();
|
||||||
static Future replyList({
|
static Future<LoadingState> replyList({
|
||||||
required int oid,
|
required int oid,
|
||||||
required String nextOffset,
|
required String nextOffset,
|
||||||
required int type,
|
required int type,
|
||||||
@@ -23,27 +25,16 @@ class ReplyHttp {
|
|||||||
'mode': sort + 2, //2:按时间排序;3:按热度排序
|
'mode': sort + 2, //2:按时间排序;3:按热度排序
|
||||||
});
|
});
|
||||||
if (res.data['code'] == 0) {
|
if (res.data['code'] == 0) {
|
||||||
return {
|
return LoadingState.success(ReplyData.fromJson(res.data['data']));
|
||||||
'status': true,
|
|
||||||
'data': ReplyData.fromJson(res.data['data']),
|
|
||||||
};
|
|
||||||
} else {
|
} else {
|
||||||
return {
|
return LoadingState.error(res.data['message']);
|
||||||
'status': false,
|
|
||||||
'date': [],
|
|
||||||
'msg': res.data['message'],
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return {
|
return LoadingState.error(e.toString());
|
||||||
'status': false,
|
|
||||||
'date': [],
|
|
||||||
'msg': e.toString(),
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static Future replyReplyList({
|
static Future<LoadingState> replyReplyList({
|
||||||
required int oid,
|
required int oid,
|
||||||
required String root,
|
required String root,
|
||||||
required int pageNum,
|
required int pageNum,
|
||||||
@@ -61,23 +52,12 @@ class ReplyHttp {
|
|||||||
'csrf': await Request.getCsrf(),
|
'csrf': await Request.getCsrf(),
|
||||||
});
|
});
|
||||||
if (res.data['code'] == 0) {
|
if (res.data['code'] == 0) {
|
||||||
return {
|
return LoadingState.success(ReplyReplyData.fromJson(res.data['data']));
|
||||||
'status': true,
|
|
||||||
'data': ReplyReplyData.fromJson(res.data['data']),
|
|
||||||
};
|
|
||||||
} else {
|
} else {
|
||||||
return {
|
return LoadingState.error(res.data['message']);
|
||||||
'status': false,
|
|
||||||
'date': [],
|
|
||||||
'msg': res.data['message'],
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return {
|
return LoadingState.error(e.toString());
|
||||||
'status': false,
|
|
||||||
'date': [],
|
|
||||||
'msg': e.toString(),
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -294,7 +294,7 @@ class BangumiIntroController extends GetxController {
|
|||||||
VideoReplyController videoReplyCtr =
|
VideoReplyController videoReplyCtr =
|
||||||
Get.find<VideoReplyController>(tag: Get.arguments['heroTag']);
|
Get.find<VideoReplyController>(tag: Get.arguments['heroTag']);
|
||||||
videoReplyCtr.aid = aid;
|
videoReplyCtr.aid = aid;
|
||||||
videoReplyCtr.queryReplyList(type: 'init');
|
videoReplyCtr.queryData();
|
||||||
} catch (_) {}
|
} catch (_) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ class _BangumiPageState extends State<BangumiPage>
|
|||||||
super.build(context);
|
super.build(context);
|
||||||
return RefreshIndicator(
|
return RefreshIndicator(
|
||||||
onRefresh: () async {
|
onRefresh: () async {
|
||||||
await _bangumiController.queryData();
|
await _bangumiController.onRefresh();
|
||||||
await _bangumiController.queryBangumiFollow();
|
await _bangumiController.queryBangumiFollow();
|
||||||
},
|
},
|
||||||
child: CustomScrollView(
|
child: CustomScrollView(
|
||||||
@@ -154,11 +154,8 @@ class _BangumiPageState extends State<BangumiPage>
|
|||||||
? (_bangumiController.loadingState.value as Error)
|
? (_bangumiController.loadingState.value as Error)
|
||||||
.errMsg
|
.errMsg
|
||||||
: '没有相关数据',
|
: '没有相关数据',
|
||||||
fn: () {
|
fn: _bangumiController.onReload,
|
||||||
_bangumiController.loadingState.value =
|
),
|
||||||
LoadingState.loading();
|
|
||||||
_bangumiController.onRefresh();
|
|
||||||
}),
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -12,10 +12,14 @@ abstract class CommonController extends GetxController {
|
|||||||
|
|
||||||
Future<LoadingState> customGetData();
|
Future<LoadingState> customGetData();
|
||||||
|
|
||||||
List? handleResponse(List currentList, List dataList) {
|
List? handleListResponse(List currentList, List dataList) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool customHandleResponse(Success response) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
void handleSuccess(List currentList, List dataList) {}
|
void handleSuccess(List currentList, List dataList) {}
|
||||||
|
|
||||||
Future queryData([bool isRefresh = true]) async {
|
Future queryData([bool isRefresh = true]) async {
|
||||||
@@ -23,17 +27,19 @@ abstract class CommonController extends GetxController {
|
|||||||
isLoading = true;
|
isLoading = true;
|
||||||
LoadingState response = await customGetData();
|
LoadingState response = await customGetData();
|
||||||
if (response is Success) {
|
if (response is Success) {
|
||||||
|
if (!customHandleResponse(response)) {
|
||||||
|
List currentList = loadingState.value is Success
|
||||||
|
? (loadingState.value as Success).response
|
||||||
|
: [];
|
||||||
|
List? handleList = handleListResponse(currentList, response.response);
|
||||||
|
loadingState.value = isRefresh
|
||||||
|
? handleList != null
|
||||||
|
? LoadingState.success(handleList)
|
||||||
|
: response
|
||||||
|
: LoadingState.success(currentList + response.response);
|
||||||
|
handleSuccess(currentList, response.response);
|
||||||
|
}
|
||||||
currentPage++;
|
currentPage++;
|
||||||
List currentList = loadingState.value is Success
|
|
||||||
? (loadingState.value as Success).response
|
|
||||||
: [];
|
|
||||||
List? handleList = handleResponse(currentList, response.response);
|
|
||||||
loadingState.value = isRefresh
|
|
||||||
? handleList != null
|
|
||||||
? LoadingState.success(handleList)
|
|
||||||
: response
|
|
||||||
: LoadingState.success(currentList + response.response);
|
|
||||||
handleSuccess(currentList, response.response);
|
|
||||||
} else {
|
} else {
|
||||||
if (isRefresh) {
|
if (isRefresh) {
|
||||||
loadingState.value = response;
|
loadingState.value = response;
|
||||||
@@ -55,6 +61,11 @@ abstract class CommonController extends GetxController {
|
|||||||
scrollController.animToTop();
|
scrollController.animToTop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void onReload() {
|
||||||
|
loadingState.value = LoadingState.loading();
|
||||||
|
queryData();
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void onClose() {
|
void onClose() {
|
||||||
scrollController.dispose();
|
scrollController.dispose();
|
||||||
|
|||||||
108
lib/pages/common/reply_controller.dart
Normal file
108
lib/pages/common/reply_controller.dart
Normal file
@@ -0,0 +1,108 @@
|
|||||||
|
import 'package:PiliPalaX/http/loading_state.dart';
|
||||||
|
import 'package:PiliPalaX/pages/common/common_controller.dart';
|
||||||
|
import 'package:easy_debounce/easy_throttle.dart';
|
||||||
|
import 'package:get/get.dart';
|
||||||
|
import 'package:PiliPalaX/models/common/reply_sort_type.dart';
|
||||||
|
import 'package:PiliPalaX/models/video/reply/item.dart';
|
||||||
|
import 'package:PiliPalaX/utils/feed_back.dart';
|
||||||
|
import 'package:PiliPalaX/utils/storage.dart';
|
||||||
|
|
||||||
|
abstract class ReplyController extends CommonController {
|
||||||
|
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;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void onInit() {
|
||||||
|
super.onInit();
|
||||||
|
int defaultReplySortIndex = GStorage.setting
|
||||||
|
.get(SettingBoxKey.replySortType, defaultValue: 1) as int;
|
||||||
|
if (defaultReplySortIndex == 2) {
|
||||||
|
GStorage.setting.put(SettingBoxKey.replySortType, 0);
|
||||||
|
defaultReplySortIndex = 0;
|
||||||
|
}
|
||||||
|
sortType = ReplySortType.values[defaultReplySortIndex];
|
||||||
|
sortTypeTitle.value = sortType.titles;
|
||||||
|
sortTypeLabel.value = sortType.labels;
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future onRefresh() {
|
||||||
|
nextOffset = '';
|
||||||
|
noMore.value = '';
|
||||||
|
return super.onRefresh();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future queryData([bool isRefresh = true]) {
|
||||||
|
if (noMore.value == '没有更多了') return Future.value();
|
||||||
|
return super.queryData(isRefresh);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool customHandleResponse(Success response) {
|
||||||
|
List<ReplyItemModel> replies = response.response.replies;
|
||||||
|
nextOffset = response.response.cursor.paginationReply.nextOffset ?? "";
|
||||||
|
if (replies.isNotEmpty) {
|
||||||
|
noMore.value = '加载中...';
|
||||||
|
|
||||||
|
/// 第一页回复数小于20
|
||||||
|
if (currentPage == 1 && replies.length < 18) {
|
||||||
|
noMore.value = '没有更多了';
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// 未登录状态replies可能返回null
|
||||||
|
noMore.value = nextOffset == "" && currentPage == 1 ? '还没有评论' : '没有更多了';
|
||||||
|
}
|
||||||
|
if (currentPage == 1) {
|
||||||
|
// 添加置顶回复
|
||||||
|
if (response.response.upper.top != null) {
|
||||||
|
final bool flag = response.response.topReplies.any(
|
||||||
|
(ReplyItemModel reply) =>
|
||||||
|
reply.rpid == response.response.upper.top.rpid) as bool;
|
||||||
|
if (!flag) {
|
||||||
|
replies.insert(0, response.response.upper.top);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
replies.insertAll(0, response.response.topReplies);
|
||||||
|
count.value = response.response.cursor.allCount ?? 0;
|
||||||
|
} else {
|
||||||
|
replies.insertAll(
|
||||||
|
0,
|
||||||
|
loadingState.value is Success
|
||||||
|
? (loadingState.value as Success).response
|
||||||
|
: <ReplyItemModel>[]);
|
||||||
|
}
|
||||||
|
loadingState.value = LoadingState.success(replies);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 排序搜索评论
|
||||||
|
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 = '';
|
||||||
|
loadingState.value = LoadingState.loading();
|
||||||
|
onRefresh();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,30 +1,15 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:PiliPalaX/http/loading_state.dart';
|
||||||
|
import 'package:PiliPalaX/pages/common/reply_controller.dart';
|
||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
import 'package:hive/hive.dart';
|
|
||||||
import 'package:PiliPalaX/http/html.dart';
|
import 'package:PiliPalaX/http/html.dart';
|
||||||
import 'package:PiliPalaX/http/reply.dart';
|
import 'package:PiliPalaX/http/reply.dart';
|
||||||
import 'package:PiliPalaX/models/common/reply_sort_type.dart';
|
|
||||||
import 'package:PiliPalaX/models/video/reply/item.dart';
|
|
||||||
import 'package:PiliPalaX/utils/feed_back.dart';
|
|
||||||
import 'package:PiliPalaX/utils/storage.dart';
|
|
||||||
|
|
||||||
class DynamicDetailController extends GetxController {
|
class DynamicDetailController extends ReplyController {
|
||||||
DynamicDetailController(this.oid, this.type);
|
DynamicDetailController(this.oid, this.type);
|
||||||
int? oid;
|
int? oid;
|
||||||
int? type;
|
int? type;
|
||||||
dynamic item;
|
dynamic item;
|
||||||
int? floor;
|
int? floor;
|
||||||
String nextOffset = "";
|
|
||||||
bool isLoadingMore = false;
|
|
||||||
RxString noMore = ''.obs;
|
|
||||||
RxList<ReplyItemModel> replyList = <ReplyItemModel>[].obs;
|
|
||||||
RxInt acount = 0.obs;
|
|
||||||
final ScrollController scrollController = ScrollController();
|
|
||||||
|
|
||||||
ReplySortType _sortType = ReplySortType.time;
|
|
||||||
RxString sortTypeTitle = ReplySortType.time.titles.obs;
|
|
||||||
RxString sortTypeLabel = ReplySortType.time.labels.obs;
|
|
||||||
Box setting = GStorage.setting;
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void onInit() {
|
void onInit() {
|
||||||
@@ -32,83 +17,10 @@ class DynamicDetailController extends GetxController {
|
|||||||
item = Get.arguments['item'];
|
item = Get.arguments['item'];
|
||||||
floor = Get.arguments['floor'];
|
floor = Get.arguments['floor'];
|
||||||
if (floor == 1) {
|
if (floor == 1) {
|
||||||
acount.value =
|
count.value = int.parse(item!.modules!.moduleStat!.comment!.count ?? '0');
|
||||||
int.parse(item!.modules!.moduleStat!.comment!.count ?? '0');
|
|
||||||
}
|
}
|
||||||
int defaultReplySortIndex =
|
|
||||||
setting.get(SettingBoxKey.replySortType, defaultValue: 1);
|
|
||||||
if (defaultReplySortIndex == 2) {
|
|
||||||
setting.put(SettingBoxKey.replySortType, 0);
|
|
||||||
defaultReplySortIndex = 0;
|
|
||||||
}
|
|
||||||
_sortType = ReplySortType.values[defaultReplySortIndex];
|
|
||||||
sortTypeTitle.value = _sortType.titles;
|
|
||||||
sortTypeLabel.value = _sortType.labels;
|
|
||||||
}
|
|
||||||
|
|
||||||
Future queryReplyList({reqType = 'init'}) async {
|
queryData();
|
||||||
if (reqType == 'init') {
|
|
||||||
nextOffset = "";
|
|
||||||
noMore.value = "";
|
|
||||||
}
|
|
||||||
if (isLoadingMore) return;
|
|
||||||
if (noMore.value == '没有更多了') return;
|
|
||||||
isLoadingMore = true;
|
|
||||||
var res = await ReplyHttp.replyList(
|
|
||||||
oid: oid!,
|
|
||||||
nextOffset: nextOffset,
|
|
||||||
type: type!,
|
|
||||||
sort: _sortType.index,
|
|
||||||
);
|
|
||||||
isLoadingMore = false;
|
|
||||||
if (res['status']) {
|
|
||||||
List<ReplyItemModel> replies = res['data'].replies;
|
|
||||||
acount.value = res['data'].cursor.allCount ?? 0;
|
|
||||||
nextOffset = res['data'].cursor.paginationReply.nextOffset ?? "";
|
|
||||||
if (replies.isNotEmpty) {
|
|
||||||
noMore.value = '加载中...';
|
|
||||||
if (res['data'].cursor.isEnd == true) {
|
|
||||||
noMore.value = '没有更多了';
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
noMore.value =
|
|
||||||
nextOffset == "" && reqType == 'init' ? '还没有评论' : '没有更多了';
|
|
||||||
}
|
|
||||||
if (reqType == 'init') {
|
|
||||||
// 添加置顶回复
|
|
||||||
if (res['data'].upper.top != null) {
|
|
||||||
bool flag = res['data']
|
|
||||||
.topReplies
|
|
||||||
.any((reply) => reply.rpid == res['data'].upper.top.rpid);
|
|
||||||
if (!flag) {
|
|
||||||
replies.insert(0, res['data'].upper.top);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
replies.insertAll(0, res['data'].topReplies);
|
|
||||||
replyList.value = replies;
|
|
||||||
} else {
|
|
||||||
replyList.addAll(replies);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 排序搜索评论
|
|
||||||
queryBySort() {
|
|
||||||
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;
|
|
||||||
replyList.clear();
|
|
||||||
queryReplyList(reqType: 'init');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 根据jumpUrl获取动态html
|
// 根据jumpUrl获取动态html
|
||||||
@@ -116,4 +28,12 @@ class DynamicDetailController extends GetxController {
|
|||||||
var res = await HtmlHttp.reqHtml(id, 'opus');
|
var res = await HtmlHttp.reqHtml(id, 'opus');
|
||||||
oid = res['commentId'];
|
oid = res['commentId'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<LoadingState> customGetData() => ReplyHttp.replyList(
|
||||||
|
oid: oid!,
|
||||||
|
nextOffset: nextOffset,
|
||||||
|
type: type!,
|
||||||
|
sort: sortType.index,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
import 'dart:math';
|
import 'dart:math';
|
||||||
|
|
||||||
|
import 'package:PiliPalaX/http/loading_state.dart';
|
||||||
import 'package:easy_debounce/easy_throttle.dart';
|
import 'package:easy_debounce/easy_throttle.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/rendering.dart';
|
import 'package:flutter/rendering.dart';
|
||||||
@@ -32,7 +33,6 @@ class _DynamicDetailPageState extends State<DynamicDetailPage>
|
|||||||
with TickerProviderStateMixin {
|
with TickerProviderStateMixin {
|
||||||
late DynamicDetailController _dynamicDetailController;
|
late DynamicDetailController _dynamicDetailController;
|
||||||
late AnimationController fabAnimationCtr;
|
late AnimationController fabAnimationCtr;
|
||||||
Future? _futureBuilderFuture;
|
|
||||||
late StreamController<bool> titleStreamC; // appBar title
|
late StreamController<bool> titleStreamC; // appBar title
|
||||||
late ScrollController scrollController;
|
late ScrollController scrollController;
|
||||||
bool _visibleTitle = false;
|
bool _visibleTitle = false;
|
||||||
@@ -103,8 +103,6 @@ class _DynamicDetailPageState extends State<DynamicDetailPage>
|
|||||||
_dynamicDetailController =
|
_dynamicDetailController =
|
||||||
Get.put(DynamicDetailController(oid, replyType), tag: oid.toString());
|
Get.put(DynamicDetailController(oid, replyType), tag: oid.toString());
|
||||||
}
|
}
|
||||||
_futureBuilderFuture =
|
|
||||||
_dynamicDetailController.queryReplyList(reqType: 'init');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 查看二级评论
|
// 查看二级评论
|
||||||
@@ -141,7 +139,7 @@ class _DynamicDetailPageState extends State<DynamicDetailPage>
|
|||||||
if (scrollController.position.pixels >=
|
if (scrollController.position.pixels >=
|
||||||
scrollController.position.maxScrollExtent - 300) {
|
scrollController.position.maxScrollExtent - 300) {
|
||||||
EasyThrottle.throttle('replylist', const Duration(seconds: 2), () {
|
EasyThrottle.throttle('replylist', const Duration(seconds: 2), () {
|
||||||
_dynamicDetailController.queryReplyList(reqType: 'onLoad');
|
_dynamicDetailController.onLoadMore();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -185,7 +183,6 @@ class _DynamicDetailPageState extends State<DynamicDetailPage>
|
|||||||
titleStreamC.close();
|
titleStreamC.close();
|
||||||
fabAnimationCtr.dispose();
|
fabAnimationCtr.dispose();
|
||||||
scrollController.removeListener(() {});
|
scrollController.removeListener(() {});
|
||||||
scrollController.dispose();
|
|
||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -212,7 +209,7 @@ class _DynamicDetailPageState extends State<DynamicDetailPage>
|
|||||||
),
|
),
|
||||||
body: RefreshIndicator(
|
body: RefreshIndicator(
|
||||||
onRefresh: () async {
|
onRefresh: () async {
|
||||||
await _dynamicDetailController.queryReplyList(reqType: 'init');
|
await _dynamicDetailController.onRefresh();
|
||||||
},
|
},
|
||||||
child: Stack(
|
child: Stack(
|
||||||
children: [
|
children: [
|
||||||
@@ -231,7 +228,10 @@ class _DynamicDetailPageState extends State<DynamicDetailPage>
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
replyPersistentHeader(context),
|
replyPersistentHeader(context),
|
||||||
replyList(),
|
Obx(
|
||||||
|
() => replyList(
|
||||||
|
_dynamicDetailController.loadingState.value),
|
||||||
|
),
|
||||||
]
|
]
|
||||||
.map<Widget>((e) => SliverPadding(
|
.map<Widget>((e) => SliverPadding(
|
||||||
padding: EdgeInsets.symmetric(horizontal: padding),
|
padding: EdgeInsets.symmetric(horizontal: padding),
|
||||||
@@ -265,8 +265,12 @@ class _DynamicDetailPageState extends State<DynamicDetailPage>
|
|||||||
padding: EdgeInsets.only(right: padding / 2),
|
padding: EdgeInsets.only(right: padding / 2),
|
||||||
sliver: replyPersistentHeader(context)),
|
sliver: replyPersistentHeader(context)),
|
||||||
SliverPadding(
|
SliverPadding(
|
||||||
padding: EdgeInsets.only(right: padding / 2),
|
padding: EdgeInsets.only(right: padding / 2),
|
||||||
sliver: replyList()),
|
sliver: Obx(
|
||||||
|
() => replyList(_dynamicDetailController
|
||||||
|
.loadingState.value),
|
||||||
|
),
|
||||||
|
),
|
||||||
]
|
]
|
||||||
// .map<Widget>(
|
// .map<Widget>(
|
||||||
// (e) => SliverPadding(padding: padding, sliver: e))
|
// (e) => SliverPadding(padding: padding, sliver: e))
|
||||||
@@ -306,14 +310,22 @@ class _DynamicDetailPageState extends State<DynamicDetailPage>
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
).then(
|
).then(
|
||||||
(value) => {
|
(value) {
|
||||||
// 完成评论,数据添加
|
// 完成评论,数据添加
|
||||||
if (value != null && value['data'] != null)
|
if (value != null && value['data'] != null) {
|
||||||
{
|
_dynamicDetailController.count.value++;
|
||||||
_dynamicDetailController.replyList
|
if (value != null && value['data'] != null) {
|
||||||
.add(value['data']),
|
List list = _dynamicDetailController
|
||||||
_dynamicDetailController.acount.value++
|
.loadingState.value is Success
|
||||||
|
? (_dynamicDetailController.loadingState.value
|
||||||
|
as Success)
|
||||||
|
.response
|
||||||
|
: [];
|
||||||
|
list.insert(0, value['data']);
|
||||||
|
_dynamicDetailController.loadingState.value =
|
||||||
|
LoadingState.success(list);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
@@ -353,8 +365,8 @@ class _DynamicDetailPageState extends State<DynamicDetailPage>
|
|||||||
return ScaleTransition(scale: animation, child: child);
|
return ScaleTransition(scale: animation, child: child);
|
||||||
},
|
},
|
||||||
child: Text(
|
child: Text(
|
||||||
'${_dynamicDetailController.acount.value}条回复',
|
'${_dynamicDetailController.count.value}条回复',
|
||||||
key: ValueKey<int>(_dynamicDetailController.acount.value),
|
key: ValueKey<int>(_dynamicDetailController.count.value),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -378,85 +390,57 @@ class _DynamicDetailPageState extends State<DynamicDetailPage>
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
FutureBuilder<dynamic> replyList() {
|
Widget replyList(LoadingState loadingState) {
|
||||||
return FutureBuilder(
|
return loadingState is Success
|
||||||
future: _futureBuilderFuture,
|
? SliverList(
|
||||||
builder: (context, snapshot) {
|
delegate: SliverChildBuilderDelegate(
|
||||||
if (snapshot.connectionState == ConnectionState.done &&
|
(context, index) {
|
||||||
snapshot.hasData) {
|
if (index == loadingState.response.length) {
|
||||||
Map data = snapshot.data as Map;
|
return Container(
|
||||||
if (snapshot.data['status']) {
|
padding: EdgeInsets.only(
|
||||||
// 请求成功
|
bottom: MediaQuery.of(context).padding.bottom),
|
||||||
return Obx(
|
height: MediaQuery.of(context).padding.bottom + 100,
|
||||||
() => _dynamicDetailController.replyList.isEmpty &&
|
child: Center(
|
||||||
_dynamicDetailController.isLoadingMore
|
child: Obx(
|
||||||
? SliverList(
|
() => Text(
|
||||||
delegate: SliverChildBuilderDelegate((context, index) {
|
_dynamicDetailController.noMore.value,
|
||||||
return const VideoReplySkeleton();
|
style: TextStyle(
|
||||||
}, childCount: 8),
|
fontSize: 12,
|
||||||
)
|
color: Theme.of(context).colorScheme.outline,
|
||||||
: SliverList(
|
),
|
||||||
delegate: SliverChildBuilderDelegate(
|
),
|
||||||
(context, index) {
|
|
||||||
if (index ==
|
|
||||||
_dynamicDetailController.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(
|
|
||||||
_dynamicDetailController.noMore.value,
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 12,
|
|
||||||
color:
|
|
||||||
Theme.of(context).colorScheme.outline,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
return ReplyItem(
|
|
||||||
replyItem:
|
|
||||||
_dynamicDetailController.replyList[index],
|
|
||||||
showReplyRow: true,
|
|
||||||
replyLevel: '1',
|
|
||||||
replyReply: replyReply,
|
|
||||||
replyType: ReplyType.values[replyType],
|
|
||||||
addReply: (replyItem) {
|
|
||||||
_dynamicDetailController
|
|
||||||
.replyList[index].replies!
|
|
||||||
.add(replyItem);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
childCount:
|
|
||||||
_dynamicDetailController.replyList.length + 1,
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
// 请求错误
|
return ReplyItem(
|
||||||
return HttpError(
|
replyItem: loadingState.response[index],
|
||||||
errMsg: data['msg'],
|
showReplyRow: true,
|
||||||
fn: () => setState(() {}),
|
replyLevel: '1',
|
||||||
);
|
replyReply: replyReply,
|
||||||
}
|
replyType: ReplyType.values[replyType],
|
||||||
} else {
|
addReply: (replyItem) {
|
||||||
// 骨架屏
|
// loadingState.response[index].replies!.add(replyItem);
|
||||||
return SliverList(
|
},
|
||||||
delegate: SliverChildBuilderDelegate((context, index) {
|
);
|
||||||
return const VideoReplySkeleton();
|
}
|
||||||
}, childCount: 8),
|
},
|
||||||
);
|
childCount: loadingState.response.length + 1,
|
||||||
}
|
),
|
||||||
},
|
)
|
||||||
);
|
: loadingState is Error
|
||||||
|
? HttpError(
|
||||||
|
errMsg: loadingState.errMsg,
|
||||||
|
fn: _dynamicDetailController.onReload,
|
||||||
|
)
|
||||||
|
: SliverList(
|
||||||
|
delegate: SliverChildBuilderDelegate(
|
||||||
|
(context, index) {
|
||||||
|
return const VideoReplySkeleton();
|
||||||
|
},
|
||||||
|
childCount: 8,
|
||||||
|
),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -90,11 +90,8 @@ class _HotPageState extends State<HotPage> with AutomaticKeepAliveClientMixin {
|
|||||||
? (_hotController.loadingState.value as Error)
|
? (_hotController.loadingState.value as Error)
|
||||||
.errMsg
|
.errMsg
|
||||||
: '没有相关数据',
|
: '没有相关数据',
|
||||||
fn: () {
|
fn: _hotController.onReload,
|
||||||
_hotController.loadingState.value =
|
),
|
||||||
LoadingState.loading();
|
|
||||||
_hotController.onRefresh();
|
|
||||||
}),
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -1,31 +1,18 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:PiliPalaX/http/loading_state.dart';
|
||||||
|
import 'package:PiliPalaX/pages/common/reply_controller.dart';
|
||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
import 'package:hive/hive.dart';
|
|
||||||
import 'package:PiliPalaX/http/html.dart';
|
import 'package:PiliPalaX/http/html.dart';
|
||||||
import 'package:PiliPalaX/http/reply.dart';
|
import 'package:PiliPalaX/http/reply.dart';
|
||||||
import 'package:PiliPalaX/models/common/reply_sort_type.dart';
|
|
||||||
import 'package:PiliPalaX/models/video/reply/item.dart';
|
|
||||||
import 'package:PiliPalaX/utils/feed_back.dart';
|
|
||||||
import 'package:PiliPalaX/utils/storage.dart';
|
|
||||||
|
|
||||||
class HtmlRenderController extends GetxController {
|
class HtmlRenderController extends ReplyController {
|
||||||
late String id;
|
late String id;
|
||||||
late String dynamicType;
|
late String dynamicType;
|
||||||
late int type;
|
late int type;
|
||||||
RxInt oid = (-1).obs;
|
RxInt oid = (-1).obs;
|
||||||
late Map response;
|
late Map response;
|
||||||
int? floor;
|
int? floor;
|
||||||
String nextOffset = "";
|
|
||||||
bool isLoadingMore = false;
|
|
||||||
RxString noMore = ''.obs;
|
|
||||||
RxList<ReplyItemModel> replyList = <ReplyItemModel>[].obs;
|
|
||||||
RxInt acount = 0.obs;
|
|
||||||
final ScrollController scrollController = ScrollController();
|
|
||||||
|
|
||||||
late ReplySortType _sortType;
|
RxBool loaded = false.obs;
|
||||||
late RxString sortTypeTitle;
|
|
||||||
late RxString sortTypeLabel;
|
|
||||||
Box setting = GStorage.setting;
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void onInit() {
|
void onInit() {
|
||||||
@@ -33,19 +20,12 @@ class HtmlRenderController extends GetxController {
|
|||||||
id = Get.parameters['id']!;
|
id = Get.parameters['id']!;
|
||||||
dynamicType = Get.parameters['dynamicType']!;
|
dynamicType = Get.parameters['dynamicType']!;
|
||||||
type = dynamicType == 'picture' ? 11 : 12;
|
type = dynamicType == 'picture' ? 11 : 12;
|
||||||
int defaultReplySortIndex =
|
|
||||||
setting.get(SettingBoxKey.replySortType, defaultValue: 1) as int;
|
reqHtml();
|
||||||
if (defaultReplySortIndex == 2) {
|
|
||||||
setting.put(SettingBoxKey.replySortType, 0);
|
|
||||||
defaultReplySortIndex = 0;
|
|
||||||
}
|
|
||||||
_sortType = ReplySortType.values[defaultReplySortIndex];
|
|
||||||
sortTypeLabel = _sortType.labels.obs;
|
|
||||||
sortTypeTitle = _sortType.titles.obs;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 请求动态内容
|
// 请求动态内容
|
||||||
Future reqHtml(id) async {
|
Future reqHtml() async {
|
||||||
late dynamic res;
|
late dynamic res;
|
||||||
if (dynamicType == 'opus' || dynamicType == 'picture') {
|
if (dynamicType == 'opus' || dynamicType == 'picture') {
|
||||||
res = await HtmlHttp.reqHtml(id, dynamicType);
|
res = await HtmlHttp.reqHtml(id, dynamicType);
|
||||||
@@ -54,72 +34,17 @@ class HtmlRenderController extends GetxController {
|
|||||||
}
|
}
|
||||||
response = res;
|
response = res;
|
||||||
oid.value = res['commentId'];
|
oid.value = res['commentId'];
|
||||||
queryReplyList(reqType: 'init');
|
queryData();
|
||||||
return res;
|
if (res['status'] == true) {
|
||||||
|
loaded.value = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 请求评论
|
@override
|
||||||
Future queryReplyList({reqType = 'init'}) async {
|
Future<LoadingState> customGetData() => ReplyHttp.replyList(
|
||||||
if (reqType == 'init') {
|
oid: oid.value,
|
||||||
nextOffset = "";
|
nextOffset: nextOffset,
|
||||||
noMore.value = "";
|
type: type,
|
||||||
}
|
sort: sortType.index,
|
||||||
if (noMore.value == '没有更多了') return;
|
);
|
||||||
var res = await ReplyHttp.replyList(
|
|
||||||
oid: oid.value,
|
|
||||||
nextOffset: nextOffset,
|
|
||||||
type: type,
|
|
||||||
sort: _sortType.index,
|
|
||||||
);
|
|
||||||
if (res['status']) {
|
|
||||||
List<ReplyItemModel> replies = res['data'].replies;
|
|
||||||
acount.value = res['data'].cursor.allCount ?? 0;
|
|
||||||
nextOffset = res['data'].cursor.paginationReply.nextOffset ?? "";
|
|
||||||
if (replies.isNotEmpty) {
|
|
||||||
noMore.value = '加载中...';
|
|
||||||
if (res['data'].cursor.isEnd == true) {
|
|
||||||
noMore.value = '没有更多了';
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
noMore.value =
|
|
||||||
nextOffset == "" && reqType == 'init' ? '还没有评论' : '没有更多了';
|
|
||||||
}
|
|
||||||
if (reqType == 'init') {
|
|
||||||
// 添加置顶回复
|
|
||||||
if (res['data'].upper.top != null) {
|
|
||||||
bool flag = res['data']
|
|
||||||
.topReplies
|
|
||||||
.any((reply) => reply.rpid == res['data'].upper.top.rpid);
|
|
||||||
if (!flag) {
|
|
||||||
replies.insert(0, res['data'].upper.top);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
replies.insertAll(0, res['data'].topReplies);
|
|
||||||
replyList.value = replies;
|
|
||||||
} else {
|
|
||||||
replyList.addAll(replies);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
isLoadingMore = false;
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 排序搜索评论
|
|
||||||
queryBySort() {
|
|
||||||
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 = "";
|
|
||||||
replyList.clear();
|
|
||||||
queryReplyList(reqType: 'init');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
import 'dart:math';
|
import 'dart:math';
|
||||||
|
|
||||||
|
import 'package:PiliPalaX/common/widgets/http_error.dart';
|
||||||
|
import 'package:PiliPalaX/http/loading_state.dart';
|
||||||
import 'package:easy_debounce/easy_throttle.dart';
|
import 'package:easy_debounce/easy_throttle.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/rendering.dart';
|
import 'package:flutter/rendering.dart';
|
||||||
@@ -34,8 +36,6 @@ class _HtmlRenderPageState extends State<HtmlRenderPage>
|
|||||||
late String dynamicType;
|
late String dynamicType;
|
||||||
late int type;
|
late int type;
|
||||||
bool _isFabVisible = true;
|
bool _isFabVisible = true;
|
||||||
late final Future _futureBuilderFuture;
|
|
||||||
late ScrollController scrollController;
|
|
||||||
late AnimationController fabAnimationCtr;
|
late AnimationController fabAnimationCtr;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -46,31 +46,29 @@ class _HtmlRenderPageState extends State<HtmlRenderPage>
|
|||||||
url = Get.parameters['url']!;
|
url = Get.parameters['url']!;
|
||||||
dynamicType = Get.parameters['dynamicType']!;
|
dynamicType = Get.parameters['dynamicType']!;
|
||||||
type = dynamicType == 'picture' ? 11 : 12;
|
type = dynamicType == 'picture' ? 11 : 12;
|
||||||
_futureBuilderFuture = _htmlRenderCtr.reqHtml(id);
|
|
||||||
fabAnimationCtr = AnimationController(
|
fabAnimationCtr = AnimationController(
|
||||||
vsync: this,
|
vsync: this,
|
||||||
duration: const Duration(milliseconds: 300),
|
duration: const Duration(milliseconds: 300),
|
||||||
);
|
);
|
||||||
|
fabAnimationCtr.forward();
|
||||||
scrollListener();
|
scrollListener();
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void dispose() {
|
void dispose() {
|
||||||
fabAnimationCtr.dispose();
|
fabAnimationCtr.dispose();
|
||||||
scrollController.removeListener(() {});
|
_htmlRenderCtr.scrollController.removeListener(() {});
|
||||||
scrollController.dispose();
|
|
||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
void scrollListener() {
|
void scrollListener() {
|
||||||
scrollController = _htmlRenderCtr.scrollController;
|
_htmlRenderCtr.scrollController.addListener(
|
||||||
scrollController.addListener(
|
|
||||||
() {
|
() {
|
||||||
// 分页加载
|
// 分页加载
|
||||||
if (scrollController.position.pixels >=
|
if (_htmlRenderCtr.scrollController.position.pixels >=
|
||||||
scrollController.position.maxScrollExtent - 300) {
|
_htmlRenderCtr.scrollController.position.maxScrollExtent - 300) {
|
||||||
EasyThrottle.throttle('replylist', const Duration(seconds: 2), () {
|
EasyThrottle.throttle('replylist', const Duration(seconds: 2), () {
|
||||||
_htmlRenderCtr.queryReplyList(reqType: 'onLoad');
|
_htmlRenderCtr.onLoadMore();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -85,7 +83,7 @@ class _HtmlRenderPageState extends State<HtmlRenderPage>
|
|||||||
|
|
||||||
// fab按钮
|
// fab按钮
|
||||||
final ScrollDirection direction =
|
final ScrollDirection direction =
|
||||||
scrollController.position.userScrollDirection;
|
_htmlRenderCtr.scrollController.position.userScrollDirection;
|
||||||
if (direction == ScrollDirection.forward) {
|
if (direction == ScrollDirection.forward) {
|
||||||
_showFab();
|
_showFab();
|
||||||
} else if (direction == ScrollDirection.reverse) {
|
} else if (direction == ScrollDirection.reverse) {
|
||||||
@@ -161,7 +159,7 @@ class _HtmlRenderPageState extends State<HtmlRenderPage>
|
|||||||
itemBuilder: (BuildContext context) => <PopupMenuEntry>[
|
itemBuilder: (BuildContext context) => <PopupMenuEntry>[
|
||||||
PopupMenuItem(
|
PopupMenuItem(
|
||||||
onTap: () => {
|
onTap: () => {
|
||||||
_htmlRenderCtr.reqHtml(id),
|
_htmlRenderCtr.reqHtml(),
|
||||||
},
|
},
|
||||||
child: const Row(
|
child: const Row(
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
@@ -225,23 +223,17 @@ class _HtmlRenderPageState extends State<HtmlRenderPage>
|
|||||||
double padding = max(context.width / 2 - Grid.maxRowWidth, 0);
|
double padding = max(context.width / 2 - Grid.maxRowWidth, 0);
|
||||||
return Row(crossAxisAlignment: CrossAxisAlignment.start, children: [
|
return Row(crossAxisAlignment: CrossAxisAlignment.start, children: [
|
||||||
Expanded(
|
Expanded(
|
||||||
child: SingleChildScrollView(
|
child: SingleChildScrollView(
|
||||||
controller: orientation == Orientation.portrait
|
controller: orientation == Orientation.portrait
|
||||||
? scrollController
|
? _htmlRenderCtr.scrollController
|
||||||
: ScrollController(),
|
: ScrollController(),
|
||||||
child: Padding(
|
child: Padding(
|
||||||
padding: orientation == Orientation.portrait
|
padding: orientation == Orientation.portrait
|
||||||
? EdgeInsets.symmetric(horizontal: padding)
|
? EdgeInsets.symmetric(horizontal: padding)
|
||||||
: EdgeInsets.only(left: padding / 2),
|
: EdgeInsets.only(left: padding / 2),
|
||||||
child: FutureBuilder(
|
child: Obx(
|
||||||
future: _futureBuilderFuture,
|
() => _htmlRenderCtr.loaded.value
|
||||||
builder: (context, snapshot) {
|
? Column(
|
||||||
if (snapshot.connectionState == ConnectionState.done &&
|
|
||||||
snapshot.hasData) {
|
|
||||||
var data = snapshot.data;
|
|
||||||
// fabAnimationCtr.forward();
|
|
||||||
if (data != null && data['status']) {
|
|
||||||
return Column(
|
|
||||||
children: [
|
children: [
|
||||||
Padding(
|
Padding(
|
||||||
padding:
|
padding:
|
||||||
@@ -306,35 +298,38 @@ class _HtmlRenderPageState extends State<HtmlRenderPage>
|
|||||||
.dividerColor
|
.dividerColor
|
||||||
.withOpacity(0.05)),
|
.withOpacity(0.05)),
|
||||||
replyHeader(),
|
replyHeader(),
|
||||||
replyList(),
|
Obx(
|
||||||
|
() => replyList(
|
||||||
|
_htmlRenderCtr.loadingState.value),
|
||||||
|
),
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
);
|
)
|
||||||
} else {
|
: const SizedBox(),
|
||||||
return const Text('error');
|
),
|
||||||
}
|
),
|
||||||
} else {
|
),
|
||||||
// 骨架屏
|
),
|
||||||
return const SizedBox();
|
|
||||||
}
|
|
||||||
},
|
|
||||||
)),
|
|
||||||
)),
|
|
||||||
if (orientation == Orientation.landscape) ...[
|
if (orientation == Orientation.landscape) ...[
|
||||||
VerticalDivider(
|
VerticalDivider(
|
||||||
thickness: 8,
|
thickness: 8,
|
||||||
color: Theme.of(context).dividerColor.withOpacity(0.05)),
|
color: Theme.of(context).dividerColor.withOpacity(0.05)),
|
||||||
Expanded(
|
Expanded(
|
||||||
child: SingleChildScrollView(
|
child: SingleChildScrollView(
|
||||||
controller: scrollController,
|
controller: _htmlRenderCtr.scrollController,
|
||||||
child: Padding(
|
child: Padding(
|
||||||
padding: EdgeInsets.only(right: padding / 2),
|
padding: EdgeInsets.only(right: padding / 2),
|
||||||
child: Column(
|
child: Column(
|
||||||
children: [
|
children: [
|
||||||
replyHeader(),
|
replyHeader(),
|
||||||
replyList(),
|
Obx(
|
||||||
],
|
() => replyList(_htmlRenderCtr.loadingState.value),
|
||||||
))))
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
]
|
]
|
||||||
]);
|
]);
|
||||||
}),
|
}),
|
||||||
@@ -365,13 +360,18 @@ class _HtmlRenderPageState extends State<HtmlRenderPage>
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
).then(
|
).then(
|
||||||
(value) => {
|
(value) {
|
||||||
// 完成评论,数据添加
|
// 完成评论,数据添加
|
||||||
if (value != null && value['data'] != null)
|
if (value != null && value['data'] != null) {
|
||||||
{
|
_htmlRenderCtr.count.value++;
|
||||||
_htmlRenderCtr.replyList.insert(0, value['data']),
|
List list = _htmlRenderCtr.loadingState.value is Success
|
||||||
_htmlRenderCtr.acount.value++
|
? (_htmlRenderCtr.loadingState.value as Success)
|
||||||
}
|
.response
|
||||||
|
: [];
|
||||||
|
list.insert(0, value['data']);
|
||||||
|
_htmlRenderCtr.loadingState.value =
|
||||||
|
LoadingState.success(list);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
@@ -385,54 +385,59 @@ class _HtmlRenderPageState extends State<HtmlRenderPage>
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Obx replyList() {
|
Widget replyList(LoadingState loadingState) {
|
||||||
return Obx(
|
return loadingState is Success
|
||||||
() => _htmlRenderCtr.replyList.isEmpty && _htmlRenderCtr.isLoadingMore
|
? ListView.builder(
|
||||||
? ListView.builder(
|
shrinkWrap: true,
|
||||||
itemCount: 5,
|
physics: const NeverScrollableScrollPhysics(),
|
||||||
shrinkWrap: true,
|
itemCount: loadingState.response.length + 1,
|
||||||
physics: const NeverScrollableScrollPhysics(),
|
itemBuilder: (context, index) {
|
||||||
itemBuilder: (context, index) {
|
if (index == loadingState.response.length) {
|
||||||
return const VideoReplySkeleton();
|
return Container(
|
||||||
},
|
padding: EdgeInsets.only(
|
||||||
)
|
bottom: MediaQuery.of(context).padding.bottom),
|
||||||
: ListView.builder(
|
height: MediaQuery.of(context).padding.bottom + 100,
|
||||||
shrinkWrap: true,
|
child: Center(
|
||||||
physics: const NeverScrollableScrollPhysics(),
|
child: Obx(
|
||||||
itemCount: _htmlRenderCtr.replyList.length + 1,
|
() => Text(
|
||||||
itemBuilder: (context, index) {
|
_htmlRenderCtr.noMore.value,
|
||||||
if (index == _htmlRenderCtr.replyList.length) {
|
style: TextStyle(
|
||||||
return Container(
|
fontSize: 12,
|
||||||
padding: EdgeInsets.only(
|
color: Theme.of(context).colorScheme.outline,
|
||||||
bottom: MediaQuery.of(context).padding.bottom),
|
|
||||||
height: MediaQuery.of(context).padding.bottom + 100,
|
|
||||||
child: Center(
|
|
||||||
child: Obx(
|
|
||||||
() => Text(
|
|
||||||
_htmlRenderCtr.noMore.value,
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 12,
|
|
||||||
color: Theme.of(context).colorScheme.outline,
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
),
|
||||||
} else {
|
);
|
||||||
return ReplyItem(
|
} else {
|
||||||
replyItem: _htmlRenderCtr.replyList[index],
|
return ReplyItem(
|
||||||
showReplyRow: true,
|
replyItem: loadingState.response[index],
|
||||||
replyLevel: '1',
|
showReplyRow: true,
|
||||||
replyReply: (replyItem) => replyReply(replyItem),
|
replyLevel: '1',
|
||||||
replyType: ReplyType.values[type],
|
replyReply: (replyItem) => replyReply(replyItem),
|
||||||
addReply: (replyItem) {
|
replyType: ReplyType.values[type],
|
||||||
_htmlRenderCtr.replyList[index].replies!.add(replyItem);
|
addReply: (replyItem) {
|
||||||
},
|
loadingState.response[index].replies!.add(replyItem);
|
||||||
);
|
},
|
||||||
}
|
);
|
||||||
},
|
}
|
||||||
),
|
},
|
||||||
);
|
)
|
||||||
|
: loadingState is Error
|
||||||
|
? HttpError(
|
||||||
|
errMsg: _htmlRenderCtr.loadingState.value is Error
|
||||||
|
? (_htmlRenderCtr.loadingState.value as Error).errMsg
|
||||||
|
: '没有相关数据',
|
||||||
|
fn: _htmlRenderCtr.onReload,
|
||||||
|
)
|
||||||
|
: ListView.builder(
|
||||||
|
itemCount: 5,
|
||||||
|
shrinkWrap: true,
|
||||||
|
physics: const NeverScrollableScrollPhysics(),
|
||||||
|
itemBuilder: (context, index) {
|
||||||
|
return const VideoReplySkeleton();
|
||||||
|
},
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Container replyHeader() {
|
Container replyHeader() {
|
||||||
|
|||||||
@@ -90,11 +90,8 @@ class _ZonePageState extends State<ZonePage>
|
|||||||
? (_zoneController.loadingState.value as Error)
|
? (_zoneController.loadingState.value as Error)
|
||||||
.errMsg
|
.errMsg
|
||||||
: '没有相关数据',
|
: '没有相关数据',
|
||||||
fn: () {
|
fn: _zoneController.onReload,
|
||||||
_zoneController.loadingState.value =
|
),
|
||||||
LoadingState.loading();
|
|
||||||
_zoneController.onRefresh();
|
|
||||||
}),
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ class RcmdController extends PopupController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
List? handleResponse(List currentList, List dataList) {
|
List? handleListResponse(List currentList, List dataList) {
|
||||||
return currentPage == 1 && enableSaveLastData
|
return currentPage == 1 && enableSaveLastData
|
||||||
? dataList +
|
? dataList +
|
||||||
(currentList.isEmpty ? <RecVideoItemAppModel>[] : currentList)
|
(currentList.isEmpty ? <RecVideoItemAppModel>[] : currentList)
|
||||||
|
|||||||
@@ -101,11 +101,8 @@ class _RcmdPageState extends State<RcmdPage>
|
|||||||
errMsg: _controller.loadingState.value is Error
|
errMsg: _controller.loadingState.value is Error
|
||||||
? (_controller.loadingState.value as Error).errMsg
|
? (_controller.loadingState.value as Error).errMsg
|
||||||
: '没有相关数据',
|
: '没有相关数据',
|
||||||
fn: () {
|
fn: _controller.onReload,
|
||||||
_controller.loadingState.value =
|
),
|
||||||
LoadingState.loading();
|
|
||||||
_controller.onRefresh();
|
|
||||||
}),
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -488,7 +488,7 @@ class VideoIntroController extends GetxController {
|
|||||||
final VideoReplyController videoReplyCtr =
|
final VideoReplyController videoReplyCtr =
|
||||||
Get.find<VideoReplyController>(tag: heroTag);
|
Get.find<VideoReplyController>(tag: heroTag);
|
||||||
videoReplyCtr.aid = aid;
|
videoReplyCtr.aid = aid;
|
||||||
videoReplyCtr.queryReplyList(type: 'init');
|
videoReplyCtr.queryData();
|
||||||
} catch (_) {}
|
} catch (_) {}
|
||||||
this.bvid = bvid;
|
this.bvid = bvid;
|
||||||
lastPlayCid.value = cid;
|
lastPlayCid.value = cid;
|
||||||
|
|||||||
@@ -74,11 +74,8 @@ class _RelatedVideoPanelState extends State<RelatedVideoPanel>
|
|||||||
: loadingState is Error
|
: loadingState is Error
|
||||||
? HttpError(
|
? HttpError(
|
||||||
errMsg: '出错了',
|
errMsg: '出错了',
|
||||||
fn: () {
|
fn: _relatedController.onReload,
|
||||||
_relatedController.loadingState.value =
|
)
|
||||||
LoadingState.loading();
|
|
||||||
_relatedController.queryData();
|
|
||||||
})
|
|
||||||
: SliverGrid(
|
: SliverGrid(
|
||||||
gridDelegate: SliverGridDelegateWithExtentAndRatio(
|
gridDelegate: SliverGridDelegateWithExtentAndRatio(
|
||||||
mainAxisSpacing: StyleString.safeSpace,
|
mainAxisSpacing: StyleString.safeSpace,
|
||||||
|
|||||||
@@ -1,142 +1,26 @@
|
|||||||
import 'package:PiliPalaX/utils/extension.dart';
|
import 'package:PiliPalaX/http/loading_state.dart';
|
||||||
import 'package:easy_debounce/easy_throttle.dart';
|
import 'package:PiliPalaX/pages/common/reply_controller.dart';
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:get/get.dart';
|
|
||||||
import 'package:hive/hive.dart';
|
|
||||||
import 'package:PiliPalaX/http/reply.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/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(
|
VideoReplyController(
|
||||||
this.aid,
|
this.aid,
|
||||||
this.rpid,
|
this.rpid,
|
||||||
this.replyLevel,
|
this.replyLevel,
|
||||||
);
|
);
|
||||||
final ScrollController scrollController = ScrollController();
|
|
||||||
// 视频aid 请求时使用的oid
|
// 视频aid 请求时使用的oid
|
||||||
int? aid;
|
int? aid;
|
||||||
// 层级 2为楼中楼
|
// 层级 2为楼中楼
|
||||||
String? replyLevel;
|
String? replyLevel;
|
||||||
// rpid 请求楼中楼回复
|
// rpid 请求楼中楼回复
|
||||||
String? 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
|
@override
|
||||||
void onInit() {
|
Future<LoadingState> customGetData() => ReplyHttp.replyList(
|
||||||
super.onInit();
|
oid: aid!,
|
||||||
int defaultReplySortIndex =
|
nextOffset: nextOffset,
|
||||||
setting.get(SettingBoxKey.replySortType, defaultValue: 1) as int;
|
type: ReplyType.video.index,
|
||||||
if (defaultReplySortIndex == 2) {
|
sort: sortType.index,
|
||||||
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();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import 'package:PiliPalaX/common/widgets/http_error.dart';
|
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:PiliPalaX/pages/video/detail/reply_new/reply_page.dart';
|
||||||
import 'package:easy_debounce/easy_throttle.dart';
|
import 'package:easy_debounce/easy_throttle.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
@@ -74,7 +75,6 @@ class _VideoReplyPanelState extends State<VideoReplyPanel>
|
|||||||
void dispose() {
|
void dispose() {
|
||||||
_videoReplyController.scrollController.removeListener(() {});
|
_videoReplyController.scrollController.removeListener(() {});
|
||||||
fabAnimationCtr.dispose();
|
fabAnimationCtr.dispose();
|
||||||
// _videoReplyController.scrollController.dispose();
|
|
||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -86,7 +86,7 @@ class _VideoReplyPanelState extends State<VideoReplyPanel>
|
|||||||
300) {
|
300) {
|
||||||
EasyThrottle.throttle('replylist', const Duration(milliseconds: 200),
|
EasyThrottle.throttle('replylist', const Duration(milliseconds: 200),
|
||||||
() {
|
() {
|
||||||
_videoReplyController.onLoad();
|
_videoReplyController.onLoadMore();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -136,7 +136,7 @@ class _VideoReplyPanelState extends State<VideoReplyPanel>
|
|||||||
super.build(context);
|
super.build(context);
|
||||||
return RefreshIndicator(
|
return RefreshIndicator(
|
||||||
onRefresh: () async {
|
onRefresh: () async {
|
||||||
await _videoReplyController.queryReplyList(type: 'init');
|
await _videoReplyController.onRefresh();
|
||||||
},
|
},
|
||||||
child: Stack(
|
child: Stack(
|
||||||
children: [
|
children: [
|
||||||
@@ -181,175 +181,7 @@ class _VideoReplyPanelState extends State<VideoReplyPanel>
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
FutureBuilder(
|
Obx(() => _buildBody(_videoReplyController.loadingState.value)),
|
||||||
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),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
Positioned(
|
Positioned(
|
||||||
@@ -407,8 +239,15 @@ class _VideoReplyPanelState extends State<VideoReplyPanel>
|
|||||||
// 完成评论,数据添加
|
// 完成评论,数据添加
|
||||||
if (value != null && value['data'] != null) {
|
if (value != null && value['data'] != null) {
|
||||||
_savedReplies[oid] = null;
|
_savedReplies[oid] = null;
|
||||||
_videoReplyController.replyList
|
List list =
|
||||||
.insert(0, value['data']);
|
_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 {
|
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:flutter/material.dart';
|
||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
import 'package:PiliPalaX/http/reply.dart';
|
import 'package:PiliPalaX/http/reply.dart';
|
||||||
import 'package:PiliPalaX/models/common/reply_type.dart';
|
import 'package:PiliPalaX/models/common/reply_type.dart';
|
||||||
import 'package:PiliPalaX/models/video/reply/item.dart';
|
import 'package:PiliPalaX/models/video/reply/item.dart';
|
||||||
|
|
||||||
class VideoReplyReplyController extends GetxController {
|
class VideoReplyReplyController extends CommonController {
|
||||||
VideoReplyReplyController(this.aid, this.rpid, this.replyType);
|
VideoReplyReplyController(this.aid, this.rpid, this.replyType);
|
||||||
final ScrollController scrollController = ScrollController();
|
|
||||||
// 视频aid 请求时使用的oid
|
// 视频aid 请求时使用的oid
|
||||||
int? aid;
|
int? aid;
|
||||||
// rpid 请求楼中楼回复
|
// rpid 请求楼中楼回复
|
||||||
String? rpid;
|
String? rpid;
|
||||||
ReplyType replyType; // = ReplyType.video;
|
ReplyType replyType; // = ReplyType.video;
|
||||||
RxList<ReplyItemModel> replyList = <ReplyItemModel>[].obs;
|
|
||||||
// 当前页
|
// 当前页
|
||||||
int currentPage = 0;
|
|
||||||
bool isLoadingMore = false;
|
|
||||||
RxString noMore = ''.obs;
|
RxString noMore = ''.obs;
|
||||||
// 当前回复的回复
|
// 当前回复的回复
|
||||||
ReplyItemModel? currentReplyItem;
|
ReplyItemModel? currentReplyItem;
|
||||||
@@ -24,54 +22,42 @@ class VideoReplyReplyController extends GetxController {
|
|||||||
@override
|
@override
|
||||||
void onInit() {
|
void onInit() {
|
||||||
super.onInit();
|
super.onInit();
|
||||||
currentPage = 0;
|
queryData();
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void onClose() {
|
bool customHandleResponse(Success response) {
|
||||||
currentPage = 0;
|
if (response.response.root != null) root = response.response.root;
|
||||||
super.onClose();
|
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:PiliPalaX/pages/video/detail/reply_new/reply_page.dart';
|
||||||
import 'package:easy_debounce/easy_throttle.dart';
|
import 'package:easy_debounce/easy_throttle.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
@@ -37,7 +38,6 @@ class VideoReplyReplyPanel extends StatefulWidget {
|
|||||||
|
|
||||||
class _VideoReplyReplyPanelState extends State<VideoReplyReplyPanel> {
|
class _VideoReplyReplyPanelState extends State<VideoReplyReplyPanel> {
|
||||||
late VideoReplyReplyController _videoReplyReplyController;
|
late VideoReplyReplyController _videoReplyReplyController;
|
||||||
Future? _futureBuilderFuture;
|
|
||||||
late final _savedReplies = {};
|
late final _savedReplies = {};
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -57,13 +57,11 @@ class _VideoReplyReplyPanelState extends State<VideoReplyReplyPanel> {
|
|||||||
300) {
|
300) {
|
||||||
EasyThrottle.throttle('replylist', const Duration(milliseconds: 200),
|
EasyThrottle.throttle('replylist', const Duration(milliseconds: 200),
|
||||||
() {
|
() {
|
||||||
_videoReplyReplyController.queryReplyList(type: 'onLoad');
|
_videoReplyReplyController.onLoadMore();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
_futureBuilderFuture = _videoReplyReplyController.queryReplyList();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void replyReply(replyItem) {}
|
void replyReply(replyItem) {}
|
||||||
@@ -71,7 +69,6 @@ class _VideoReplyReplyPanelState extends State<VideoReplyReplyPanel> {
|
|||||||
@override
|
@override
|
||||||
void dispose() {
|
void dispose() {
|
||||||
_videoReplyReplyController.scrollController.removeListener(() {});
|
_videoReplyReplyController.scrollController.removeListener(() {});
|
||||||
_videoReplyReplyController.scrollController.dispose();
|
|
||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -95,7 +92,6 @@ class _VideoReplyReplyPanelState extends State<VideoReplyReplyPanel> {
|
|||||||
tooltip: '关闭',
|
tooltip: '关闭',
|
||||||
icon: const Icon(Icons.close, size: 20),
|
icon: const Icon(Icons.close, size: 20),
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
_videoReplyReplyController.currentPage = 0;
|
|
||||||
widget.closePanel!();
|
widget.closePanel!();
|
||||||
Navigator.pop(context);
|
Navigator.pop(context);
|
||||||
},
|
},
|
||||||
@@ -110,9 +106,7 @@ class _VideoReplyReplyPanelState extends State<VideoReplyReplyPanel> {
|
|||||||
Expanded(
|
Expanded(
|
||||||
child: RefreshIndicator(
|
child: RefreshIndicator(
|
||||||
onRefresh: () async {
|
onRefresh: () async {
|
||||||
setState(() {});
|
await _videoReplyReplyController.onRefresh();
|
||||||
_videoReplyReplyController.currentPage = 0;
|
|
||||||
return await _videoReplyReplyController.queryReplyList();
|
|
||||||
},
|
},
|
||||||
child: CustomScrollView(
|
child: CustomScrollView(
|
||||||
controller: _videoReplyReplyController.scrollController,
|
controller: _videoReplyReplyController.scrollController,
|
||||||
@@ -126,7 +120,7 @@ class _VideoReplyReplyPanelState extends State<VideoReplyReplyPanel> {
|
|||||||
replyLevel: '2',
|
replyLevel: '2',
|
||||||
showReplyRow: false,
|
showReplyRow: false,
|
||||||
addReply: (replyItem) {
|
addReply: (replyItem) {
|
||||||
_videoReplyReplyController.replyList.add(replyItem);
|
// _videoReplyReplyController.replyList.add(replyItem);
|
||||||
},
|
},
|
||||||
replyType: widget.replyType,
|
replyType: widget.replyType,
|
||||||
replyReply: replyReply,
|
replyReply: replyReply,
|
||||||
@@ -144,129 +138,8 @@ class _VideoReplyReplyPanelState extends State<VideoReplyReplyPanel> {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
FutureBuilder(
|
Obx(() => _buildBody(
|
||||||
future: _futureBuilderFuture,
|
_videoReplyReplyController.loadingState.value)),
|
||||||
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),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
)
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -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 {
|
Future<void> videoSourceInit() async {
|
||||||
_futureBuilderFuture = videoDetailController.queryVideoUrl();
|
_futureBuilderFuture = videoDetailController.queryVideoUrl();
|
||||||
_videoReplyController.futureBuilderFuture =
|
_videoReplyController.queryData();
|
||||||
_videoReplyController.queryReplyList(type: 'init');
|
|
||||||
if (videoDetailController.autoPlay.value) {
|
if (videoDetailController.autoPlay.value) {
|
||||||
plPlayerController = videoDetailController.plPlayerController;
|
plPlayerController = videoDetailController.plPlayerController;
|
||||||
plPlayerController!.addStatusLister(playerListener);
|
plPlayerController!.addStatusLister(playerListener);
|
||||||
@@ -429,7 +428,7 @@ class _VideoDetailPageState extends State<VideoDetailPage>
|
|||||||
if (value == 0) {
|
if (value == 0) {
|
||||||
_introController.animToTop();
|
_introController.animToTop();
|
||||||
} else {
|
} else {
|
||||||
_videoReplyController.animToTop();
|
_videoReplyController.animateToTop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user