refa: query data (#659)

Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
dom
2025-04-10 21:43:01 +08:00
committed by GitHub
parent 99b19e7b03
commit e1b73f4766
128 changed files with 1493 additions and 1987 deletions

View File

@@ -1,11 +1,11 @@
import 'package:PiliPlus/http/loading_state.dart';
import 'package:PiliPlus/pages/common/common_controller.dart';
import 'package:PiliPlus/utils/extension.dart';
import 'package:PiliPlus/http/msg.dart';
import 'package:PiliPlus/models/msg/msgfeed_reply_me.dart';
import 'package:PiliPlus/pages/common/common_list_controller.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
class ReplyMeController extends CommonController {
class ReplyMeController
extends CommonListController<MsgFeedReplyMe, ReplyMeItems> {
int cursor = -1;
int cursorTime = -1;
@@ -16,19 +16,19 @@ class ReplyMeController extends CommonController {
}
@override
bool customHandleResponse(Success response) {
MsgFeedReplyMe data = response.response;
if (data.cursor?.isEnd == true || data.items.isNullOrEmpty) {
List<ReplyMeItems>? getDataList(MsgFeedReplyMe response) {
return response.items;
}
@override
bool customHandleResponse(bool isRefresh, Success<MsgFeedReplyMe> response) {
final data = response.response;
if (data.cursor?.isEnd == true) {
isEnd = true;
}
cursor = data.cursor?.id ?? -1;
cursorTime = data.cursor?.time ?? -1;
if (currentPage != 1 && loadingState.value is Success) {
data.items ??= <ReplyMeItems>[];
data.items!.insertAll(0, (loadingState.value as Success).response);
}
loadingState.value = LoadingState.success(data.items);
return true;
return false;
}
@override
@@ -39,16 +39,16 @@ class ReplyMeController extends CommonController {
}
@override
Future<LoadingState> customGetData() =>
Future<LoadingState<MsgFeedReplyMe>> customGetData() =>
MsgHttp.msgFeedReplyMe(cursor: cursor, cursorTime: cursorTime);
Future onRemove(dynamic id, int index) async {
try {
var res = await MsgHttp.delMsgfeed(1, id);
if (res['status']) {
List list = (loadingState.value as Success).response;
List<ReplyMeItems> list = (loadingState.value as Success).response;
list.removeAt(index);
loadingState.value = LoadingState.success(list);
loadingState.refresh();
SmartDialog.showToast('删除成功');
} else {
SmartDialog.showToast(res['msg']);

View File

@@ -34,21 +34,21 @@ class _ReplyMePageState extends State<ReplyMePage> {
);
}
Widget _buildBody(LoadingState loadingState) {
Widget _buildBody(LoadingState<List<ReplyMeItems>?> loadingState) {
return switch (loadingState) {
Loading() => loadingWidget,
Success() => (loadingState.response as List?)?.isNotEmpty == true
Success() => loadingState.response?.isNotEmpty == true
? ListView.separated(
itemCount: loadingState.response.length,
itemCount: loadingState.response!.length,
physics: const AlwaysScrollableScrollPhysics(),
padding: EdgeInsets.only(
bottom: MediaQuery.paddingOf(context).bottom + 80),
itemBuilder: (context, int index) {
if (index == loadingState.response.length - 1) {
if (index == loadingState.response!.length - 1) {
_replyMeController.onLoadMore();
}
ReplyMeItems item = loadingState.response[index];
ReplyMeItems item = loadingState.response![index];
return ListTile(
onTap: () {
String? nativeUri = item.item?.nativeUri;
@@ -121,12 +121,8 @@ class _ReplyMePageState extends State<ReplyMePage> {
Text(item.item?.sourceContent ?? "",
style: Theme.of(context).textTheme.bodyMedium),
const SizedBox(height: 4),
if (loadingState
.response[index].item?.targetReplyContent !=
null &&
loadingState
.response[index].item?.targetReplyContent !=
"")
if (item.item?.targetReplyContent != null &&
item.item?.targetReplyContent != "")
Text("| ${item.item?.targetReplyContent}",
maxLines: 1,
overflow: TextOverflow.ellipsis,