diff --git a/lib/pages/search_page/notifier/search_tag_notifier.dart b/lib/pages/search_page/notifier/search_tag_notifier.dart index fc16cfb..2355800 100644 --- a/lib/pages/search_page/notifier/search_tag_notifier.dart +++ b/lib/pages/search_page/notifier/search_tag_notifier.dart @@ -27,14 +27,25 @@ class SearchTagNotifier with ChangeNotifier { return _tagList; } - /// 添加搜索 + /// 添加搜索标签 void addTag(String tag) async { SharedPreferences prefs = await SharedPreferences.getInstance(); String jsonStr = prefs.getString(_SP_HOISTROY_KEY); if (null != jsonStr && jsonStr.length > 0) { final Map jsonMap = jsonDecode(jsonStr); - jsonMap[tag.toString()] = tag.toString(); + if(jsonMap.containsKey(tag)){ + if(_tagList.length > 0) { + int lastIndex = 0; + for (int i = 0; i < _tagList.length; i++) { + if(tag == _tagList[i]){ + lastIndex = i; + } + } + _tagList.removeAt(lastIndex); + } + } + jsonMap[tag.toString()] = tag.toString(); _tagList.insert(0, tag); // 第一位 if (_tagList.length > _MAX_COUNT) { jsonMap.remove(_tagList[_tagList.length - 1]); diff --git a/lib/pages/search_page/search_page.dart b/lib/pages/search_page/search_page.dart index c332847..bce11f4 100644 --- a/lib/pages/search_page/search_page.dart +++ b/lib/pages/search_page/search_page.dart @@ -117,8 +117,11 @@ class _SearchPageContianerState extends State { Widget _getMainWidget(List> datas) { return Scaffold( backgroundColor: Colors.white, - body: Column( - children: _createContentWidget(datas), + body: Listener( + onPointerDown: (down) => RouterUtil.hideKeyboard(context), + child: Column( + children: _createContentWidget(datas), + ), ), ); } diff --git a/lib/pages/search_result_page/item/search_result_item_page.dart b/lib/pages/search_result_page/item/search_result_item_page.dart index 9c92524..dd90987 100644 --- a/lib/pages/search_result_page/item/search_result_item_page.dart +++ b/lib/pages/search_result_page/item/search_result_item_page.dart @@ -61,7 +61,6 @@ class _SearchResultItemPageContianerState extends State= _controller.position.maxScrollExtent && !_isEnded) { @@ -127,31 +126,34 @@ class _SearchResultItemPageContianerState extends State> datas) { return Scaffold( backgroundColor: HexColor.fromHex('#F9F9F9'), - body: Stack( - children: [ - Positioned( - top: 20, - left: 0, - right: 0, - bottom: 0, - child: SmartRefresher( - onLoading: _onLoading, - onRefresh: _onRefresh, - enablePullDown: true, - enablePullUp: true, - // footer: ClassicFooter(), - // header: MaterialClassicHeader(), - controller: _refreshController, - child: CustomScrollView( - controller: _controller, - slivers: _createContentWidget(datas), + body: Listener( + onPointerDown: (down) => RouterUtil.hideKeyboard(context), + child: Stack( + children: [ + Positioned( + top: 20, + left: 0, + right: 0, + bottom: 0, + child: SmartRefresher( + onLoading: _onLoading, + onRefresh: _onRefresh, + enablePullDown: true, + enablePullUp: true, + // footer: ClassicFooter(), + // header: MaterialClassicHeader(), + controller: _refreshController, + child: CustomScrollView( + controller: _controller, + slivers: _createContentWidget(datas), + ), ), ), - ), - /// 筛选栏 - _getSearchResultSortWidget(datas), - ], + /// 筛选栏 + _getSearchResultSortWidget(datas), + ], + ), ), ); } diff --git a/lib/pages/search_result_page/search_result_page.dart b/lib/pages/search_result_page/search_result_page.dart index 99f3b14..e5c6dce 100644 --- a/lib/pages/search_result_page/search_result_page.dart +++ b/lib/pages/search_result_page/search_result_page.dart @@ -1,9 +1,11 @@ import 'package:flutter/material.dart'; +import 'package:zhiying_base_widget/pages/search_page/notifier/search_tag_notifier.dart'; import 'package:zhiying_base_widget/pages/search_result_page/bloc/search_result_bloc.dart'; import 'package:zhiying_base_widget/pages/search_think_page/bloc/search_think_bloc.dart'; import 'package:zhiying_base_widget/pages/search_think_page/bloc/search_think_repository.dart'; import 'package:zhiying_comm/zhiying_comm.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:provider/provider.dart'; import 'bloc/search_result_repository.dart'; @@ -21,20 +23,25 @@ class SearchResultPage extends StatelessWidget { // create: (_) => SearchResultBloc(repository: SearchResultRepository())..add(SearchResultInitEvent(model: data)), // child: SearchResultContianer(), // ); - - return MultiBlocProvider( + return MultiProvider( providers: [ - /// 页面的数据 - BlocProvider( - create: (_) => SearchResultBloc(repository: SearchResultRepository())..add(SearchResultInitEvent(model: data)), - ), - - /// 输入框联想的bloc - BlocProvider( - create: (_)=> SearchThinkBloc(SearchThinkRepository()), - ), + ChangeNotifierProvider.value(value: SearchTagNotifier()) ], - child: SearchResultContianer(), + child: MultiBlocProvider( + providers: [ + + /// 页面的数据 + BlocProvider( + create: (_) => SearchResultBloc(repository: SearchResultRepository())..add(SearchResultInitEvent(model: data)), + ), + + /// 输入框联想的bloc + BlocProvider( + create: (_)=> SearchThinkBloc(SearchThinkRepository()), + ), + ], + child: SearchResultContianer(), + ), ); } } diff --git a/lib/pages/search_think_page/bloc/search_think_bloc.dart b/lib/pages/search_think_page/bloc/search_think_bloc.dart index 80eb345..7457203 100644 --- a/lib/pages/search_think_page/bloc/search_think_bloc.dart +++ b/lib/pages/search_think_page/bloc/search_think_bloc.dart @@ -30,7 +30,7 @@ class SearchThinkBloc extends Bloc { /// 修改渠道关键字 if (event is SearchThinkChangeTypeEvent) { - _mapChangeTypeToState(event); + _mapChangeTypeToState( state, event); } /// 显示原本的视图 @@ -55,7 +55,8 @@ class SearchThinkBloc extends Bloc { } /// 修改商品电商类型 - _mapChangeTypeToState(SearchThinkChangeTypeEvent event) { + Stream _mapChangeTypeToState(SearchThinkState state,SearchThinkChangeTypeEvent event) async* { repository.changeType(event.type); + yield state; } } diff --git a/lib/widgets/home/home_goods/home_goods_item.dart b/lib/widgets/home/home_goods/home_goods_item.dart index d3b45ec..8568a63 100644 --- a/lib/widgets/home/home_goods/home_goods_item.dart +++ b/lib/widgets/home/home_goods/home_goods_item.dart @@ -26,6 +26,7 @@ class HomeGoodsItem extends StatelessWidget { /// 跳到商品详情 void _onJumpGoodsDetails(BuildContext context, HomeGoodsModel goods) { + RouterUtil.hideKeyboard(context); Navigator.push(context, CupertinoPageRoute(builder: (_) => GoodsDetailsPage(goods.toJson()))); } diff --git a/lib/widgets/home/home_goods/home_goods_item_single.dart b/lib/widgets/home/home_goods/home_goods_item_single.dart index eb34b8b..edcdb20 100644 --- a/lib/widgets/home/home_goods/home_goods_item_single.dart +++ b/lib/widgets/home/home_goods/home_goods_item_single.dart @@ -26,6 +26,7 @@ class HomeGoodsItemSingle extends StatelessWidget { /// 跳到商品详情 void _onJumpGoodsDetails(BuildContext context, HomeGoodsModel goods) { + RouterUtil.hideKeyboard(context); Navigator.push(context, CupertinoPageRoute(builder: (_) => GoodsDetailsPage(goods.toJson()))); } diff --git a/lib/widgets/mine/mine_data/mine_data_container.dart b/lib/widgets/mine/mine_data/mine_data_container.dart index 4e36668..b32853e 100644 --- a/lib/widgets/mine/mine_data/mine_data_container.dart +++ b/lib/widgets/mine/mine_data/mine_data_container.dart @@ -32,7 +32,7 @@ class _MineDataContainerState extends State { MineProfileModel profile = snapshot.data; return profile == null ? MineDataSkeleton() - : MineDataWidget(profile, widget.data); + : MineDataWidget(profile, widget?.data); }); } } diff --git a/lib/widgets/mine/mine_header/mine_header_container.dart b/lib/widgets/mine/mine_header/mine_header_container.dart index 7c47b49..6d6ad43 100644 --- a/lib/widgets/mine/mine_header/mine_header_container.dart +++ b/lib/widgets/mine/mine_header/mine_header_container.dart @@ -79,7 +79,7 @@ class _MineHeaderContainerState extends State { Row( children: [ Text( - profile.username, + profile?.username ?? '', maxLines: 1, overflow: TextOverflow.ellipsis, style: TextStyle( diff --git a/lib/widgets/search/history_tag/search_history_tag.dart b/lib/widgets/search/history_tag/search_history_tag.dart index 1526e8b..ac22cff 100644 --- a/lib/widgets/search/history_tag/search_history_tag.dart +++ b/lib/widgets/search/history_tag/search_history_tag.dart @@ -41,6 +41,7 @@ class _SearchHistoryTagWidgetState extends State { /// 点击历史标签 void _historyTagClick(String tag) { if (!EmptyUtil.isEmpty(tag)) { + Provider.of(context, listen: false).addTag(tag); Navigator.push(context, CupertinoPageRoute(builder: (_) => SearchResultPage({'keywords': tag ?? '', 'tag': 'search_page'}))); } } @@ -82,10 +83,8 @@ class _SearchHistoryTagWidgetState extends State { /// 点击清除所有历史记录 void _clearTag() async { - await Provider.of(context, listen: false).clear(); - setState(() { - - }); + Provider.of(context, listen: false).clear(); + setState(() {}); } @override @@ -96,8 +95,7 @@ class _SearchHistoryTagWidgetState extends State { _initHistoryTag() async { _tagList = await Provider.of(context, listen: false).getHistoryTag(); - setState(() { - }); + setState(() {}); } @override diff --git a/lib/widgets/search/hot_tag/search_hot_tag_widget.dart b/lib/widgets/search/hot_tag/search_hot_tag_widget.dart index 9dd32a2..0e57a6f 100644 --- a/lib/widgets/search/hot_tag/search_hot_tag_widget.dart +++ b/lib/widgets/search/hot_tag/search_hot_tag_widget.dart @@ -30,7 +30,7 @@ class SearchHotTagWidget extends StatelessWidget { print('${model?.keyword}'); if (!EmptyUtil.isEmpty(model?.keyword)) { - await Provider.of(context, listen: false).addTag(model.keyword); + Provider.of(context, listen: false).addTag(model.keyword); Navigator.push(context, CupertinoPageRoute(builder: (_) => SearchResultPage({'keywords': model?.keyword ?? '', 'tag': 'search_page'}))); } diff --git a/lib/widgets/search/input/search_input_widget.dart b/lib/widgets/search/input/search_input_widget.dart index 50b0373..a3dbb80 100644 --- a/lib/widgets/search/input/search_input_widget.dart +++ b/lib/widgets/search/input/search_input_widget.dart @@ -35,19 +35,18 @@ class SearchInputWidget extends StatefulWidget { } class _SearchInputWidgetState extends State { + FocusNode _focusNode; + TextEditingController _editingController; + /// 点击搜索按钮 void _onSearchButtomClick() async { String content = _editingController?.text?.toString()?.trim() ?? ''; /// TODO 保存历史标签 if (!EmptyUtil.isEmpty(content)) { - await Provider.of(context, listen: false) - .addTag(content); - Navigator.push( - context, - CupertinoPageRoute( - builder: (_) => SearchResultPage( - {'keywords': content, 'tag': 'search_page'}))); + Provider.of(context, listen: false).addTag(content); + RouterUtil.hideKeyboard(context); + Navigator.push(context, CupertinoPageRoute(builder: (_) => SearchResultPage({'keywords': content, 'tag': 'search_page'}))); } else { Fluttertoast.showToast(msg: '输入内容不能为空!'); } @@ -55,8 +54,7 @@ class _SearchInputWidgetState extends State { /// 【弃用】打开搜索联想页面 void _openSearchThinkPage() { - Navigator.push( - context, CupertinoPageRoute(builder: (_) => SearchThinkPage({}))); + Navigator.push(context, CupertinoPageRoute(builder: (_) => SearchThinkPage({}))); } /// 搜索框值改变 @@ -64,17 +62,16 @@ class _SearchInputWidgetState extends State { if (!EmptyUtil.isEmpty(text)) { // 进行网络更新 print('输入框的内容是 $text'); - BlocProvider.of(context) - .add(SearchThinkKeyWrodsChangeEvent(text)); + BlocProvider.of(context).add(SearchThinkKeyWrodsChangeEvent(text)); } else { /// 输入框为空的时候,隐藏联想视图,显示原本的视图 - BlocProvider.of(context) - .add(SearchThinkShowBaseViewEvent()); + BlocProvider.of(context).add(SearchThinkShowBaseViewEvent()); } } - FocusNode _focusNode; - TextEditingController _editingController; + void _onEditingComplete() { + Logger.log('=======我输入完毕拉!!!!'); + } @override void didChangeDependencies() { @@ -110,10 +107,7 @@ class _SearchInputWidgetState extends State { return Container( color: Colors.white, width: double.infinity, - margin: EdgeInsets.only( - top: MediaQueryData.fromWindow(window).padding.top + 7.5, - left: 12.5, - right: 12.5), + margin: EdgeInsets.only(top: MediaQueryData.fromWindow(window).padding.top + 7.5, left: 12.5, right: 12.5), child: Row( children: [ /// 返回键 @@ -186,9 +180,7 @@ class _SearchInputWidgetState extends State { return Container( height: double.infinity, alignment: Alignment.centerLeft, - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(30), - color: HexColor.fromHex('#F9F9F9')), + decoration: BoxDecoration(borderRadius: BorderRadius.circular(30), color: HexColor.fromHex('#F9F9F9')), // padding: const EdgeInsets.symmetric(vertical: 6), child: TextField( showCursor: true, @@ -197,17 +189,16 @@ class _SearchInputWidgetState extends State { onChanged: (val) => _searchInputChange(val), cursorWidth: 1, onSubmitted: (text) => _onSearchButtomClick(), + onEditingComplete: () => _onEditingComplete(), controller: _editingController, focusNode: _focusNode, cursorColor: Colors.transparent, - style: TextStyle( - fontSize: 14, - color: HexColor.fromHex('#333333'), - textBaseline: TextBaseline.alphabetic), + style: TextStyle(fontSize: 14, color: HexColor.fromHex('#333333'), textBaseline: TextBaseline.alphabetic), decoration: InputDecoration( filled: true, isDense: true, - contentPadding: EdgeInsets.zero, + // contentPadding: EdgeInsets.zero, + contentPadding: const EdgeInsets.only(left: 0, right: 5, top: 0, bottom: 0), // contentPadding: const EdgeInsets.only(left: 0, right: 0, bottom: 12, top: 0), // focusColor: Colors.transparent, fillColor: Colors.transparent, @@ -218,10 +209,7 @@ class _SearchInputWidgetState extends State { disabledBorder: InputBorder.none, enabledBorder: InputBorder.none, hintText: model?.search_inpu_hint_text ?? '搜索更多优惠商品', - hintStyle: TextStyle( - color: HexColor.fromHex('#999999'), - fontSize: 14, - textBaseline: TextBaseline.alphabetic), + hintStyle: TextStyle(color: HexColor.fromHex('#999999'), fontSize: 14, textBaseline: TextBaseline.alphabetic), ), ), ); @@ -235,10 +223,10 @@ class _SearchInputWidgetState extends State { child: Container( padding: const EdgeInsets.symmetric(horizontal: 17.5, vertical: 6), decoration: BoxDecoration( - gradient: LinearGradient(colors: [ - HexColor.fromHex(model?.search_button_color ?? '#FD5E5E'), - HexColor.fromHex(model?.search_button_t ?? '#FF0100') - ], begin: Alignment.centerLeft, end: Alignment.centerRight), + gradient: LinearGradient( + colors: [HexColor.fromHex(model?.search_button_color ?? '#FD5E5E'), HexColor.fromHex(model?.search_button_t ?? '#FF0100')], + begin: Alignment.centerLeft, + end: Alignment.centerRight), borderRadius: BorderRadius.circular(30), ), child: Text( diff --git a/lib/widgets/search/tabbar/search_tab_widget.dart b/lib/widgets/search/tabbar/search_tab_widget.dart index 66965e2..ff1ddca 100644 --- a/lib/widgets/search/tabbar/search_tab_widget.dart +++ b/lib/widgets/search/tabbar/search_tab_widget.dart @@ -4,6 +4,7 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:cached_network_image/cached_network_image.dart'; import 'package:tab_indicator_styler/tab_indicator_styler.dart'; +import 'package:zhiying_base_widget/pages/search_page/notifier/search_tag_notifier.dart'; import 'package:zhiying_base_widget/pages/search_result_page/search_result_page.dart'; import 'package:zhiying_base_widget/pages/search_think_page/bloc/search_think_bloc.dart'; import 'package:zhiying_base_widget/pages/search_think_page/model/search_think_model.dart'; @@ -12,7 +13,7 @@ import 'package:zhiying_base_widget/widgets/search/tabbar/search_tab_sk.dart'; import 'package:zhiying_base_widget/widgets/search/widget/my_tab.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:zhiying_comm/zhiying_comm.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:provider/provider.dart'; import 'model/search_tab_model.dart'; @@ -34,9 +35,14 @@ class SearchTabWidget extends StatefulWidget { class _SearchTabWidgetState extends State { TabController _tabController; + String _type = 'taobao'; /// 联想列表的item点击事件 _onThinkItemClick(SearchThinkModel model){ + model.type = _type; + RouterUtil.hideKeyboard(context); + Provider.of(context, listen: false).addTag(model?.keywords); + BlocProvider.of(context).add(SearchThinkShowBaseViewEvent()); Navigator.push(context, CupertinoPageRoute( builder: (_)=> SearchResultPage(model.toJson()..['tag'] = 'search_page') )); @@ -46,13 +52,22 @@ class _SearchTabWidgetState extends State { void initState() { _tabController = TabController(length: widget?.model?.search_icon_list?.length ?? 0, vsync: ScrollableState())..addListener((){ - String type = ''; - try{ - type = widget.model.search_icon_list[_tabController.index].type; - }catch(_){} - if(!EmptyUtil.isEmpty(type)) { - BlocProvider.of(context).add(SearchThinkChangeTypeEvent(type)); + // String type = ''; + // try{ + // type = widget.model.search_icon_list[_tabController.index].type; + // }catch(_){} + // if(!EmptyUtil.isEmpty(type)) { + // BlocProvider.of(context).add(SearchThinkChangeTypeEvent(type)); + // } + if(!_tabController.indexIsChanging){ + Logger.log('_tabController.indexIsChanging = ${_tabController?.index}'); + try{ + _type = widget.model.search_icon_list[_tabController.index].type; + }catch(e, s){ + Logger.error(e,s); + } } + }); super.initState(); } diff --git a/lib/widgets/search_result/goods_list/bloc/search_result_goods_list_bloc.dart b/lib/widgets/search_result/goods_list/bloc/search_result_goods_list_bloc.dart index d0b8ab3..df7b299 100644 --- a/lib/widgets/search_result/goods_list/bloc/search_result_goods_list_bloc.dart +++ b/lib/widgets/search_result/goods_list/bloc/search_result_goods_list_bloc.dart @@ -82,7 +82,7 @@ class SearchResultGoodsListBloc extends Bloc get props => [this.model]; } +/// 初始化失败 +class SearchResultGoodsListInitErrorState extends SearchResultGoodsListState{} + /// 数据加载出错 class SearchResultGoodsListErrorState extends SearchResultGoodsListState {} diff --git a/lib/widgets/search_result/goods_list/search_result_goods_list_widget.dart b/lib/widgets/search_result/goods_list/search_result_goods_list_widget.dart index e5e508a..4a40efa 100644 --- a/lib/widgets/search_result/goods_list/search_result_goods_list_widget.dart +++ b/lib/widgets/search_result/goods_list/search_result_goods_list_widget.dart @@ -2,6 +2,7 @@ import 'dart:convert'; import 'package:flutter/material.dart'; import 'package:zhiying_base_widget/pages/goods_details_page/goods_details_page.dart'; +import 'package:zhiying_base_widget/widgets/empty/empty_widget.dart'; import 'package:zhiying_base_widget/widgets/home/home_goods/home_goods_item.dart'; import 'package:zhiying_base_widget/widgets/home/home_goods/home_goods_item_single.dart'; import 'package:zhiying_base_widget/widgets/home/home_goods/models/home_goods_model.dart'; @@ -98,6 +99,7 @@ class _SearchResultGoodsListWidgetContainerState extends State( builder: (context, state) { if (state is SearchResultGoodsListLoadedState) { @@ -107,7 +109,10 @@ class _SearchResultGoodsListWidgetContainerState extends State { TextEditingController _textEditingController; FocusNode _focusNode; + bool _canSearchTag = true; /// 返回事件 void _openPop() { Navigator.maybePop(context); } - /// 搜索事件 + /// 搜索框的联想 void _onSearchButtomClick() { print('搜索商品'); - String keywords = _textEditingController?.text?.toString()?.trim(); - if(!EmptyUtil.isEmpty(keywords)){ - // BlocProvider.of(context).add(SearchResultGoodsListSubmitEvent(keywords)); + RouterUtil.hideKeyboard(context); + /// 搜索 + if(!_canSearchTag){ + BlocProvider.of(context).add(SearchThinkShowBaseViewEvent()); + } + } + + /// 搜索事件 + void _onSearchInputSubmit(){ + + String text = _textEditingController?.text?.toString()?.trim(); + if(!EmptyUtil.isEmpty(text)) { + Provider.of(context, listen: false).addTag(text); + RouterUtil.hideKeyboard(context); + // TODO ❌ 如果使用咸鱼,则这里需要改成 push + Navigator.pushReplacement(context, CupertinoPageRoute( + builder: (_) => SearchResultPage({'keywords':text}), + //SearchResultPage(model.toJson()..['tag'] = 'search_page') + )); } } /// 输入变化 - // void _onChanged(String text){ - // if(!EmptyUtil.isEmpty(text)){ - // BlocProvider.of(context).add(SearchThinkKeyWrodsChangeEvent(text)); - // }else{ - // BlocProvider.of(context).add(SearchThinkShowBaseViewEvent()); - // } - // } + void _onChanged(String text){ + Logger.log('onChanged input text = $text'); + if(!EmptyUtil.isEmpty(text)){ + BlocProvider.of(context).add(SearchThinkKeyWrodsChangeEvent(text)); + }else{ + BlocProvider.of(context).add(SearchThinkShowBaseViewEvent()); + } + } + @override void initState() { _textEditingController = TextEditingController(text: widget?.model?.keywords ?? ''); - _focusNode = FocusNode(); + _focusNode = FocusNode()..addListener(() { + bool hasFocus = _focusNode?.hasFocus ?? false; + Logger.log('onInputClick input onTap = $hasFocus'); + if(hasFocus){ + String text = _textEditingController?.text?.toString()?.trim(); + if(!EmptyUtil.isEmpty(text)){ + BlocProvider.of(context).add(SearchThinkKeyWrodsChangeEvent(text)); + } + setState(() { + _canSearchTag = false; + }); + }else{ + setState(() { + _canSearchTag =true; + }); + } + }); super.initState(); } @@ -69,6 +107,7 @@ class _SearchResultInputWidgetState extends State { super.dispose(); } + @override Widget build(BuildContext context) { return Container( @@ -123,8 +162,8 @@ class _SearchResultInputWidgetState extends State { left: 10, /*right: 12.5*/ ), child: Text( - model?.search_button ?? '搜索', - style: TextStyle(fontSize: 14, color: HexColor.fromHex(model?.search_button_color), fontWeight: FontWeight.bold), + _canSearchTag ? model?.search_button ?? '搜索' : '取消', + style: TextStyle(fontSize: 14, color: HexColor.fromHex(_canSearchTag ?model?.search_button_color : '#999999'), fontWeight: _canSearchTag? FontWeight.bold : FontWeight.normal), ), ), ); @@ -143,11 +182,11 @@ class _SearchResultInputWidgetState extends State { ), padding: const EdgeInsets.only(left: 12.5, right: 12.5), child: TextField( - onTap: ()=> Navigator.maybePop(context), - // onChanged: (str) => _onChanged(str), + // onTap: ()=> _onInputClick(), + onChanged: (str) => _onChanged(str), showCursor: true, cursorWidth: 1, - onSubmitted: (text) => _onSearchButtomClick(), + onSubmitted: (text) => _onSearchInputSubmit(), controller: _textEditingController, focusNode: _focusNode, style: TextStyle(fontSize: 14, color: HexColor.fromHex('#333333'), textBaseline: TextBaseline.alphabetic), diff --git a/lib/widgets/search_result/tarbar/search_result_tab_widget.dart b/lib/widgets/search_result/tarbar/search_result_tab_widget.dart index 8926dfa..9039e6b 100644 --- a/lib/widgets/search_result/tarbar/search_result_tab_widget.dart +++ b/lib/widgets/search_result/tarbar/search_result_tab_widget.dart @@ -1,14 +1,17 @@ import 'dart:convert'; +import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:cached_network_image/cached_network_image.dart'; import 'package:tab_indicator_styler/tab_indicator_styler.dart'; +import 'package:zhiying_base_widget/pages/search_page/notifier/search_tag_notifier.dart'; +import 'package:zhiying_base_widget/pages/search_result_page/search_result_page.dart'; import 'package:zhiying_base_widget/pages/search_think_page/bloc/search_think_bloc.dart'; import 'package:zhiying_base_widget/pages/search_think_page/model/search_think_model.dart'; import 'package:zhiying_base_widget/widgets/home/home_quick_entry/cached_network_image_util.dart'; import 'package:zhiying_base_widget/widgets/search/tabbar/search_tab_sk.dart'; import 'package:zhiying_base_widget/widgets/search/widget/my_tab.dart'; -import 'package:zhiying_base_widget/widgets/search_result/sort/search_result_sort_widget.dart'; +import 'package:provider/provider.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:zhiying_comm/zhiying_comm.dart'; @@ -34,11 +37,18 @@ class SearchResultTabWidget extends StatefulWidget { class _SearchResultTabWidgetState extends State { TabController _tabController; - + String _type = 'taobao'; /// 联想点击事件 _onThinkItemClick(SearchThinkModel model){ - + model.type = _type; + RouterUtil.hideKeyboard(context); + Provider.of(context, listen: false).addTag(model?.keywords); + // TODO ❌ 如果使用咸鱼,则这里需要改成 push + Navigator.pushReplacement(context, CupertinoPageRoute( + builder: (_)=> SearchResultPage(model.toJson()..['tag'] = 'search_page') + )); + // BlocProvider.of(context).add(SearchThinkShowBaseViewEvent()); } @override @@ -49,12 +59,24 @@ class _SearchResultTabWidgetState extends State { for(int i = 0; i { // BlocProvider.of(context).add(SearchThinkChangeTypeEvent(type)); // } // }); + super.initState(); } @@ -96,6 +119,7 @@ class _SearchResultTabWidgetState extends State { crossAxisAlignment: CrossAxisAlignment.start, children: [ TabBar( + onTap: (index)=> RouterUtil.hideKeyboard(context), controller: _tabController, isScrollable: true, labelStyle: TextStyle(fontSize: 14, fontWeight: FontWeight.bold), @@ -140,21 +164,21 @@ class _SearchResultTabWidgetState extends State { /// tabBraviwe _getTabBarViewWidget(model), - // BlocConsumer( - // listener: (context, state){}, - // buildWhen: (prev, current){ - // if(current is SearchThinkErrorState){ - // return false; - // } - // return true; - // }, - // builder: (context, state){ - // if(state is SearchThinkLoadedState){ - // return _getThinkListWidget(state.model); - // } - // return Container(); - // }, - // ), + BlocConsumer( + listener: (context, state){}, + buildWhen: (prev, current){ + if(current is SearchThinkErrorState){ + return false; + } + return true; + }, + builder: (context, state){ + if(state is SearchThinkLoadedState){ + return _getThinkListWidget(state.model); + } + return Container(); + }, + ), ], ); diff --git a/lib/widgets/team/recommend/team_recommend_widget.dart b/lib/widgets/team/recommend/team_recommend_widget.dart index 1cbb204..786b62a 100644 --- a/lib/widgets/team/recommend/team_recommend_widget.dart +++ b/lib/widgets/team/recommend/team_recommend_widget.dart @@ -31,7 +31,7 @@ class _TeamRecommendWidgetContainer extends StatefulWidget { TeamDataModel dataModel; - _TeamRecommendWidgetContainer(this.styleModel, dataModel); + _TeamRecommendWidgetContainer(this.styleModel, dataModel, {Key key}) : super(key: key); @override __TeamRecommendWidgetState createState() => __TeamRecommendWidgetState();