diff --git a/lib/pages/search_page/notifier/search_tag_notifier.dart b/lib/pages/search_page/notifier/search_tag_notifier.dart index 2355800..f3374e5 100644 --- a/lib/pages/search_page/notifier/search_tag_notifier.dart +++ b/lib/pages/search_page/notifier/search_tag_notifier.dart @@ -2,6 +2,7 @@ import 'dart:convert'; import 'package:flutter/material.dart'; import 'package:shared_preferences/shared_preferences.dart'; +import 'package:zhiying_comm/zhiying_comm.dart'; class SearchTagNotifier with ChangeNotifier { ///文本标签集合 @@ -13,6 +14,16 @@ class SearchTagNotifier with ChangeNotifier { /// 最大存储条数 static final int _MAX_COUNT = 10; + String _type = GlobalConfig.PROVIDER_TB; + + setType(String type) { + _type = type; + } + + String getType() { + return _type; + } + /// 初始化历史搜索标签 Future> getHistoryTag() async { SharedPreferences prefs = await SharedPreferences.getInstance(); @@ -34,11 +45,11 @@ class SearchTagNotifier with ChangeNotifier { if (null != jsonStr && jsonStr.length > 0) { final Map jsonMap = jsonDecode(jsonStr); - if(jsonMap.containsKey(tag)){ - if(_tagList.length > 0) { + if (jsonMap.containsKey(tag)) { + if (_tagList.length > 0) { int lastIndex = 0; for (int i = 0; i < _tagList.length; i++) { - if(tag == _tagList[i]){ + if (tag == _tagList[i]) { lastIndex = i; } } @@ -61,7 +72,7 @@ class SearchTagNotifier with ChangeNotifier { } /// 请空 - void clear() async{ + void clear() async { SharedPreferences prefs = await SharedPreferences.getInstance(); // String jsonStr = prefs.getString(_SP_HOISTROY_KEY); prefs.setString(_SP_HOISTROY_KEY, ''); diff --git a/lib/widgets/search/history_tag/search_history_tag.dart b/lib/widgets/search/history_tag/search_history_tag.dart index ac22cff..08f7349 100644 --- a/lib/widgets/search/history_tag/search_history_tag.dart +++ b/lib/widgets/search/history_tag/search_history_tag.dart @@ -5,6 +5,7 @@ import 'package:flutter/material.dart'; import 'package:shared_preferences/shared_preferences.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/model/search_think_model.dart'; import 'package:zhiying_base_widget/widgets/search/history_tag/model/search_history_model.dart'; import 'package:zhiying_base_widget/widgets/search/widget/text_tag_widget.dart'; import 'package:zhiying_base_widget/widgets/search/widget/title_widget.dart'; @@ -41,8 +42,14 @@ class _SearchHistoryTagWidgetState extends State { /// 点击历史标签 void _historyTagClick(String tag) { if (!EmptyUtil.isEmpty(tag)) { + SearchThinkModel model = SearchThinkModel(); + model.type = (Provider.of(context, listen: false)?.getType()) ?? GlobalConfig.PROVIDER_TB; + model.keywords = tag ?? ''; Provider.of(context, listen: false).addTag(tag); - Navigator.push(context, CupertinoPageRoute(builder: (_) => SearchResultPage({'keywords': tag ?? '', 'tag': 'search_page'}))); + Navigator.push( + context, CupertinoPageRoute(builder: (_) => SearchResultPage(model.toJson()..['tag'] = 'search_page'))); + // Navigator.push( + // context, CupertinoPageRoute(builder: (_) => SearchResultPage({'keywords': tag ?? '', 'tag': 'search_page'}))); } } 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 0e57a6f..5705d39 100644 --- a/lib/widgets/search/hot_tag/search_hot_tag_widget.dart +++ b/lib/widgets/search/hot_tag/search_hot_tag_widget.dart @@ -4,6 +4,7 @@ import 'package:flutter/cupertino.dart'; 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/search_result_page.dart'; +import 'package:zhiying_base_widget/pages/search_think_page/model/search_think_model.dart'; import 'package:zhiying_base_widget/widgets/search/hot_tag/model/search_hot_tag_model.dart'; import 'package:zhiying_base_widget/widgets/search/widget/text_tag_widget.dart'; import 'package:zhiying_base_widget/widgets/search/widget/title_widget.dart'; @@ -26,13 +27,18 @@ class SearchHotTagWidget extends StatelessWidget { } /// 点击事件 - void _tagOnClick(BuildContext context, SearchHostTagItemModel model) async{ + void _tagOnClick(BuildContext context, SearchHostTagItemModel model) async { print('${model?.keyword}'); if (!EmptyUtil.isEmpty(model?.keyword)) { Provider.of(context, listen: false).addTag(model.keyword); - Navigator.push(context, CupertinoPageRoute(builder: (_) => SearchResultPage({'keywords': model?.keyword ?? '', 'tag': 'search_page'}))); + SearchThinkModel searchThinkModel = SearchThinkModel(); + searchThinkModel.type = (Provider.of(context, listen: false)?.getType()) ?? GlobalConfig.PROVIDER_TB; + searchThinkModel.keywords = model?.keyword ?? ''; + Navigator.push( + context, CupertinoPageRoute(builder: (_) => SearchResultPage(searchThinkModel.toJson()..['tag'] = 'search_page'))); + // 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 a3dbb80..606c211 100644 --- a/lib/widgets/search/input/search_input_widget.dart +++ b/lib/widgets/search/input/search_input_widget.dart @@ -10,6 +10,7 @@ import 'package:provider/provider.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/pages/search_think_page/search_think_page.dart'; import 'package:zhiying_base_widget/widgets/search/input/model/search_input_model.dart'; import 'package:zhiying_base_widget/widgets/search/input/search_input_sk.dart'; @@ -46,7 +47,13 @@ class _SearchInputWidgetState extends State { if (!EmptyUtil.isEmpty(content)) { Provider.of(context, listen: false).addTag(content); RouterUtil.hideKeyboard(context); - Navigator.push(context, CupertinoPageRoute(builder: (_) => SearchResultPage({'keywords': content, 'tag': 'search_page'}))); + SearchThinkModel searchThinkModel = SearchThinkModel(); + searchThinkModel.type = (Provider.of(context, listen: false)?.getType()) ?? GlobalConfig.PROVIDER_TB; + searchThinkModel.keywords = content ?? ''; + Navigator.push( + context, CupertinoPageRoute(builder: (_) => SearchResultPage(searchThinkModel.toJson()..['tag'] = 'search_page'))); + + // Navigator.push(context, CupertinoPageRoute(builder: (_) => SearchResultPage({'keywords': content, 'tag': 'search_page'}))); } else { Fluttertoast.showToast(msg: '输入内容不能为空!'); } diff --git a/lib/widgets/search/tabbar/search_tab_widget.dart b/lib/widgets/search/tabbar/search_tab_widget.dart index 026c7b6..6176a0a 100644 --- a/lib/widgets/search/tabbar/search_tab_widget.dart +++ b/lib/widgets/search/tabbar/search_tab_widget.dart @@ -64,6 +64,7 @@ class _SearchTabWidgetState extends State { Logger.log('_tabController.indexIsChanging = ${_tabController?.index}'); try{ _type = widget.model.search_icon_list[_tabController.index].type; + Provider.of(context, listen: false).setType(_type); }catch(e, s){ Logger.error(e,s); }