提交 79b2f474 authored 作者: maodou's avatar maodou

1:修复 搜索页点击历史搜索未进行搜索的问题

上级 586ac1e7
...@@ -6,7 +6,7 @@ class SearchController extends GetxController { ...@@ -6,7 +6,7 @@ class SearchController extends GetxController {
controlFinishRefresh: true, controlFinishRefresh: true,
); );
late TextEditingController searchController = TextEditingController(); late TextEditingController searchController = TextEditingController();
bool showHistory = true;
// 搜索记录数组 // 搜索记录数组
List<String> records = []; List<String> records = [];
// 书籍数组 // 书籍数组
......
...@@ -8,7 +8,6 @@ class SearchPage extends StatefulWidget { ...@@ -8,7 +8,6 @@ class SearchPage extends StatefulWidget {
} }
class _SearchPageState extends State<SearchPage> { class _SearchPageState extends State<SearchPage> {
bool showHistory = true; // 根据条件设置为true或false
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return GetBuilder<SearchController>( return GetBuilder<SearchController>(
...@@ -27,7 +26,7 @@ class _SearchPageState extends State<SearchPage> { ...@@ -27,7 +26,7 @@ class _SearchPageState extends State<SearchPage> {
// context.pushNamed(Routes.msgs); // context.pushNamed(Routes.msgs);
}, },
onEditingComplete: () { onEditingComplete: () {
showHistory = false; controller.showHistory = false;
controller.search(); controller.search();
// FocusScope.of(context).unfocus(); // FocusScope.of(context).unfocus();
FocusNode blankNode = FocusNode(); FocusNode blankNode = FocusNode();
...@@ -57,7 +56,7 @@ class _SearchPageState extends State<SearchPage> { ...@@ -57,7 +56,7 @@ class _SearchPageState extends State<SearchPage> {
} }
Widget buildListView(SearchController controller) { Widget buildListView(SearchController controller) {
if (showHistory) { if (controller.showHistory) {
// 如果条件为true,显示历史搜索记录 // 如果条件为true,显示历史搜索记录
return BuildHistory(controller: controller); return BuildHistory(controller: controller);
} else { } else {
......
...@@ -2,7 +2,6 @@ part of search; ...@@ -2,7 +2,6 @@ part of search;
class BuildHistory extends StatefulWidget { class BuildHistory extends StatefulWidget {
final SearchController controller; final SearchController controller;
const BuildHistory({ const BuildHistory({
Key? key, Key? key,
required this.controller, required this.controller,
...@@ -65,6 +64,13 @@ class _BuildHistoryState extends State<BuildHistory> { ...@@ -65,6 +64,13 @@ class _BuildHistoryState extends State<BuildHistory> {
}else { }else {
return searchList.map((e){ return searchList.map((e){
return GestureDetector( return GestureDetector(
onTap: () {
// showHistory = false;
widget.controller.searchController.text =e;
widget.controller.showHistory = false;
widget.controller.search();
Console.log('点击了-$e');
},
child: Container( child: Container(
height: 27, height: 27,
decoration: BoxDecoration( decoration: BoxDecoration(
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论