v1.0.1
This commit is contained in:
98
lib/modules/comic/search/comic_search_controller.dart
Normal file
98
lib/modules/comic/search/comic_search_controller.dart
Normal file
@@ -0,0 +1,98 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_dmzj/app/dialog_utils.dart';
|
||||
import 'package:flutter_dmzj/app/controller/base_controller.dart';
|
||||
import 'package:flutter_dmzj/app/log.dart';
|
||||
import 'package:flutter_dmzj/models/comic/search_item.dart';
|
||||
import 'package:flutter_dmzj/requests/comic_request.dart';
|
||||
import 'package:flutter_dmzj/routes/app_navigator.dart';
|
||||
import 'package:get/get.dart';
|
||||
|
||||
class ComicSearchController extends BasePageController<SearchComicItem> {
|
||||
final String keyword;
|
||||
ComicSearchController(this.keyword) {
|
||||
searchController = TextEditingController(text: keyword);
|
||||
showHotWord.value = keyword.isEmpty;
|
||||
}
|
||||
late TextEditingController searchController;
|
||||
final ComicRequest request = ComicRequest();
|
||||
|
||||
String _keyword = "";
|
||||
|
||||
RxMap<int, String> hotWords = <int, String>{}.obs;
|
||||
|
||||
var showHotWord = true.obs;
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
// loadHotWord();
|
||||
if (keyword.isNotEmpty) {
|
||||
submit();
|
||||
}
|
||||
super.onInit();
|
||||
}
|
||||
|
||||
void submit() async {
|
||||
if (searchController.text.isEmpty) {
|
||||
list.clear();
|
||||
showHotWord.value = true;
|
||||
return;
|
||||
}
|
||||
|
||||
if (int.tryParse(searchController.text) != null &&
|
||||
await numberJumpComic()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (searchController.text.startsWith("id:\\") && await handelJumpComic()) {
|
||||
return;
|
||||
}
|
||||
|
||||
showHotWord.value = false;
|
||||
_keyword = searchController.text;
|
||||
refreshData();
|
||||
}
|
||||
|
||||
Future<bool> handelJumpComic() async {
|
||||
var id = int.tryParse(searchController.text.replaceAll("id:\\", "")) ?? 0;
|
||||
if (id != 0) {
|
||||
AppNavigator.toComicDetail(id);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Future numberJumpComic() async {
|
||||
if (!await DialogUtils.showAlertDialog(
|
||||
"你输入了纯数字,是否跳转至对应的漫画?",
|
||||
title: "漫画ID跳转",
|
||||
)) {
|
||||
return false;
|
||||
}
|
||||
return await handelJumpComic();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<List<SearchComicItem>> getData(int page, int pageSize) async {
|
||||
if (searchController.text.isEmpty) {
|
||||
return [];
|
||||
}
|
||||
// if (AppSettingsService.instance.comicSearchUseWebApi.value) {
|
||||
// //WEB接口不能分页
|
||||
// if (page > 1) {
|
||||
// return [];
|
||||
// }
|
||||
// return await request.searchWeb(keyword: _keyword);
|
||||
// } else {
|
||||
return await request.search(keyword: _keyword, page: page);
|
||||
//}
|
||||
}
|
||||
|
||||
void loadHotWord() async {
|
||||
try {
|
||||
hotWords.value = await request.searchHotWord();
|
||||
} catch (e) {
|
||||
Log.logPrint(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
171
lib/modules/comic/search/comic_search_page.dart
Normal file
171
lib/modules/comic/search/comic_search_page.dart
Normal file
@@ -0,0 +1,171 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_dmzj/app/app_style.dart';
|
||||
import 'package:flutter_dmzj/models/comic/search_item.dart';
|
||||
import 'package:flutter_dmzj/modules/comic/search/comic_search_controller.dart';
|
||||
import 'package:flutter_dmzj/routes/app_navigator.dart';
|
||||
import 'package:flutter_dmzj/widgets/net_image.dart';
|
||||
import 'package:flutter_dmzj/widgets/page_list_view.dart';
|
||||
import 'package:get/get.dart';
|
||||
|
||||
class ComicSearchPage extends StatelessWidget {
|
||||
final String keyword;
|
||||
final ComicSearchController controller;
|
||||
ComicSearchPage({this.keyword = "", super.key})
|
||||
: controller = Get.put(ComicSearchController(keyword));
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
automaticallyImplyLeading: false,
|
||||
titleSpacing: 8,
|
||||
title: SizedBox(
|
||||
height: 40,
|
||||
child: TextField(
|
||||
controller: controller.searchController,
|
||||
autofocus: true,
|
||||
decoration: InputDecoration(
|
||||
hintText: "搜索漫画",
|
||||
contentPadding: AppStyle.edgeInsetsH12,
|
||||
border: const OutlineInputBorder(),
|
||||
prefixIcon: SizedBox(
|
||||
width: 48,
|
||||
child: IconButton(
|
||||
onPressed: () {
|
||||
AppNavigator.closePage();
|
||||
},
|
||||
icon: const Icon(Icons.arrow_back),
|
||||
),
|
||||
),
|
||||
suffixIcon: SizedBox(
|
||||
width: 48,
|
||||
child: IconButton(
|
||||
onPressed: controller.submit,
|
||||
icon: const Icon(Icons.search),
|
||||
),
|
||||
),
|
||||
),
|
||||
onSubmitted: (e) {
|
||||
controller.submit();
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
body: Stack(
|
||||
children: [
|
||||
PageListView(
|
||||
pageController: controller,
|
||||
firstRefresh: false,
|
||||
showPageLoadding: true,
|
||||
separatorBuilder: (context, i) => Divider(
|
||||
endIndent: 12,
|
||||
indent: 12,
|
||||
color: Colors.grey.withOpacity(.2),
|
||||
height: 1,
|
||||
),
|
||||
itemBuilder: (context, i) {
|
||||
var item = controller.list[i];
|
||||
return buildItem(item);
|
||||
},
|
||||
),
|
||||
// Positioned.fill(
|
||||
// child: Obx(
|
||||
// () => Offstage(
|
||||
// offstage: !controller.showHotWord.value,
|
||||
// child: SingleChildScrollView(
|
||||
// child: Column(
|
||||
// children: [
|
||||
// const ListTile(
|
||||
// title: Text("热门搜索"),
|
||||
// ),
|
||||
// Padding(
|
||||
// padding: AppStyle.edgeInsetsH12.copyWith(bottom: 12),
|
||||
// child: Wrap(
|
||||
// spacing: 8,
|
||||
// runSpacing: 8,
|
||||
// children: controller.hotWords.keys
|
||||
// .map(
|
||||
// (e) => OutlinedButton(
|
||||
// style: OutlinedButton.styleFrom(
|
||||
// tapTargetSize:
|
||||
// MaterialTapTargetSize.shrinkWrap,
|
||||
// ),
|
||||
// onPressed: () {
|
||||
// AppNavigator.toComicDetail(e);
|
||||
// },
|
||||
// child: Text(controller.hotWords[e] ?? ""),
|
||||
// ),
|
||||
// )
|
||||
// .toList(),
|
||||
// ),
|
||||
// )
|
||||
// ],
|
||||
// ),
|
||||
// ),
|
||||
// ),
|
||||
// ),
|
||||
// ),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget buildItem(SearchComicItem item) {
|
||||
return InkWell(
|
||||
onTap: () {
|
||||
AppNavigator.toComicDetail(item.comicId);
|
||||
},
|
||||
child: Container(
|
||||
padding: AppStyle.edgeInsetsA12,
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
NetImage(
|
||||
item.cover,
|
||||
width: 80,
|
||||
height: 110,
|
||||
borderRadius: 4,
|
||||
),
|
||||
AppStyle.hGap12,
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
Text(
|
||||
item.title,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
const SizedBox(height: 2),
|
||||
Text.rich(
|
||||
TextSpan(children: [
|
||||
const WidgetSpan(
|
||||
child: Icon(
|
||||
Icons.account_circle,
|
||||
color: Colors.grey,
|
||||
size: 18,
|
||||
)),
|
||||
const TextSpan(
|
||||
text: " ",
|
||||
),
|
||||
TextSpan(
|
||||
text: item.author,
|
||||
style:
|
||||
const TextStyle(color: Colors.grey, fontSize: 14))
|
||||
]),
|
||||
),
|
||||
AppStyle.vGap4,
|
||||
Text(item.tags,
|
||||
style: const TextStyle(color: Colors.grey, fontSize: 14)),
|
||||
AppStyle.vGap4,
|
||||
Text(item.lastChapterName,
|
||||
style: const TextStyle(color: Colors.grey, fontSize: 14)),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user