当前位置: 首页> 健康> 知识 > 人工智能的网站_服务网站建设推广_可以免费领取会员的软件_国际新闻稿件

人工智能的网站_服务网站建设推广_可以免费领取会员的软件_国际新闻稿件

时间:2025/7/13 7:57:22来源:https://blog.csdn.net/qq_40745143/article/details/144659449 浏览次数:0次
人工智能的网站_服务网站建设推广_可以免费领取会员的软件_国际新闻稿件

view

import 'package:demo/common/index.dart';
import 'package:ducafe_ui_core/ducafe_ui_core.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:tdesign_flutter/tdesign_flutter.dart';import 'index.dart';class SearchKeywordPage extends GetView<SearchKeywordController> {const SearchKeywordPage({super.key});// 搜索Widget _buildSearch() {return <Widget>[TDImage(assetUrl: 'assets/img/search.png',width: 32.w,height: 32.w,),SizedBox(width: 20.w,),Container(width: 1.w,height: 28.w,color: const Color(0xffe9e9e9),),SizedBox(width: 20.w,),/// 输入框TDInput(leftLabel: '',leftLabelSpace: 0,textStyle: TextStyle(fontSize: 28.sp, color: const Color(0xff181818)),hintText: '搜索心仪的商品',hintTextStyle:TextStyle(fontSize: 28.sp, color: const Color(0xff181818)),backgroundColor: Colors.white,showBottomDivider: false,controller: controller.searchKeyController,inputType: TextInputType.text,contentPadding: EdgeInsets.only(top: 12.w),onChanged: (value) {controller.changeSearchKey(value);},onClearTap: () {controller.searchKeyController.text = '';controller.changeSearchKey('');},onSubmitted: (value) {if (value.isNotEmpty) {controller.onTapSearch(value);}},).expanded(),].toRow().paddingHorizontal(30.w).card(color: Colors.white,shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(35.w))).tight(width: 690.w, height: 70.w).marginOnly(top: 30.w, right: 0);}// 搜索历史标题Widget _buildSearchHistoryTitle(BuildContext context) {return <Widget>[const TextWidget.body('搜索历史', color: Color(0xff999999)),TDImage(assetUrl: 'assets/img/del.png',width: 30.w,height: 30.w,).onTap(() {showGeneralDialog(context: context,pageBuilder: (BuildContext buildContext, Animation<double> animation,Animation<double> secondaryAnimation) {return TDAlertDialog(title: '清空搜索历史',content: '请确定清空搜索历史?',buttonWidget: <Widget>[<Widget>[const TextWidget.body('取消')].toRow(mainAxisAlignment: MainAxisAlignment.center).card(color: const Color(0xffeeeeee)).tight(width: 240.w, height: 80.w).onTap(() => Navigator.of(context).pop()),<Widget>[const TextWidget.body('确定',color: Colors.white,)].toRow(mainAxisAlignment: MainAxisAlignment.center).card(color: const Color(0xffE93323)).tight(width: 240.w, height: 80.w).onTap(() {controller.clearSearchHistory();Navigator.of(context).pop();}),].toRow(mainAxisAlignment: MainAxisAlignment.spaceBetween).paddingOnly(left: 30.w, right: 30.w, bottom: 40.w),);},);})].toRow(mainAxisAlignment: MainAxisAlignment.spaceBetween).marginOnly(top: 30.w, bottom: 20.w);}// 搜索历史Widget _buildSearchHistory() {return SizedBox(// 添加一个固定宽度的容器width: double.infinity, // 让Wrap占满父容器宽度child: <Widget>[for (var i = 0; i < controller.searchHistory.length; i++)IntrinsicWidth(child: <Widget>[TextWidget.body(controller.searchHistory[i],size: 26.sp, color: const Color(0xff666666)),].toRow().paddingHorizontal(30.w).card().onTap(() {controller.onTapSearchValue(controller.searchHistory[i]);}),),].toWrap(spacing: 15.w, // 添加水平间距runSpacing: 15.w,alignment: WrapAlignment.start, // 添加左对齐crossAxisAlignment: WrapCrossAlignment.start,));}// 主视图Widget _buildView(BuildContext context) {return <Widget>[_buildSearch(),_buildSearchHistoryTitle(context),const Divider(height: 1,color: Color(0xff666666),),SizedBox(height: 30.w,),_buildSearchHistory(),].toColumn().paddingHorizontal(30.w);}@overrideWidget build(BuildContext context) {return GetBuilder<SearchKeywordController>(init: SearchKeywordController(),id: "search_keyword",builder: (_) {return Scaffold(backgroundColor: const Color(0xffF5F6FA),appBar: const TDNavBar(height: 45,title: '搜索',titleFontWeight: FontWeight.w600,backgroundColor: Colors.white,screenAdaptation: true,useDefaultBack: true,),body: SafeArea(child: _buildView(context),),);},);}
}

controller

import 'package:demo/common/index.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';class SearchKeywordController extends GetxController {SearchKeywordController();// 搜索控制器final searchKeyController = TextEditingController();// 搜索关键词String searchKey = '';// 搜索历史List<String> searchHistory = [];// 点击搜索时void onTapSearch(String value) {// 查找是否存在该搜索词final index = searchHistory.indexOf(value);// 如果已存在,删除旧值if (index != -1) {searchHistory.removeAt(index);}// 将新搜索词添加到数组开头searchHistory.insert(0, value);// 限制历史记录条数if (searchHistory.length > 20) {searchHistory = searchHistory.sublist(0, 20);}// 保存更新后的搜索历史Storage().setList('search_history', searchHistory);searchKeyController.text = '';// 使用 Get.toNamed 的返回回调来刷新数据Get.toNamed('/search_list_page', arguments: {'searchKey': value})?.then((_) {_initData(); // 返回时重新加载数据});}// 点击搜索值跳转搜索列表void onTapSearchValue(String value) {Get.toNamed('/search_list_page', arguments: {'searchKey': value})?.then((_) {_initData(); // 返回时重新加载数据});}// 清空搜索历史void clearSearchHistory() {searchHistory = [];Storage().setList('search_history', searchHistory);update(["search_keyword"]);}// 输入框内容发生改变void changeSearchKey(String value) {searchKey = value;update(["search_keyword"]);}// 初始化数据void _initData() {searchHistory = Storage().getList('search_history');update(["search_keyword"]);}@overridevoid onReady() {super.onReady();_initData();}@overridevoid onClose() {super.onClose();searchKeyController.dispose();}
}

在这里插入图片描述
在这里插入图片描述

关键字:人工智能的网站_服务网站建设推广_可以免费领取会员的软件_国际新闻稿件

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: