Files
PiliPlus/lib/pages/msg_feed_top/at_me/controller.dart
dom e1b73f4766 refa: query data (#659)
Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
2025-04-10 21:43:01 +08:00

58 lines
1.5 KiB
Dart

import 'package:PiliPlus/http/loading_state.dart';
import 'package:PiliPlus/http/msg.dart';
import 'package:PiliPlus/models/msg/msgfeed_at_me.dart';
import 'package:PiliPlus/pages/common/common_list_controller.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
class AtMeController extends CommonListController<MsgFeedAtMe, AtMeItems> {
int cursor = -1;
int cursorTime = -1;
@override
void onInit() {
super.onInit();
queryData();
}
@override
List<AtMeItems>? getDataList(MsgFeedAtMe response) {
return response.items;
}
@override
bool customHandleResponse(bool isRefresh, Success<MsgFeedAtMe> response) {
MsgFeedAtMe data = response.response;
if (data.cursor?.isEnd == true) {
isEnd = true;
}
cursor = data.cursor?.id ?? -1;
cursorTime = data.cursor?.time ?? -1;
return false;
}
@override
Future onRefresh() {
cursor = -1;
cursorTime = -1;
return super.onRefresh();
}
@override
Future<LoadingState<MsgFeedAtMe>> customGetData() =>
MsgHttp.msgFeedAtMe(cursor: cursor, cursorTime: cursorTime);
Future onRemove(dynamic id, int index) async {
try {
var res = await MsgHttp.delMsgfeed(2, id);
if (res['status']) {
List<AtMeItems> list = (loadingState.value as Success).response;
list.removeAt(index);
loadingState.refresh();
SmartDialog.showToast('删除成功');
} else {
SmartDialog.showToast(res['msg']);
}
} catch (_) {}
}
}