category options

This commit is contained in:
nyne
2024-10-03 17:39:16 +08:00
parent 368abf7860
commit df9a854cb0
2 changed files with 27 additions and 17 deletions

View File

@@ -499,12 +499,22 @@ String? isBlocked(Comic item) {
}
class ComicList extends StatefulWidget {
const ComicList({super.key, this.loadPage, this.loadNext});
const ComicList({
super.key,
this.loadPage,
this.loadNext,
this.leadingSliver,
this.trailingSliver,
});
final Future<Res<List<Comic>>> Function(int page)? loadPage;
final Future<Res<List<Comic>>> Function(String? next)? loadNext;
final Widget? leadingSliver;
final Widget? trailingSliver;
@override
State<ComicList> createState() => _ComicListState();
}
@@ -567,16 +577,18 @@ class _ComicListState extends State<ComicList> {
onPressed: () {
Navigator.of(context).pop();
var page = int.tryParse(value);
if(page == null) {
if (page == null) {
context.showMessage(message: "Invalid page".tl);
} else {
if(page > 0 && (maxPage == null || page <= maxPage!)) {
if (page > 0 &&
(maxPage == null || page <= maxPage!)) {
setState(() {
error = null;
this.page = page;
});
} else {
context.showMessage(message: "Invalid page".tl);
context.showMessage(
message: "Invalid page".tl);
}
}
},
@@ -702,9 +714,11 @@ class _ComicListState extends State<ComicList> {
}
return SmoothCustomScrollView(
slivers: [
if (widget.leadingSliver != null) widget.leadingSliver!,
buildSliverPageSelector(),
SliverGridComics(comics: data[page] ?? const []),
buildSliverPageSelector(),
if (widget.trailingSliver != null) widget.trailingSliver!,
],
);
}

View File

@@ -58,19 +58,15 @@ class _CategoryComicsPageState extends State<CategoryComicsPage> {
appBar: Appbar(
title: Text(widget.category),
),
body: Column(
children: [
Expanded(
child: ComicList(
loadPage: (i) => data.load(
widget.category,
widget.param,
optionsValue,
i,
),
),
),
],
body: ComicList(
key: Key(widget.category + optionsValue.toString()),
leadingSliver: buildOptions(),
loadPage: (i) => data.load(
widget.category,
widget.param,
optionsValue,
i,
),
),
);
}