import 'package:get/get.dart'; import 'package:isekai_wiki/api/response/page_info.dart'; import 'package:isekai_wiki/models/user.dart'; import 'package:isekai_wiki/utils/dialog.dart'; class FavoriteListController extends GetxController { var pageIds = RxList(); void updateFromPageList(List list) { List addList = []; List removeList = []; for (var pageInfo in list) { if (pageInfo.inwatchlist != null) { if (pageInfo.inwatchlist!) { addList.add(pageInfo.pageid); } else { removeList.add(pageInfo.pageid); } } } var newPageIds = pageIds.where((pageId) => !removeList.contains(pageId)).toList(); for (var pageId in addList) { if (!newPageIds.contains(pageId)) { newPageIds.add(pageId); } } pageIds.value = newPageIds; } void updateFromWatchList(List list) { List addList = []; for (var pageInfo in list) { addList.add(pageInfo.pageid); } for (var pageId in addList) { if (!pageIds.contains(pageId)) { pageIds.add(pageId); } } } bool isFavorite(PageInfo pageInfo) { return pageIds.contains(pageInfo.pageid); } Future setFavorite( PageInfo pageInfo, bool isFavorite, bool showToast) async { // 如果未登录,则提示需要登录 var uc = Get.find(); if (!uc.isLoggedIn) { var result = await confirm(Get.overlayContext!, "使用收藏功能需要登录", title: "提示", positiveText: "登录"); return false; } return false; } }