feat: fav topic

Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
bggRGjQaUbCoE
2025-05-17 21:55:36 +08:00
parent 1d4eabb770
commit d7eb734aaf
55 changed files with 1509 additions and 500 deletions

View File

@@ -29,8 +29,9 @@ class FavArticleController extends CommonListController {
Future<void> onRemove(index, id) async {
final res = await UserHttp.communityAction(opusId: id, action: 4);
if (res['status']) {
loadingState.value.data!.removeAt(index);
loadingState.refresh();
loadingState
..value.data!.removeAt(index)
..refresh();
SmartDialog.showToast('已取消收藏');
} else {
SmartDialog.showToast(res['msg']);

View File

@@ -68,14 +68,15 @@ class _FavArticlePageState extends State<FavArticlePage>
item: response[index],
onDelete: () {
showConfirmDialog(
context: context,
title: '确定取消收藏?',
onConfirm: () {
_favArticleController.onRemove(
index,
response[index]['opus_id'],
);
});
context: context,
title: '确定取消收藏?',
onConfirm: () {
_favArticleController.onRemove(
index,
response[index]['opus_id'],
);
},
);
},
);
},

View File

@@ -57,8 +57,9 @@ class FavPgcController
Future<void> bangumiDel(index, seasonId) async {
var result = await VideoHttp.bangumiDel(seasonId: seasonId);
if (result['status']) {
loadingState.value.data!.removeAt(index);
loadingState.refresh();
loadingState
..value.data!.removeAt(index)
..refresh();
}
SmartDialog.showToast(result['msg']);
}

View File

@@ -0,0 +1,52 @@
import 'package:PiliPlus/http/loading_state.dart';
import 'package:PiliPlus/http/user.dart';
import 'package:PiliPlus/models/user/fav_topic/data.dart';
import 'package:PiliPlus/models/user/fav_topic/topic_item.dart';
import 'package:PiliPlus/pages/common/common_list_controller.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
class FavTopicController
extends CommonListController<FavTopicData, FavTopicModel> {
int? total;
@override
void onInit() {
super.onInit();
queryData();
}
@override
void checkIsEnd(int length) {
if (total != null && length >= total!) {
isEnd = true;
}
}
@override
List<FavTopicModel>? getDataList(FavTopicData response) {
total = response.topicList?.pageInfo?.total;
return response.topicList?.topicItems;
}
@override
Future<void> onRefresh() {
total = null;
return super.onRefresh();
}
@override
Future<LoadingState<FavTopicData>> customGetData() =>
UserHttp.favTopic(page: page);
Future<void> onRemove(index, id) async {
var res = await UserHttp.delFavTopic(id);
if (res['status']) {
loadingState
..value.data!.removeAt(index)
..refresh();
SmartDialog.showToast('已取消收藏');
} else {
SmartDialog.showToast(res['msg']);
}
}
}

View File

@@ -0,0 +1,117 @@
import 'package:PiliPlus/common/constants.dart';
import 'package:PiliPlus/common/widgets/dialog/dialog.dart';
import 'package:PiliPlus/common/widgets/loading_widget/http_error.dart';
import 'package:PiliPlus/common/widgets/refresh_indicator.dart';
import 'package:PiliPlus/http/loading_state.dart';
import 'package:PiliPlus/models/user/fav_topic/topic_item.dart';
import 'package:PiliPlus/pages/fav/topic/controller.dart';
import 'package:PiliPlus/utils/grid.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
class FavTopicPage extends StatefulWidget {
const FavTopicPage({super.key});
@override
State<FavTopicPage> createState() => _FavTopicPageState();
}
class _FavTopicPageState extends State<FavTopicPage>
with AutomaticKeepAliveClientMixin {
final FavTopicController _controller = Get.put(FavTopicController());
@override
bool get wantKeepAlive => true;
@override
Widget build(BuildContext context) {
super.build(context);
final ThemeData theme = Theme.of(context);
return refreshIndicator(
onRefresh: _controller.onRefresh,
child: CustomScrollView(
slivers: [
SliverPadding(
padding: EdgeInsets.only(
left: StyleString.safeSpace,
right: StyleString.safeSpace,
top: StyleString.safeSpace,
bottom: MediaQuery.paddingOf(context).bottom + 80,
),
sliver:
Obx(() => _buildBody(theme, _controller.loadingState.value)),
),
],
),
);
}
Widget _buildBody(
ThemeData theme, LoadingState<List<FavTopicModel>?> loadingState) {
return switch (loadingState) {
Loading() => const SliverToBoxAdapter(child: LinearProgressIndicator()),
Success(:var response) => response?.isNotEmpty == true
? SliverGrid(
gridDelegate: SliverGridDelegateWithMaxCrossAxisExtent(
mainAxisSpacing: 12,
crossAxisSpacing: 12,
maxCrossAxisExtent: Grid.smallCardWidth,
mainAxisExtent: MediaQuery.textScalerOf(context).scale(30),
),
delegate: SliverChildBuilderDelegate(
(context, index) {
if (index == response.length - 1) {
_controller.onLoadMore();
}
final item = response[index];
return Material(
color: theme.colorScheme.onInverseSurface,
borderRadius: const BorderRadius.all(Radius.circular(6)),
child: InkWell(
onTap: () {
Get.toNamed(
'/dynTopic',
parameters: {
'id': item.id!.toString(),
'name': item.name!,
},
);
},
onLongPress: () {
showConfirmDialog(
context: context,
title: '确定取消收藏?',
onConfirm: () {
_controller.onRemove(index, item.id);
},
);
},
borderRadius: const BorderRadius.all(Radius.circular(6)),
child: Container(
alignment: Alignment.centerLeft,
padding: const EdgeInsets.symmetric(
horizontal: 11, vertical: 5),
child: Text(
'# ${item.name}',
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(
fontSize: 14,
color: theme.colorScheme.onSurfaceVariant,
),
),
),
),
);
},
childCount: response!.length,
),
)
: HttpError(onReload: _controller.onReload),
Error(:var errMsg) => HttpError(
errMsg: errMsg,
onReload: _controller.onReload,
),
};
}
}

View File

@@ -116,6 +116,8 @@ class _FavPageState extends State<FavPage> with SingleTickerProviderStateMixin {
],
bottom: TabBar(
controller: _tabController,
isScrollable: true,
tabAlignment: TabAlignment.start,
tabs: FavTabType.values.map((item) => Tab(text: item.title)).toList(),
),
),