Files
PiliPlus/lib/pages/subscription/controller.dart
My-Responsitories ce5e85e64b tweaks (#1780)
* opt: sized

* fix: self send

* feat: ctrl enter to send

* opt: checked

* opt: download notifier

* opt: Future.syncValue

* mod: account

* mod: loading state

* opt: DebounceStreamMixin

* opt: report

* opt: enum map

* opt: file handler

* opt: dyn color

* opt: Uint8List subview

* opt: FileExt

* opt: computeLuminance

* opt: isNullOrEmpty

* opt: Get context

* update [skip ci]

Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>

* opt dynamicColor [skip ci]

Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>

* fixes [skip ci]

* update

Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>

* update

Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>

---------

Signed-off-by: My-Responsitories <107370289+My-Responsitories@users.noreply.github.com>
Co-authored-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
2025-12-17 17:01:10 +08:00

83 lines
2.3 KiB
Dart

import 'package:PiliPlus/http/fav.dart';
import 'package:PiliPlus/http/loading_state.dart';
import 'package:PiliPlus/http/user.dart';
import 'package:PiliPlus/models_new/sub/sub/data.dart';
import 'package:PiliPlus/models_new/sub/sub/list.dart';
import 'package:PiliPlus/pages/common/common_list_controller.dart';
import 'package:PiliPlus/utils/accounts.dart';
import 'package:flutter/material.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:get/get.dart';
class SubController extends CommonListController<SubData, SubItemModel> {
late final account = Accounts.main;
@override
void onInit() {
super.onInit();
queryData();
}
@override
Future<void> queryData([bool isRefresh = true]) {
if (!account.isLogin) {
loadingState.value = const Error('账号未登录');
return Future.syncValue(null);
}
return super.queryData(isRefresh);
}
// 取消订阅
void cancelSub(SubItemModel subFolderItem) {
showDialog(
context: Get.context!,
builder: (context) => AlertDialog(
title: const Text('提示'),
content: const Text('确定取消订阅吗?'),
actions: [
TextButton(
onPressed: Get.back,
child: Text(
'取消',
style: TextStyle(color: Theme.of(context).colorScheme.outline),
),
),
TextButton(
onPressed: () async {
var res = await FavHttp.cancelSub(
id: subFolderItem.id!,
type: subFolderItem.type!,
);
if (res.isSuccess) {
loadingState
..value.data!.remove(subFolderItem)
..refresh();
SmartDialog.showToast('取消订阅成功');
} else {
res.toast();
}
Get.back();
},
child: const Text('确定'),
),
],
),
);
}
@override
List<SubItemModel>? getDataList(SubData response) {
if (response.hasMore == false) {
isEnd = true;
}
return response.list;
}
@override
Future<LoadingState<SubData>> customGetData() => UserHttp.userSubFolder(
pn: page,
ps: 20,
mid: account.mid,
);
}