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

View File

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