From 5bf7b69d790e8fd4f42114c15a0c4a93b14501a0 Mon Sep 17 00:00:00 2001 From: guozhigq Date: Fri, 16 Feb 2024 09:33:59 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=94=B6=E8=97=8F=E6=90=9C=E7=B4=A2?= =?UTF-8?q?=E7=BB=93=E6=9E=9C=E5=88=A0=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fav_detail/widget/fav_video_card.dart | 110 ++++++++++-------- lib/pages/fav_search/controller.dart | 20 ++++ lib/pages/fav_search/view.dart | 13 ++- 3 files changed, 92 insertions(+), 51 deletions(-) diff --git a/lib/pages/fav_detail/widget/fav_video_card.dart b/lib/pages/fav_detail/widget/fav_video_card.dart index a3c1e8e5..1c4008ff 100644 --- a/lib/pages/fav_detail/widget/fav_video_card.dart +++ b/lib/pages/fav_detail/widget/fav_video_card.dart @@ -15,9 +15,14 @@ import '../../../common/widgets/badge.dart'; class FavVideoCardH extends StatelessWidget { final dynamic videoItem; final Function? callFn; + final int? searchType; - const FavVideoCardH({Key? key, required this.videoItem, this.callFn}) - : super(key: key); + const FavVideoCardH({ + Key? key, + required this.videoItem, + this.callFn, + this.searchType, + }) : super(key: key); @override Widget build(BuildContext context) { @@ -107,7 +112,11 @@ class FavVideoCardH extends StatelessWidget { }, ), ), - VideoContent(videoItem: videoItem, callFn: callFn) + VideoContent( + videoItem: videoItem, + callFn: callFn, + searchType: searchType, + ) ], ), ); @@ -123,7 +132,13 @@ class FavVideoCardH extends StatelessWidget { class VideoContent extends StatelessWidget { final dynamic videoItem; final Function? callFn; - const VideoContent({super.key, required this.videoItem, this.callFn}); + final int? searchType; + const VideoContent({ + super.key, + required this.videoItem, + this.callFn, + this.searchType, + }); @override Widget build(BuildContext context) { @@ -189,48 +204,51 @@ class VideoContent extends StatelessWidget { ), ], ), - Positioned( - right: 0, - bottom: -4, - child: IconButton( - style: ButtonStyle( - padding: MaterialStateProperty.all(EdgeInsets.zero), - ), - onPressed: () { - showDialog( - context: Get.context!, - builder: (context) { - return 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 { - await callFn!(); - Get.back(); - }, - child: const Text('确定取消'), - ) - ], - ); - }, - ); - }, - icon: Icon( - Icons.clear_outlined, - color: Theme.of(context).colorScheme.outline, - size: 18, - ), - ), - ), + searchType != 1 + ? Positioned( + right: 0, + bottom: -4, + child: IconButton( + style: ButtonStyle( + padding: MaterialStateProperty.all(EdgeInsets.zero), + ), + onPressed: () { + showDialog( + context: Get.context!, + builder: (context) { + return 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 { + await callFn!(); + Get.back(); + }, + child: const Text('确定取消'), + ) + ], + ); + }, + ); + }, + icon: Icon( + Icons.clear_outlined, + color: Theme.of(context).colorScheme.outline, + size: 18, + ), + ), + ) + : const SizedBox(), ], ), ), diff --git a/lib/pages/fav_search/controller.dart b/lib/pages/fav_search/controller.dart index 642fea6b..abd25e0b 100644 --- a/lib/pages/fav_search/controller.dart +++ b/lib/pages/fav_search/controller.dart @@ -1,8 +1,11 @@ import 'package:flutter/material.dart'; +import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; import 'package:get/get.dart'; import 'package:pilipala/http/user.dart'; import 'package:pilipala/models/user/fav_detail.dart'; +import '../../http/video.dart'; + class FavSearchController extends GetxController { final ScrollController scrollController = ScrollController(); Rx controller = TextEditingController().obs; @@ -72,4 +75,21 @@ class FavSearchController extends GetxController { if (!hasMore) return; searchFav(type: 'onLoad'); } + + onCancelFav(int id) async { + var result = await VideoHttp.favVideo( + aid: id, addIds: '', delIds: mediaId.toString()); + if (result['status']) { + if (result['data']['prompt']) { + List dataList = favList; + for (var i in dataList) { + if (i.id == id) { + dataList.remove(i); + break; + } + } + SmartDialog.showToast('取消收藏'); + } + } + } } diff --git a/lib/pages/fav_search/view.dart b/lib/pages/fav_search/view.dart index 37e3046f..9b2ab15d 100644 --- a/lib/pages/fav_search/view.dart +++ b/lib/pages/fav_search/view.dart @@ -8,9 +8,7 @@ import 'package:pilipala/pages/fav_detail/widget/fav_video_card.dart'; import 'controller.dart'; class FavSearchPage extends StatefulWidget { - final int? sourceType; - final int? mediaId; - const FavSearchPage({super.key, this.sourceType, this.mediaId}); + const FavSearchPage({super.key}); @override State createState() => _FavSearchPageState(); @@ -19,11 +17,12 @@ class FavSearchPage extends StatefulWidget { class _FavSearchPageState extends State { final FavSearchController _favSearchCtr = Get.put(FavSearchController()); late ScrollController scrollController; + late int searchType; @override void initState() { super.initState(); - + searchType = int.parse(Get.parameters['searchType']!); scrollController = _favSearchCtr.scrollController; scrollController.addListener( () { @@ -100,7 +99,11 @@ class _FavSearchPageState extends State { } else { return FavVideoCardH( videoItem: _favSearchCtr.favList[index], - callFn: () => null, + searchType: searchType, + callFn: () => searchType != 1 + ? _favSearchCtr + .onCancelFav(_favSearchCtr.favList[index].id!) + : {}, ); } },