mirror of
https://github.com/venera-app/venera.git
synced 2025-09-27 07:47:24 +00:00
117 lines
3.0 KiB
Dart
117 lines
3.0 KiB
Dart
import "package:flutter/material.dart";
|
|
import "package:venera/components/components.dart";
|
|
import "package:venera/foundation/app.dart";
|
|
import "package:venera/foundation/comic_source/comic_source.dart";
|
|
import "package:venera/utils/translations.dart";
|
|
|
|
class CategoryComicsPage extends StatefulWidget {
|
|
const CategoryComicsPage({
|
|
required this.category,
|
|
this.param,
|
|
required this.categoryKey,
|
|
super.key,
|
|
});
|
|
|
|
final String category;
|
|
|
|
final String? param;
|
|
|
|
final String categoryKey;
|
|
|
|
@override
|
|
State<CategoryComicsPage> createState() => _CategoryComicsPageState();
|
|
}
|
|
|
|
class _CategoryComicsPageState extends State<CategoryComicsPage> {
|
|
late final CategoryComicsData data;
|
|
late final List<CategoryComicsOptions> options;
|
|
late List<String> optionsValue;
|
|
|
|
void findData() {
|
|
for (final source in ComicSource.all()) {
|
|
if (source.categoryData?.key == widget.categoryKey) {
|
|
data = source.categoryComicsData!;
|
|
options = data.options.where((element) {
|
|
if (element.notShowWhen.contains(widget.category)) {
|
|
return false;
|
|
} else if (element.showWhen != null) {
|
|
return element.showWhen!.contains(widget.category);
|
|
}
|
|
return true;
|
|
}).toList();
|
|
optionsValue = options.map((e) => e.options.keys.first).toList();
|
|
return;
|
|
}
|
|
}
|
|
throw "${widget.categoryKey} Not found";
|
|
}
|
|
|
|
@override
|
|
void initState() {
|
|
findData();
|
|
super.initState();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
appBar: Appbar(
|
|
title: Text(widget.category),
|
|
),
|
|
body: ComicList(
|
|
key: Key(widget.category + optionsValue.toString()),
|
|
leadingSliver: buildOptions(),
|
|
loadPage: (i) => data.load(
|
|
widget.category,
|
|
widget.param,
|
|
optionsValue,
|
|
i,
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget buildOptionItem(
|
|
String text, String value, int group, BuildContext context) {
|
|
return OptionChip(
|
|
text: text,
|
|
isSelected: value == optionsValue[group],
|
|
onTap: () {
|
|
if (value == optionsValue[group]) return;
|
|
setState(() {
|
|
optionsValue[group] = value;
|
|
});
|
|
},
|
|
);
|
|
}
|
|
|
|
Widget buildOptions() {
|
|
List<Widget> children = [];
|
|
for (var optionList in options) {
|
|
children.add(Wrap(
|
|
spacing: 8,
|
|
runSpacing: 8,
|
|
children: [
|
|
for (var option in optionList.options.entries)
|
|
buildOptionItem(
|
|
option.value.tl,
|
|
option.key,
|
|
options.indexOf(optionList),
|
|
context,
|
|
)
|
|
],
|
|
));
|
|
if (options.last != optionList) {
|
|
children.add(const SizedBox(height: 8));
|
|
}
|
|
}
|
|
return SliverToBoxAdapter(
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [...children, const Divider()],
|
|
).paddingLeft(8).paddingRight(8),
|
|
);
|
|
}
|
|
}
|