Fix the issue of the comic list loading infinitely. Close #584

This commit is contained in:
ynyx631
2025-10-29 19:39:18 +08:00
parent 09a1d2821c
commit 9636cf62cb

View File

@@ -1159,7 +1159,7 @@ class ComicListState extends State<ComicList> {
if (res.data.isEmpty) { if (res.data.isEmpty) {
setState(() { setState(() {
_data[page] = const []; _data[page] = const [];
_maxPage = page; _maxPage ??= page;
}); });
} else { } else {
setState(() { setState(() {
@@ -1282,8 +1282,8 @@ class ComicListState extends State<ComicList> {
], ],
); );
} }
if (_data[_page] == null) { if (_data[1] == null) {
_loadPage(_page); _loadPage(1);
return Column( return Column(
children: [ children: [
if (widget.errorLeading != null) widget.errorLeading!, if (widget.errorLeading != null) widget.errorLeading!,
@@ -1304,7 +1304,7 @@ class ComicListState extends State<ComicList> {
comics: _data.values.expand((element) => element).toList(), comics: _data.values.expand((element) => element).toList(),
menuBuilder: widget.menuBuilder, menuBuilder: widget.menuBuilder,
onLastItemBuild: () { onLastItemBuild: () {
if (_error == null && (_maxPage == null || _page < _maxPage!)) { if (_error == null && (_maxPage == null || _data.length < _maxPage!)) {
_loadPage(_data.length + 1); _loadPage(_data.length + 1);
} }
}, },
@@ -1334,7 +1334,7 @@ class ComicListState extends State<ComicList> {
], ],
).paddingHorizontal(16).paddingVertical(8), ).paddingHorizontal(16).paddingVertical(8),
) )
else if (_maxPage == null || _page < _maxPage!) else if (_maxPage == null || _data.length < _maxPage!)
const SliverListLoadingIndicator(), const SliverListLoadingIndicator(),
if (widget.trailingSliver != null) widget.trailingSliver!, if (widget.trailingSliver != null) widget.trailingSliver!,
], ],