pikapika/lib/screens/ComicsScreen.dart

162 lines
4.6 KiB
Dart
Raw Permalink Normal View History

2021-09-29 23:57:09 +00:00
import 'package:flutter/material.dart';
import 'package:flutter_search_bar/flutter_search_bar.dart';
2021-11-11 03:00:38 +00:00
import 'package:pikapika/basic/Common.dart';
import 'package:pikapika/basic/config/ShadowCategories.dart';
2021-11-24 13:22:22 +00:00
import 'package:pikapika/basic/config/shadowCategoriesMode.dart';
2021-11-11 03:00:38 +00:00
import 'package:pikapika/basic/store/Categories.dart';
import 'package:pikapika/basic/config/ListLayout.dart';
import 'package:pikapika/basic/Method.dart';
2021-09-29 23:57:09 +00:00
import '../basic/Entities.dart';
import 'SearchScreen.dart';
import 'components/ComicPager.dart';
2022-03-19 04:12:27 +00:00
import 'components/RightClickPop.dart';
2021-09-29 23:57:09 +00:00
// 漫画列表
class ComicsScreen extends StatefulWidget {
final String? category; // 指定分类
final String? tag; // 指定标签
final String? creatorId; // 指定上传者
final String? creatorName; // 上传者名称 (仅显示)
final String? chineseTeam;
const ComicsScreen({
Key? key,
this.category,
this.tag,
this.creatorId,
this.creatorName,
this.chineseTeam,
}) : super(key: key);
@override
State<StatefulWidget> createState() => _ComicsScreenState();
}
class _ComicsScreenState extends State<ComicsScreen> {
2022-03-17 03:31:25 +00:00
late final SearchBar _categorySearchBar = SearchBar(
2021-09-29 23:57:09 +00:00
hintText: '搜索分类 - ${categoryTitle(widget.category)}',
inBar: false,
setState: setState,
onSubmitted: (value) {
if (value.isNotEmpty) {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) =>
SearchScreen(keyword: value, category: widget.category),
),
);
}
},
buildDefaultAppBar: (BuildContext context) {
return AppBar(
2022-03-17 03:31:25 +00:00
title: Text(categoryTitle(widget.category)),
2021-09-29 23:57:09 +00:00
actions: [
shadowCategoriesActionButton(context),
2021-11-04 05:56:25 +00:00
chooseLayoutActionButton(context),
2021-09-29 23:57:09 +00:00
_chooseCategoryAction(),
_categorySearchBar.getSearchAction(context),
],
);
},
);
Widget _chooseCategoryAction() => IconButton(
onPressed: () async {
String? category = await chooseListDialog(context, '请选择分类', [
categoryTitle(null),
...filteredList(
storedCategories,
2021-11-24 13:22:22 +00:00
(c) {
switch (currentShadowCategoriesMode()) {
case ShadowCategoriesMode.BLACK_LIST:
if (shadowCategories.contains(c)) return false;
break;
case ShadowCategoriesMode.WHITE_LIST:
if (!shadowCategories.contains(c)) return false;
break;
}
return true;
},
2021-09-29 23:57:09 +00:00
),
]);
if (category != null) {
if (category == categoryTitle(null)) {
category = null;
}
Navigator.of(context).pushReplacement(MaterialPageRoute(
builder: (context) {
return ComicsScreen(
category: category,
tag: widget.tag,
creatorId: widget.creatorId,
creatorName: widget.creatorName,
chineseTeam: widget.chineseTeam,
);
},
));
}
},
2022-03-19 04:12:27 +00:00
icon: const Icon(Icons.category),
2021-09-29 23:57:09 +00:00
);
Future<ComicsPage> _load(String _currentSort, int _currentPage) {
return method.comics(
_currentSort,
_currentPage,
category: widget.category ?? "",
tag: widget.tag ?? "",
creatorId: widget.creatorId ?? "",
chineseTeam: widget.chineseTeam ?? "",
);
}
@override
2022-03-19 04:12:27 +00:00
Widget build(BuildContext context){
2022-03-25 14:57:30 +00:00
return rightClickPop(
child: buildScreen(context),
context: context,
canPop: true,
);
2022-03-19 04:12:27 +00:00
}
Widget buildScreen(BuildContext context) {
2021-09-29 23:57:09 +00:00
PreferredSizeWidget? appBar;
if (widget.tag == null &&
widget.creatorId == null &&
widget.chineseTeam == null) {
// 只有只传分类或不传参数时时才开放搜索
appBar = _categorySearchBar.build(context);
} else {
var title = "";
if (widget.category != null) {
title += "${widget.category} ";
}
if (widget.tag != null) {
title += "${widget.tag} ";
}
if (widget.creatorName != null) {
title += "${widget.creatorName} ";
}
if (widget.chineseTeam != null) {
title += "${widget.chineseTeam} ";
}
appBar = AppBar(
title: Text(title),
actions: [
shadowCategoriesActionButton(context),
2021-11-04 05:56:25 +00:00
chooseLayoutActionButton(context),
2021-09-29 23:57:09 +00:00
_chooseCategoryAction(),
],
);
}
return Scaffold(
appBar: appBar,
body: ComicPager(
fetchPage: _load,
),
);
}
}