From 856ec9fca248a35fae2ddcbe208a8d66d9c6a5ca Mon Sep 17 00:00:00 2001 From: 3003h Date: Mon, 13 Nov 2023 23:39:47 +0800 Subject: [PATCH] new FavoriteSelectorPage --- lib/pages/tab/view/favorite_sel_page.dart | 218 +++++++--------------- 1 file changed, 68 insertions(+), 150 deletions(-) diff --git a/lib/pages/tab/view/favorite_sel_page.dart b/lib/pages/tab/view/favorite_sel_page.dart index 260b64d7a..1ee35bb02 100644 --- a/lib/pages/tab/view/favorite_sel_page.dart +++ b/lib/pages/tab/view/favorite_sel_page.dart @@ -1,179 +1,97 @@ import 'package:fehviewer/common/service/layout_service.dart'; import 'package:fehviewer/const/theme_colors.dart'; -import 'package:fehviewer/generated/l10n.dart'; -import 'package:fehviewer/models/base/eh_models.dart'; +import 'package:fehviewer/fehviewer.dart'; import 'package:fehviewer/network/request.dart'; import 'package:fehviewer/pages/controller/favorite_sel_controller.dart'; +import 'package:fehviewer/pages/tab/fetch_list.dart'; import 'package:fehviewer/pages/tab/view/gallery_base.dart'; import 'package:flutter/cupertino.dart'; -import 'package:flutter/material.dart'; -import 'package:font_awesome_flutter/font_awesome_flutter.dart'; import 'package:get/get.dart'; -import '../fetch_list.dart'; - -/// 收藏夹选择页面 列表 class FavoriteSelectorPage extends StatelessWidget { - FavoriteSelectorPage({Key? key, this.favcatItemBean}) : super(key: key); + const FavoriteSelectorPage({super.key, this.favCatItemBean}); - final Favcat? favcatItemBean; + final Favcat? favCatItemBean; - final FavoriteSelectorController favoriteSelectorController = Get.find(); + FavoriteSelectorController get favoriteSelectorController => Get.find(); @override Widget build(BuildContext context) { - final String _title = L10n.of(context).favcat; - final CupertinoPageScaffold sca = CupertinoPageScaffold( - navigationBar: CupertinoNavigationBar( - middle: Text(_title), - transitionBetweenRoutes: false, - ), - child: SafeArea( - child: _buildFavoriteSelectorListView(), - )); - - return sca; - } - - Widget _buildFavoriteSelectorListView() { - return favoriteSelectorController.obx( - (List? state) { - return ListViewFavorite( - favcatList: state ?? [], - ); - }, - onLoading: Container( - alignment: Alignment.center, - padding: const EdgeInsets.only(bottom: 50), - child: const CupertinoActivityIndicator( - radius: 14.0, - ), - ), - onError: (err) { - return Center( - child: Container( - padding: const EdgeInsets.only(bottom: 50), - child: GalleryErrorPage( - onTap: () async { - await getGallery( - favcat: 'a', - refresh: true, - galleryListType: GalleryListType.favorite, - ); - }, + return CupertinoPageScaffold( + backgroundColor: CupertinoColors.systemGroupedBackground, + navigationBar: CupertinoNavigationBar( + middle: Text(L10n.of(context).favcat), + ), + child: CustomScrollView(slivers: [ + SliverSafeArea( + sliver: favoriteSelectorController.obx( + (List? state) { + return ListViewFavorite( + favCatList: state ?? [], + ); + }, + onLoading: const SliverFillRemaining( + child: Center( + child: CupertinoActivityIndicator( + radius: 14.0, + ), + ), ), - ), - ); - }); - } -} - -class ListViewFavorite extends StatelessWidget { - const ListViewFavorite({Key? key, required this.favcatList}) - : super(key: key); - final List favcatList; - - @override - Widget build(BuildContext context) { - return ListView.builder( - itemCount: favcatList.length, - - //列表项构造器 - itemBuilder: (BuildContext context, int index) { - return _FavSelectorItem( - favcat: favcatList[index], - index: index, - ); - }, + onError: (err) { + return SliverFillRemaining( + child: Center( + child: GalleryErrorPage( + onTap: () async { + await getGallery( + favcat: 'a', + refresh: true, + galleryListType: GalleryListType.favorite, + ); + }, + ), + ), + ); + }), + ), + ]), ); } } -/// 收藏夹选择单项 -class _FavSelectorItem extends StatelessWidget { - const _FavSelectorItem({required this.index, required this.favcat}); +class ListViewFavorite extends StatelessWidget { + const ListViewFavorite({super.key, required this.favCatList}); - final int index; - final Favcat favcat; + final List favCatList; @override Widget build(BuildContext context) { - // 每个Item单独的依赖 - final FavSelectorItemController favoriteSelectorItemController = - Get.put(FavSelectorItemController(), tag: '$index')!; - - final Widget container = Obx(() => Container( - color: favoriteSelectorItemController.colorTap.value, - padding: const EdgeInsets.fromLTRB(24, 8, 12, 8), - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Row(children: [ - // 图标 - Icon( - FontAwesomeIcons.solidHeart, - color: ThemeColors.favColor[favcat.favId], - ), - Container( - width: 8, - ), // 占位 宽度8 - Text( - favcat.favTitle, - style: const TextStyle( - fontSize: 20, - ), - ), - const Spacer(), - Text( - '${favcat.totNum ?? 0}', - style: const TextStyle( - fontSize: 18, - ), - ), - const Icon( - CupertinoIcons.forward, - size: 24.0, - color: CupertinoColors.systemGrey, - ), - ]), - ], + return SliverCupertinoListSection.insetGrouped( + hasLeading: true, + itemBuilder: (context, index) { + final Favcat _favcat = favCatList[index]; + return EhCupertinoListTile( + title: Text(_favcat.favTitle), + leading: Icon( + CupertinoIcons.heart_fill, + color: ThemeColors.favColor[_favcat.favId], ), - )); - - return GestureDetector( - child: Column( - children: [ - container, - _settingItemDivider(), - ], - ), - // 不可见区域点击有效 - behavior: HitTestBehavior.opaque, - onTap: () { - // 返回 并带上参数 - Get.back( - result: favcat, - id: isLayoutLarge ? 1 : null, + trailing: const CupertinoListTileChevron(), + additionalInfo: Text( + '${_favcat.totNum ?? 0}', + style: const TextStyle( + fontSize: 16, + color: CupertinoColors.secondaryLabel, + ), + ), + onTap: () { + Get.back( + result: _favcat, + id: isLayoutLarge ? 1 : null, + ); + }, ); }, - onTapDown: (_) => favoriteSelectorItemController.updatePressedColor(), - onTapUp: (_) { - Future.delayed(const Duration(milliseconds: 100), () { - favoriteSelectorItemController.updateNormalColor(); - }); - }, - onTapCancel: () => favoriteSelectorItemController.updateNormalColor(), - ); - } - - /// 设置项分隔线 - Widget _settingItemDivider() { - return Divider( - height: 1.0, - indent: 48, - color: CupertinoDynamicColor.resolve( - CupertinoColors.systemGrey4, Get.context!), + itemCount: favCatList.length, ); } }