From e77424e00e1d38cc93758c63bf6182984c8f1935 Mon Sep 17 00:00:00 2001 From: nyne Date: Sat, 21 Dec 2024 18:08:32 +0800 Subject: [PATCH] fix #109 --- lib/components/comic.dart | 13 ++++++++++--- lib/pages/explore_page.dart | 1 + lib/pages/favorites/network_favorites_page.dart | 2 ++ lib/pages/main_page.dart | 4 +--- 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/lib/components/comic.dart b/lib/components/comic.dart index b131e4d..b0b455d 100644 --- a/lib/components/comic.dart +++ b/lib/components/comic.dart @@ -833,6 +833,7 @@ class ComicList extends StatefulWidget { this.menuBuilder, this.controller, this.refreshHandlerCallback, + this.enablePageStorage = false, }); final Future>> Function(int page)? loadPage; @@ -851,6 +852,8 @@ class ComicList extends StatefulWidget { final void Function(VoidCallback c)? refreshHandlerCallback; + final bool enablePageStorage; + @override State createState() => ComicListState(); } @@ -868,6 +871,8 @@ class ComicListState extends State { String? _nextUrl; + late bool enablePageStorage = widget.enablePageStorage; + Map get state => { 'maxPage': _maxPage, 'data': _data, @@ -878,7 +883,7 @@ class ComicListState extends State { }; void restoreState(Map? state) { - if (state == null) { + if (state == null || !enablePageStorage) { return; } _maxPage = state['maxPage']; @@ -892,7 +897,9 @@ class ComicListState extends State { } void storeState() { - PageStorage.of(context).writeState(context, state); + if(enablePageStorage) { + PageStorage.of(context).writeState(context, state); + } } void refresh() { @@ -1122,7 +1129,7 @@ class ComicListState extends State { ); } return SmoothCustomScrollView( - key: const PageStorageKey('scroll'), + key: enablePageStorage ? PageStorageKey('scroll$_page') : null, controller: widget.controller, slivers: [ if (widget.leadingSliver != null) widget.leadingSliver!, diff --git a/lib/pages/explore_page.dart b/lib/pages/explore_page.dart index dcb6b53..d43e57b 100644 --- a/lib/pages/explore_page.dart +++ b/lib/pages/explore_page.dart @@ -295,6 +295,7 @@ class _SingleExplorePageState extends StateWithController<_SingleExplorePage> ); } else if (data.loadPage != null || data.loadNext != null) { return ComicList( + enablePageStorage: true, loadPage: data.loadPage, loadNext: data.loadNext, key: const PageStorageKey("comic_list"), diff --git a/lib/pages/favorites/network_favorites_page.dart b/lib/pages/favorites/network_favorites_page.dart index c382b09..5cd0f53 100644 --- a/lib/pages/favorites/network_favorites_page.dart +++ b/lib/pages/favorites/network_favorites_page.dart @@ -166,6 +166,7 @@ class _NormalFavoritePageState extends State<_NormalFavoritePage> { ), ]; }, + enablePageStorage: true, ); } } @@ -548,6 +549,7 @@ class _FavoriteFolder extends StatelessWidget { Widget build(BuildContext context) { return ComicList( key: comicListKey, + enablePageStorage: true, leadingSliver: SliverAppbar( title: Text(title), actions: [ diff --git a/lib/pages/main_page.dart b/lib/pages/main_page.dart index 2801e55..fdd4e7b 100644 --- a/lib/pages/main_page.dart +++ b/lib/pages/main_page.dart @@ -62,9 +62,7 @@ class _MainPageState extends State { } final _pages = [ - const HomePage( - key: PageStorageKey('home'), - ), + const HomePage(), const FavoritesPage( key: PageStorageKey('favorites'), ),