fix: loadingState cast

Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
bggRGjQaUbCoE
2024-12-01 13:59:02 +08:00
parent 62a1768307
commit 43977c737b
4 changed files with 26 additions and 20 deletions

View File

@@ -18,11 +18,13 @@ abstract class MultiSelectController extends CommonController {
} }
void handleSelect([bool checked = false]) { void handleSelect([bool checked = false]) {
List? list = (loadingState.value as Success?)?.response; if (loadingState.value is Success) {
if (list.isNullOrEmpty.not) { List list = (loadingState.value as Success).response;
loadingState.value = LoadingState.success( if (list.isNotEmpty) {
list!.map((item) => item..checked = checked).toList()); loadingState.value = LoadingState.success(
checkedCount.value = checked ? list.length : 0; list.map((item) => item..checked = checked).toList());
checkedCount.value = checked ? list.length : 0;
}
} }
if (checked.not) { if (checked.not) {
enableMultiSelect.value = false; enableMultiSelect.value = false;

View File

@@ -200,8 +200,9 @@ abstract class ReplyController extends CommonController {
savedReplies[key] = null; savedReplies[key] = null;
if (GlobalData().grpcReply) { if (GlobalData().grpcReply) {
ReplyInfo replyInfo = Utils.replyCast(res); ReplyInfo replyInfo = Utils.replyCast(res);
MainListReply response = MainListReply response = loadingState.value is Success
(loadingState.value as Success?)?.response ?? MainListReply(); ? (loadingState.value as Success).response
: MainListReply();
if (oid != null) { if (oid != null) {
response.replies.insert(hasUpTop ? 1 : 0, replyInfo); response.replies.insert(hasUpTop ? 1 : 0, replyInfo);
} else { } else {
@@ -210,8 +211,9 @@ abstract class ReplyController extends CommonController {
count.value += 1; count.value += 1;
loadingState.value = LoadingState.success(response); loadingState.value = LoadingState.success(response);
} else { } else {
ReplyData response = ReplyData response = loadingState.value is Success
(loadingState.value as Success?)?.response ?? ReplyData(); ? (loadingState.value as Success).response
: ReplyData();
response.replies ??= <ReplyItemModel>[]; response.replies ??= <ReplyItemModel>[];
if (oid != null) { if (oid != null) {
response.replies response.replies

View File

@@ -179,9 +179,11 @@ class HistoryController extends MultiSelectController {
TextButton( TextButton(
onPressed: () async { onPressed: () async {
Get.back(); Get.back();
_onDelete(((loadingState.value as Success).response as List) if (loadingState.value is Success) {
.where((e) => e.checked) _onDelete(((loadingState.value as Success).response as List)
.toList()); .where((e) => e.checked)
.toList());
}
}, },
child: const Text('确认'), child: const Text('确认'),
) )

View File

@@ -298,19 +298,19 @@ class _VideoReplyReplyPanelState extends State<VideoReplyReplyPanel> {
_savedReplies[key] = null; _savedReplies[key] = null;
if (GlobalData().grpcReply) { if (GlobalData().grpcReply) {
ReplyInfo replyInfo = Utils.replyCast(res); ReplyInfo replyInfo = Utils.replyCast(res);
List list = List list = _videoReplyReplyController.loadingState.value is Success
(_videoReplyReplyController.loadingState.value as Success?) ? (_videoReplyReplyController.loadingState.value as Success)
?.response ?? .response
<ReplyInfo>[]; : <ReplyInfo>[];
list.insert(index + 1, replyInfo); list.insert(index + 1, replyInfo);
_videoReplyReplyController.count.value += 1; _videoReplyReplyController.count.value += 1;
_videoReplyReplyController.loadingState.value = _videoReplyReplyController.loadingState.value =
LoadingState.success(list); LoadingState.success(list);
} else { } else {
List list = List list = _videoReplyReplyController.loadingState.value is Success
(_videoReplyReplyController.loadingState.value as Success?) ? (_videoReplyReplyController.loadingState.value as Success)
?.response ?? .response
<ReplyItemModel>[]; : <ReplyItemModel>[];
list.insert(index + 1, ReplyItemModel.fromJson(res, '')); list.insert(index + 1, ReplyItemModel.fromJson(res, ''));
_videoReplyReplyController.count.value += 1; _videoReplyReplyController.count.value += 1;
_videoReplyReplyController.loadingState.value = _videoReplyReplyController.loadingState.value =