From 929c1a9d91008b0781c93886a42594014322dab0 Mon Sep 17 00:00:00 2001 From: nyne Date: Mon, 28 Apr 2025 19:46:29 +0800 Subject: [PATCH] Show comics count of a folder on sidebar. --- lib/pages/favorites/local_favorites_page.dart | 2 +- lib/pages/favorites/side_bar.dart | 37 +++++++++++++++---- 2 files changed, 31 insertions(+), 8 deletions(-) diff --git a/lib/pages/favorites/local_favorites_page.dart b/lib/pages/favorites/local_favorites_page.dart index 7acd560..7dfe925 100644 --- a/lib/pages/favorites/local_favorites_page.dart +++ b/lib/pages/favorites/local_favorites_page.dart @@ -4,7 +4,7 @@ const _localAllFolderLabel = '^_^[%local_all%]^_^'; /// If the number of comics in a folder exceeds this limit, it will be /// fetched asynchronously. -const _asyncDataFetchLimit = 200; +const _asyncDataFetchLimit = 500; class _LocalFavoritesPage extends StatefulWidget { const _LocalFavoritesPage({required this.folder, super.key}); diff --git a/lib/pages/favorites/side_bar.dart b/lib/pages/favorites/side_bar.dart index 024edc1..464ad75 100644 --- a/lib/pages/favorites/side_bar.dart +++ b/lib/pages/favorites/side_bar.dart @@ -133,8 +133,7 @@ class _LeftBarState extends State<_LeftBar> implements FolderList { onClick: () { newFolder().then((value) { setState(() { - folders = - LocalFavoritesManager().folderNames; + folders = LocalFavoritesManager().folderNames; }); }); }, @@ -145,8 +144,7 @@ class _LeftBarState extends State<_LeftBar> implements FolderList { onClick: () { sortFolders().then((value) { setState(() { - folders = - LocalFavoritesManager().folderNames; + folders = LocalFavoritesManager().folderNames; }); }); }, @@ -195,6 +193,15 @@ class _LeftBarState extends State<_LeftBar> implements FolderList { Widget buildLocalFolder(String name) { bool isSelected = name == favPage.folder && !favPage.isNetwork; + int count = 0; + if (name == _localAllFolderLabel) { + count = LocalFavoritesManager().totalComics; + } else { + count = LocalFavoritesManager().folderComics(name); + } + var folderName = name == _localAllFolderLabel + ? "All".tl + : getFavoriteDataOrNull(name)?.title ?? name; return InkWell( onTap: () { if (isSelected) { @@ -219,9 +226,25 @@ class _LeftBarState extends State<_LeftBar> implements FolderList { ), ), padding: const EdgeInsets.only(left: 16), - child: Text(name == _localAllFolderLabel - ? "All".tl - : getFavoriteDataOrNull(name)?.title ?? name), + child: Row( + children: [ + Expanded( + child: Text(folderName), + ), + Container( + margin: EdgeInsets.only(right: 8), + padding: EdgeInsets.symmetric( + horizontal: 8, + vertical: 2, + ), + decoration: BoxDecoration( + color: context.colorScheme.surfaceContainer, + borderRadius: BorderRadius.circular(8), + ), + child: Text(count.toString()), + ), + ], + ), ), ); }