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';
|
|
|
|
import 'package:pikapika/basic/store/Categories.dart';
|
|
|
|
import 'package:pikapika/basic/config/ListLayout.dart';
|
|
|
|
import 'package:pikapika/basic/Method.dart';
|
2022-03-19 04:12:27 +00:00
|
|
|
import 'package:pikapika/screens/components/RightClickPop.dart';
|
2021-09-29 23:57:09 +00:00
|
|
|
import '../basic/Entities.dart';
|
|
|
|
import 'components/ComicPager.dart';
|
|
|
|
|
2021-10-26 11:04:23 +00:00
|
|
|
// 搜索页面
|
2021-09-29 23:57:09 +00:00
|
|
|
class SearchScreen extends StatefulWidget {
|
|
|
|
final String keyword;
|
|
|
|
final String? category;
|
|
|
|
|
|
|
|
const SearchScreen({
|
|
|
|
Key? key,
|
|
|
|
required this.keyword,
|
|
|
|
this.category,
|
|
|
|
}) : super(key: key);
|
|
|
|
|
|
|
|
@override
|
|
|
|
State<StatefulWidget> createState() => _SearchScreenState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _SearchScreenState extends State<SearchScreen> {
|
2022-03-17 03:31:25 +00:00
|
|
|
late final TextEditingController _textEditController =
|
2021-09-29 23:57:09 +00:00
|
|
|
TextEditingController(text: widget.keyword);
|
2022-03-17 03:31:25 +00:00
|
|
|
late final SearchBar _searchBar = SearchBar(
|
2021-09-29 23:57:09 +00:00
|
|
|
hintText: '搜索 ${categoryTitle(widget.category)}',
|
|
|
|
controller: _textEditController,
|
|
|
|
inBar: false,
|
|
|
|
setState: setState,
|
|
|
|
onSubmitted: (value) {
|
|
|
|
if (value.isNotEmpty) {
|
|
|
|
Navigator.pushReplacement(
|
|
|
|
context,
|
|
|
|
MaterialPageRoute(
|
|
|
|
builder: (context) => SearchScreen(
|
|
|
|
keyword: value,
|
|
|
|
category: widget.category,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
buildDefaultAppBar: (BuildContext context) {
|
|
|
|
return AppBar(
|
|
|
|
title: Text("${categoryTitle(widget.category)} ${widget.keyword}"),
|
|
|
|
actions: [
|
|
|
|
shadowCategoriesActionButton(context),
|
2021-11-04 05:56:25 +00:00
|
|
|
chooseLayoutActionButton(context),
|
2021-09-29 23:57:09 +00:00
|
|
|
_chooseCategoryAction(),
|
|
|
|
_searchBar.getSearchAction(context),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
|
|
|
|
Widget _chooseCategoryAction() => IconButton(
|
|
|
|
onPressed: () async {
|
|
|
|
String? category = await chooseListDialog(context, '请选择分类', [
|
|
|
|
categoryTitle(null),
|
|
|
|
...filteredList(
|
|
|
|
storedCategories,
|
|
|
|
(c) => !shadowCategories.contains(c),
|
|
|
|
),
|
|
|
|
]);
|
|
|
|
if (category != null) {
|
|
|
|
if (category == categoryTitle(null)) {
|
|
|
|
category = null;
|
|
|
|
}
|
|
|
|
Navigator.of(context).pushReplacement(MaterialPageRoute(
|
|
|
|
builder: (context) {
|
|
|
|
return SearchScreen(
|
|
|
|
category: category,
|
|
|
|
keyword: widget.keyword,
|
|
|
|
);
|
|
|
|
},
|
|
|
|
));
|
|
|
|
}
|
|
|
|
},
|
2022-03-19 04:12:27 +00:00
|
|
|
icon: const Icon(Icons.category),
|
2021-09-29 23:57:09 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
Future<ComicsPage> _fetch(String _currentSort, int _currentPage) {
|
|
|
|
if (widget.category == null) {
|
|
|
|
return method.searchComics(widget.keyword, _currentSort, _currentPage);
|
|
|
|
} else {
|
|
|
|
return method.searchComicsInCategories(
|
|
|
|
widget.keyword,
|
|
|
|
_currentSort,
|
|
|
|
_currentPage,
|
|
|
|
[widget.category!],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@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
|
|
|
return Scaffold(
|
|
|
|
appBar: _searchBar.build(context),
|
|
|
|
body: ComicPager(
|
|
|
|
fetchPage: _fetch,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|