feat: 长按删除搜索记录
This commit is contained in:
@ -117,6 +117,13 @@ class SSearchController extends GetxController {
|
|||||||
submit();
|
submit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onLongSelect(word) {
|
||||||
|
int index = historyList.indexOf(word);
|
||||||
|
historyList.value = historyList.removeAt(index);
|
||||||
|
historyList.refresh();
|
||||||
|
histiryWord.put('cacheList', historyList);
|
||||||
|
}
|
||||||
|
|
||||||
onClearHis() {
|
onClearHis() {
|
||||||
historyList.value = [];
|
historyList.value = [];
|
||||||
historyCacheList = [];
|
historyCacheList = [];
|
||||||
|
|||||||
@ -299,20 +299,24 @@ class _SearchPageState extends State<SearchPage> with RouteAware {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
// if (_searchController.historyList.isNotEmpty)
|
// if (_searchController.historyList.isNotEmpty)
|
||||||
Wrap(
|
Obx(() => Wrap(
|
||||||
spacing: 8,
|
spacing: 8,
|
||||||
runSpacing: 8,
|
runSpacing: 8,
|
||||||
direction: Axis.horizontal,
|
direction: Axis.horizontal,
|
||||||
textDirection: TextDirection.ltr,
|
textDirection: TextDirection.ltr,
|
||||||
children: [
|
children: [
|
||||||
for (int i = 0; i < _searchController.historyList.length; i++)
|
for (int i = 0;
|
||||||
|
i < _searchController.historyList.length;
|
||||||
|
i++)
|
||||||
SearchText(
|
SearchText(
|
||||||
searchText: _searchController.historyList[i],
|
searchText: _searchController.historyList[i],
|
||||||
searchTextIdx: i,
|
searchTextIdx: i,
|
||||||
onSelect: (value) => _searchController.onSelect(value),
|
onSelect: (value) => _searchController.onSelect(value),
|
||||||
|
onLongSelect: (value) =>
|
||||||
|
_searchController.onLongSelect(value),
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
),
|
)),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
@ -4,8 +4,14 @@ class SearchText extends StatelessWidget {
|
|||||||
final String? searchText;
|
final String? searchText;
|
||||||
final Function? onSelect;
|
final Function? onSelect;
|
||||||
final int? searchTextIdx;
|
final int? searchTextIdx;
|
||||||
const SearchText(
|
final Function? onLongSelect;
|
||||||
{super.key, this.searchText, this.onSelect, this.searchTextIdx});
|
const SearchText({
|
||||||
|
super.key,
|
||||||
|
this.searchText,
|
||||||
|
this.onSelect,
|
||||||
|
this.searchTextIdx,
|
||||||
|
this.onLongSelect,
|
||||||
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
@ -18,6 +24,9 @@ class SearchText extends StatelessWidget {
|
|||||||
onTap: () {
|
onTap: () {
|
||||||
onSelect!(searchText);
|
onSelect!(searchText);
|
||||||
},
|
},
|
||||||
|
onLongPress: () {
|
||||||
|
onLongSelect!(searchText);
|
||||||
|
},
|
||||||
borderRadius: BorderRadius.circular(6),
|
borderRadius: BorderRadius.circular(6),
|
||||||
child: Padding(
|
child: Padding(
|
||||||
padding:
|
padding:
|
||||||
|
|||||||
Reference in New Issue
Block a user