This commit is contained in:
2024-12-21 18:08:32 +08:00
parent 9f67cd0d07
commit e77424e00e
4 changed files with 14 additions and 6 deletions

View File

@@ -833,6 +833,7 @@ class ComicList extends StatefulWidget {
this.menuBuilder, this.menuBuilder,
this.controller, this.controller,
this.refreshHandlerCallback, this.refreshHandlerCallback,
this.enablePageStorage = false,
}); });
final Future<Res<List<Comic>>> Function(int page)? loadPage; final Future<Res<List<Comic>>> Function(int page)? loadPage;
@@ -851,6 +852,8 @@ class ComicList extends StatefulWidget {
final void Function(VoidCallback c)? refreshHandlerCallback; final void Function(VoidCallback c)? refreshHandlerCallback;
final bool enablePageStorage;
@override @override
State<ComicList> createState() => ComicListState(); State<ComicList> createState() => ComicListState();
} }
@@ -868,6 +871,8 @@ class ComicListState extends State<ComicList> {
String? _nextUrl; String? _nextUrl;
late bool enablePageStorage = widget.enablePageStorage;
Map<String, dynamic> get state => { Map<String, dynamic> get state => {
'maxPage': _maxPage, 'maxPage': _maxPage,
'data': _data, 'data': _data,
@@ -878,7 +883,7 @@ class ComicListState extends State<ComicList> {
}; };
void restoreState(Map<String, dynamic>? state) { void restoreState(Map<String, dynamic>? state) {
if (state == null) { if (state == null || !enablePageStorage) {
return; return;
} }
_maxPage = state['maxPage']; _maxPage = state['maxPage'];
@@ -892,7 +897,9 @@ class ComicListState extends State<ComicList> {
} }
void storeState() { void storeState() {
PageStorage.of(context).writeState(context, state); if(enablePageStorage) {
PageStorage.of(context).writeState(context, state);
}
} }
void refresh() { void refresh() {
@@ -1122,7 +1129,7 @@ class ComicListState extends State<ComicList> {
); );
} }
return SmoothCustomScrollView( return SmoothCustomScrollView(
key: const PageStorageKey('scroll'), key: enablePageStorage ? PageStorageKey('scroll$_page') : null,
controller: widget.controller, controller: widget.controller,
slivers: [ slivers: [
if (widget.leadingSliver != null) widget.leadingSliver!, if (widget.leadingSliver != null) widget.leadingSliver!,

View File

@@ -295,6 +295,7 @@ class _SingleExplorePageState extends StateWithController<_SingleExplorePage>
); );
} else if (data.loadPage != null || data.loadNext != null) { } else if (data.loadPage != null || data.loadNext != null) {
return ComicList( return ComicList(
enablePageStorage: true,
loadPage: data.loadPage, loadPage: data.loadPage,
loadNext: data.loadNext, loadNext: data.loadNext,
key: const PageStorageKey("comic_list"), key: const PageStorageKey("comic_list"),

View File

@@ -166,6 +166,7 @@ class _NormalFavoritePageState extends State<_NormalFavoritePage> {
), ),
]; ];
}, },
enablePageStorage: true,
); );
} }
} }
@@ -548,6 +549,7 @@ class _FavoriteFolder extends StatelessWidget {
Widget build(BuildContext context) { Widget build(BuildContext context) {
return ComicList( return ComicList(
key: comicListKey, key: comicListKey,
enablePageStorage: true,
leadingSliver: SliverAppbar( leadingSliver: SliverAppbar(
title: Text(title), title: Text(title),
actions: [ actions: [

View File

@@ -62,9 +62,7 @@ class _MainPageState extends State<MainPage> {
} }
final _pages = [ final _pages = [
const HomePage( const HomePage(),
key: PageStorageKey('home'),
),
const FavoritesPage( const FavoritesPage(
key: PageStorageKey('favorites'), key: PageStorageKey('favorites'),
), ),