@@ -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<List<String>> 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, ''); | |||
@@ -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<SearchHistoryTagWidget> { | |||
/// 点击历史标签 | |||
void _historyTagClick(String tag) { | |||
if (!EmptyUtil.isEmpty(tag)) { | |||
SearchThinkModel model = SearchThinkModel(); | |||
model.type = (Provider.of<SearchTagNotifier>(context, listen: false)?.getType()) ?? GlobalConfig.PROVIDER_TB; | |||
model.keywords = tag ?? ''; | |||
Provider.of<SearchTagNotifier>(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'}))); | |||
} | |||
} | |||
@@ -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<SearchTagNotifier>(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<SearchTagNotifier>(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'}))); | |||
} | |||
} | |||
@@ -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<SearchInputWidget> { | |||
if (!EmptyUtil.isEmpty(content)) { | |||
Provider.of<SearchTagNotifier>(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<SearchTagNotifier>(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: '输入内容不能为空!'); | |||
} | |||
@@ -64,6 +64,7 @@ class _SearchTabWidgetState extends State<SearchTabWidget> { | |||
Logger.log('_tabController.indexIsChanging = ${_tabController?.index}'); | |||
try{ | |||
_type = widget.model.search_icon_list[_tabController.index].type; | |||
Provider.of<SearchTagNotifier>(context, listen: false).setType(_type); | |||
}catch(e, s){ | |||
Logger.error(e,s); | |||
} | |||