From 96523a99ce0065af4d292b8b944b075b4d3f7de2 Mon Sep 17 00:00:00 2001 From: guozhigq Date: Sat, 11 Nov 2023 23:39:54 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E9=95=BF=E6=8C=89=E5=88=A0=E9=99=A4?= =?UTF-8?q?=E6=90=9C=E7=B4=A2=E8=AE=B0=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/pages/search/controller.dart | 7 +++++ lib/pages/search/view.dart | 32 +++++++++++++---------- lib/pages/search/widgets/search_text.dart | 13 +++++++-- 3 files changed, 36 insertions(+), 16 deletions(-) diff --git a/lib/pages/search/controller.dart b/lib/pages/search/controller.dart index b95b048b..59d51a41 100644 --- a/lib/pages/search/controller.dart +++ b/lib/pages/search/controller.dart @@ -117,6 +117,13 @@ class SSearchController extends GetxController { submit(); } + onLongSelect(word) { + int index = historyList.indexOf(word); + historyList.value = historyList.removeAt(index); + historyList.refresh(); + histiryWord.put('cacheList', historyList); + } + onClearHis() { historyList.value = []; historyCacheList = []; diff --git a/lib/pages/search/view.dart b/lib/pages/search/view.dart index 81f56ce0..0ec910f1 100644 --- a/lib/pages/search/view.dart +++ b/lib/pages/search/view.dart @@ -299,20 +299,24 @@ class _SearchPageState extends State with RouteAware { ), ), // if (_searchController.historyList.isNotEmpty) - Wrap( - spacing: 8, - runSpacing: 8, - direction: Axis.horizontal, - textDirection: TextDirection.ltr, - children: [ - for (int i = 0; i < _searchController.historyList.length; i++) - SearchText( - searchText: _searchController.historyList[i], - searchTextIdx: i, - onSelect: (value) => _searchController.onSelect(value), - ) - ], - ), + Obx(() => Wrap( + spacing: 8, + runSpacing: 8, + direction: Axis.horizontal, + textDirection: TextDirection.ltr, + children: [ + for (int i = 0; + i < _searchController.historyList.length; + i++) + SearchText( + searchText: _searchController.historyList[i], + searchTextIdx: i, + onSelect: (value) => _searchController.onSelect(value), + onLongSelect: (value) => + _searchController.onLongSelect(value), + ) + ], + )), ], ), ), diff --git a/lib/pages/search/widgets/search_text.dart b/lib/pages/search/widgets/search_text.dart index 9f5f84c3..039a851b 100644 --- a/lib/pages/search/widgets/search_text.dart +++ b/lib/pages/search/widgets/search_text.dart @@ -4,8 +4,14 @@ class SearchText extends StatelessWidget { final String? searchText; final Function? onSelect; final int? searchTextIdx; - const SearchText( - {super.key, this.searchText, this.onSelect, this.searchTextIdx}); + final Function? onLongSelect; + const SearchText({ + super.key, + this.searchText, + this.onSelect, + this.searchTextIdx, + this.onLongSelect, + }); @override Widget build(BuildContext context) { @@ -18,6 +24,9 @@ class SearchText extends StatelessWidget { onTap: () { onSelect!(searchText); }, + onLongPress: () { + onLongSelect!(searchText); + }, borderRadius: BorderRadius.circular(6), child: Padding( padding: