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

View File

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