@@ -27,14 +27,25 @@ class SearchTagNotifier with ChangeNotifier { | |||||
return _tagList; | return _tagList; | ||||
} | } | ||||
/// 添加搜索 | |||||
/// 添加搜索标签 | |||||
void addTag(String tag) async { | void addTag(String tag) async { | ||||
SharedPreferences prefs = await SharedPreferences.getInstance(); | SharedPreferences prefs = await SharedPreferences.getInstance(); | ||||
String jsonStr = prefs.getString(_SP_HOISTROY_KEY); | String jsonStr = prefs.getString(_SP_HOISTROY_KEY); | ||||
if (null != jsonStr && jsonStr.length > 0) { | if (null != jsonStr && jsonStr.length > 0) { | ||||
final Map jsonMap = jsonDecode(jsonStr); | 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); // 第一位 | _tagList.insert(0, tag); // 第一位 | ||||
if (_tagList.length > _MAX_COUNT) { | if (_tagList.length > _MAX_COUNT) { | ||||
jsonMap.remove(_tagList[_tagList.length - 1]); | jsonMap.remove(_tagList[_tagList.length - 1]); | ||||
@@ -117,8 +117,11 @@ class _SearchPageContianerState extends State<SearchPageContianer> { | |||||
Widget _getMainWidget(List<Map<String, dynamic>> datas) { | Widget _getMainWidget(List<Map<String, dynamic>> datas) { | ||||
return Scaffold( | return Scaffold( | ||||
backgroundColor: Colors.white, | backgroundColor: Colors.white, | ||||
body: Column( | |||||
children: _createContentWidget(datas), | |||||
body: Listener( | |||||
onPointerDown: (down) => RouterUtil.hideKeyboard(context), | |||||
child: Column( | |||||
children: _createContentWidget(datas), | |||||
), | |||||
), | ), | ||||
); | ); | ||||
} | } | ||||
@@ -61,7 +61,6 @@ class _SearchResultItemPageContianerState extends State<SearchResultItemPageCont | |||||
void initState() { | void initState() { | ||||
_refreshController = RefreshController(); | _refreshController = RefreshController(); | ||||
_controller = ScrollController(); | _controller = ScrollController(); | ||||
_controller.addListener(() { | _controller.addListener(() { | ||||
// print('${_controller.offset} ${_controller.position.maxScrollExtent}'); | // print('${_controller.offset} ${_controller.position.maxScrollExtent}'); | ||||
if (_controller.offset >= _controller.position.maxScrollExtent && !_isEnded) { | if (_controller.offset >= _controller.position.maxScrollExtent && !_isEnded) { | ||||
@@ -127,31 +126,34 @@ class _SearchResultItemPageContianerState extends State<SearchResultItemPageCont | |||||
Widget _getMainWidget(List<Map<String, dynamic>> datas) { | Widget _getMainWidget(List<Map<String, dynamic>> datas) { | ||||
return Scaffold( | return Scaffold( | ||||
backgroundColor: HexColor.fromHex('#F9F9F9'), | backgroundColor: HexColor.fromHex('#F9F9F9'), | ||||
body: Stack( | |||||
children: <Widget>[ | |||||
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: <Widget>[ | |||||
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), | |||||
], | |||||
), | |||||
), | ), | ||||
); | ); | ||||
} | } | ||||
@@ -1,9 +1,11 @@ | |||||
import 'package:flutter/material.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/bloc/search_result_bloc.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_bloc.dart'; | ||||
import 'package:zhiying_base_widget/pages/search_think_page/bloc/search_think_repository.dart'; | import 'package:zhiying_base_widget/pages/search_think_page/bloc/search_think_repository.dart'; | ||||
import 'package:zhiying_comm/zhiying_comm.dart'; | import 'package:zhiying_comm/zhiying_comm.dart'; | ||||
import 'package:flutter_bloc/flutter_bloc.dart'; | import 'package:flutter_bloc/flutter_bloc.dart'; | ||||
import 'package:provider/provider.dart'; | |||||
import 'bloc/search_result_repository.dart'; | import 'bloc/search_result_repository.dart'; | ||||
@@ -21,20 +23,25 @@ class SearchResultPage extends StatelessWidget { | |||||
// create: (_) => SearchResultBloc(repository: SearchResultRepository())..add(SearchResultInitEvent(model: data)), | // create: (_) => SearchResultBloc(repository: SearchResultRepository())..add(SearchResultInitEvent(model: data)), | ||||
// child: SearchResultContianer(), | // child: SearchResultContianer(), | ||||
// ); | // ); | ||||
return MultiBlocProvider( | |||||
return MultiProvider( | |||||
providers: [ | providers: [ | ||||
/// 页面的数据 | |||||
BlocProvider<SearchResultBloc>( | |||||
create: (_) => SearchResultBloc(repository: SearchResultRepository())..add(SearchResultInitEvent(model: data)), | |||||
), | |||||
/// 输入框联想的bloc | |||||
BlocProvider<SearchThinkBloc>( | |||||
create: (_)=> SearchThinkBloc(SearchThinkRepository()), | |||||
), | |||||
ChangeNotifierProvider.value(value: SearchTagNotifier()) | |||||
], | ], | ||||
child: SearchResultContianer(), | |||||
child: MultiBlocProvider( | |||||
providers: [ | |||||
/// 页面的数据 | |||||
BlocProvider<SearchResultBloc>( | |||||
create: (_) => SearchResultBloc(repository: SearchResultRepository())..add(SearchResultInitEvent(model: data)), | |||||
), | |||||
/// 输入框联想的bloc | |||||
BlocProvider<SearchThinkBloc>( | |||||
create: (_)=> SearchThinkBloc(SearchThinkRepository()), | |||||
), | |||||
], | |||||
child: SearchResultContianer(), | |||||
), | |||||
); | ); | ||||
} | } | ||||
} | } | ||||
@@ -30,7 +30,7 @@ class SearchThinkBloc extends Bloc<SearchThinkEvent, SearchThinkState> { | |||||
/// 修改渠道关键字 | /// 修改渠道关键字 | ||||
if (event is SearchThinkChangeTypeEvent) { | if (event is SearchThinkChangeTypeEvent) { | ||||
_mapChangeTypeToState(event); | |||||
_mapChangeTypeToState( state, event); | |||||
} | } | ||||
/// 显示原本的视图 | /// 显示原本的视图 | ||||
@@ -55,7 +55,8 @@ class SearchThinkBloc extends Bloc<SearchThinkEvent, SearchThinkState> { | |||||
} | } | ||||
/// 修改商品电商类型 | /// 修改商品电商类型 | ||||
_mapChangeTypeToState(SearchThinkChangeTypeEvent event) { | |||||
Stream<SearchThinkState> _mapChangeTypeToState(SearchThinkState state,SearchThinkChangeTypeEvent event) async* { | |||||
repository.changeType(event.type); | repository.changeType(event.type); | ||||
yield state; | |||||
} | } | ||||
} | } |
@@ -26,6 +26,7 @@ class HomeGoodsItem extends StatelessWidget { | |||||
/// 跳到商品详情 | /// 跳到商品详情 | ||||
void _onJumpGoodsDetails(BuildContext context, HomeGoodsModel goods) { | void _onJumpGoodsDetails(BuildContext context, HomeGoodsModel goods) { | ||||
RouterUtil.hideKeyboard(context); | |||||
Navigator.push(context, | Navigator.push(context, | ||||
CupertinoPageRoute(builder: (_) => GoodsDetailsPage(goods.toJson()))); | CupertinoPageRoute(builder: (_) => GoodsDetailsPage(goods.toJson()))); | ||||
} | } | ||||
@@ -26,6 +26,7 @@ class HomeGoodsItemSingle extends StatelessWidget { | |||||
/// 跳到商品详情 | /// 跳到商品详情 | ||||
void _onJumpGoodsDetails(BuildContext context, HomeGoodsModel goods) { | void _onJumpGoodsDetails(BuildContext context, HomeGoodsModel goods) { | ||||
RouterUtil.hideKeyboard(context); | |||||
Navigator.push(context, | Navigator.push(context, | ||||
CupertinoPageRoute(builder: (_) => GoodsDetailsPage(goods.toJson()))); | CupertinoPageRoute(builder: (_) => GoodsDetailsPage(goods.toJson()))); | ||||
} | } | ||||
@@ -32,7 +32,7 @@ class _MineDataContainerState extends State<MineDataContainer> { | |||||
MineProfileModel profile = snapshot.data; | MineProfileModel profile = snapshot.data; | ||||
return profile == null | return profile == null | ||||
? MineDataSkeleton() | ? MineDataSkeleton() | ||||
: MineDataWidget(profile, widget.data); | |||||
: MineDataWidget(profile, widget?.data); | |||||
}); | }); | ||||
} | } | ||||
} | } |
@@ -79,7 +79,7 @@ class _MineHeaderContainerState extends State<MineHeaderContainer> { | |||||
Row( | Row( | ||||
children: <Widget>[ | children: <Widget>[ | ||||
Text( | Text( | ||||
profile.username, | |||||
profile?.username ?? '', | |||||
maxLines: 1, | maxLines: 1, | ||||
overflow: TextOverflow.ellipsis, | overflow: TextOverflow.ellipsis, | ||||
style: TextStyle( | style: TextStyle( | ||||
@@ -41,6 +41,7 @@ class _SearchHistoryTagWidgetState extends State<SearchHistoryTagWidget> { | |||||
/// 点击历史标签 | /// 点击历史标签 | ||||
void _historyTagClick(String tag) { | void _historyTagClick(String tag) { | ||||
if (!EmptyUtil.isEmpty(tag)) { | if (!EmptyUtil.isEmpty(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({'keywords': tag ?? '', 'tag': 'search_page'}))); | ||||
} | } | ||||
} | } | ||||
@@ -82,10 +83,8 @@ class _SearchHistoryTagWidgetState extends State<SearchHistoryTagWidget> { | |||||
/// 点击清除所有历史记录 | /// 点击清除所有历史记录 | ||||
void _clearTag() async { | void _clearTag() async { | ||||
await Provider.of<SearchTagNotifier>(context, listen: false).clear(); | |||||
setState(() { | |||||
}); | |||||
Provider.of<SearchTagNotifier>(context, listen: false).clear(); | |||||
setState(() {}); | |||||
} | } | ||||
@override | @override | ||||
@@ -96,8 +95,7 @@ class _SearchHistoryTagWidgetState extends State<SearchHistoryTagWidget> { | |||||
_initHistoryTag() async { | _initHistoryTag() async { | ||||
_tagList = await Provider.of<SearchTagNotifier>(context, listen: false).getHistoryTag(); | _tagList = await Provider.of<SearchTagNotifier>(context, listen: false).getHistoryTag(); | ||||
setState(() { | |||||
}); | |||||
setState(() {}); | |||||
} | } | ||||
@override | @override | ||||
@@ -30,7 +30,7 @@ class SearchHotTagWidget extends StatelessWidget { | |||||
print('${model?.keyword}'); | print('${model?.keyword}'); | ||||
if (!EmptyUtil.isEmpty(model?.keyword)) { | if (!EmptyUtil.isEmpty(model?.keyword)) { | ||||
await Provider.of<SearchTagNotifier>(context, listen: false).addTag(model.keyword); | |||||
Provider.of<SearchTagNotifier>(context, listen: false).addTag(model.keyword); | |||||
Navigator.push(context, CupertinoPageRoute(builder: (_) => SearchResultPage({'keywords': model?.keyword ?? '', 'tag': 'search_page'}))); | Navigator.push(context, CupertinoPageRoute(builder: (_) => SearchResultPage({'keywords': model?.keyword ?? '', 'tag': 'search_page'}))); | ||||
} | } | ||||
@@ -35,19 +35,18 @@ class SearchInputWidget extends StatefulWidget { | |||||
} | } | ||||
class _SearchInputWidgetState extends State<SearchInputWidget> { | class _SearchInputWidgetState extends State<SearchInputWidget> { | ||||
FocusNode _focusNode; | |||||
TextEditingController _editingController; | |||||
/// 点击搜索按钮 | /// 点击搜索按钮 | ||||
void _onSearchButtomClick() async { | void _onSearchButtomClick() async { | ||||
String content = _editingController?.text?.toString()?.trim() ?? ''; | String content = _editingController?.text?.toString()?.trim() ?? ''; | ||||
/// TODO 保存历史标签 | /// TODO 保存历史标签 | ||||
if (!EmptyUtil.isEmpty(content)) { | if (!EmptyUtil.isEmpty(content)) { | ||||
await Provider.of<SearchTagNotifier>(context, listen: false) | |||||
.addTag(content); | |||||
Navigator.push( | |||||
context, | |||||
CupertinoPageRoute( | |||||
builder: (_) => SearchResultPage( | |||||
{'keywords': content, 'tag': 'search_page'}))); | |||||
Provider.of<SearchTagNotifier>(context, listen: false).addTag(content); | |||||
RouterUtil.hideKeyboard(context); | |||||
Navigator.push(context, CupertinoPageRoute(builder: (_) => SearchResultPage({'keywords': content, 'tag': 'search_page'}))); | |||||
} else { | } else { | ||||
Fluttertoast.showToast(msg: '输入内容不能为空!'); | Fluttertoast.showToast(msg: '输入内容不能为空!'); | ||||
} | } | ||||
@@ -55,8 +54,7 @@ class _SearchInputWidgetState extends State<SearchInputWidget> { | |||||
/// 【弃用】打开搜索联想页面 | /// 【弃用】打开搜索联想页面 | ||||
void _openSearchThinkPage() { | void _openSearchThinkPage() { | ||||
Navigator.push( | |||||
context, CupertinoPageRoute(builder: (_) => SearchThinkPage({}))); | |||||
Navigator.push(context, CupertinoPageRoute(builder: (_) => SearchThinkPage({}))); | |||||
} | } | ||||
/// 搜索框值改变 | /// 搜索框值改变 | ||||
@@ -64,17 +62,16 @@ class _SearchInputWidgetState extends State<SearchInputWidget> { | |||||
if (!EmptyUtil.isEmpty(text)) { | if (!EmptyUtil.isEmpty(text)) { | ||||
// 进行网络更新 | // 进行网络更新 | ||||
print('输入框的内容是 $text'); | print('输入框的内容是 $text'); | ||||
BlocProvider.of<SearchThinkBloc>(context) | |||||
.add(SearchThinkKeyWrodsChangeEvent(text)); | |||||
BlocProvider.of<SearchThinkBloc>(context).add(SearchThinkKeyWrodsChangeEvent(text)); | |||||
} else { | } else { | ||||
/// 输入框为空的时候,隐藏联想视图,显示原本的视图 | /// 输入框为空的时候,隐藏联想视图,显示原本的视图 | ||||
BlocProvider.of<SearchThinkBloc>(context) | |||||
.add(SearchThinkShowBaseViewEvent()); | |||||
BlocProvider.of<SearchThinkBloc>(context).add(SearchThinkShowBaseViewEvent()); | |||||
} | } | ||||
} | } | ||||
FocusNode _focusNode; | |||||
TextEditingController _editingController; | |||||
void _onEditingComplete() { | |||||
Logger.log('=======我输入完毕拉!!!!'); | |||||
} | |||||
@override | @override | ||||
void didChangeDependencies() { | void didChangeDependencies() { | ||||
@@ -110,10 +107,7 @@ class _SearchInputWidgetState extends State<SearchInputWidget> { | |||||
return Container( | return Container( | ||||
color: Colors.white, | color: Colors.white, | ||||
width: double.infinity, | 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( | child: Row( | ||||
children: <Widget>[ | children: <Widget>[ | ||||
/// 返回键 | /// 返回键 | ||||
@@ -186,9 +180,7 @@ class _SearchInputWidgetState extends State<SearchInputWidget> { | |||||
return Container( | return Container( | ||||
height: double.infinity, | height: double.infinity, | ||||
alignment: Alignment.centerLeft, | 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), | // padding: const EdgeInsets.symmetric(vertical: 6), | ||||
child: TextField( | child: TextField( | ||||
showCursor: true, | showCursor: true, | ||||
@@ -197,17 +189,16 @@ class _SearchInputWidgetState extends State<SearchInputWidget> { | |||||
onChanged: (val) => _searchInputChange(val), | onChanged: (val) => _searchInputChange(val), | ||||
cursorWidth: 1, | cursorWidth: 1, | ||||
onSubmitted: (text) => _onSearchButtomClick(), | onSubmitted: (text) => _onSearchButtomClick(), | ||||
onEditingComplete: () => _onEditingComplete(), | |||||
controller: _editingController, | controller: _editingController, | ||||
focusNode: _focusNode, | focusNode: _focusNode, | ||||
cursorColor: Colors.transparent, | 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( | decoration: InputDecoration( | ||||
filled: true, | filled: true, | ||||
isDense: 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), | // contentPadding: const EdgeInsets.only(left: 0, right: 0, bottom: 12, top: 0), | ||||
// focusColor: Colors.transparent, | // focusColor: Colors.transparent, | ||||
fillColor: Colors.transparent, | fillColor: Colors.transparent, | ||||
@@ -218,10 +209,7 @@ class _SearchInputWidgetState extends State<SearchInputWidget> { | |||||
disabledBorder: InputBorder.none, | disabledBorder: InputBorder.none, | ||||
enabledBorder: InputBorder.none, | enabledBorder: InputBorder.none, | ||||
hintText: model?.search_inpu_hint_text ?? '搜索更多优惠商品', | 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<SearchInputWidget> { | |||||
child: Container( | child: Container( | ||||
padding: const EdgeInsets.symmetric(horizontal: 17.5, vertical: 6), | padding: const EdgeInsets.symmetric(horizontal: 17.5, vertical: 6), | ||||
decoration: BoxDecoration( | 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), | borderRadius: BorderRadius.circular(30), | ||||
), | ), | ||||
child: Text( | child: Text( | ||||
@@ -4,6 +4,7 @@ import 'package:flutter/cupertino.dart'; | |||||
import 'package:flutter/material.dart'; | import 'package:flutter/material.dart'; | ||||
import 'package:cached_network_image/cached_network_image.dart'; | import 'package:cached_network_image/cached_network_image.dart'; | ||||
import 'package:tab_indicator_styler/tab_indicator_styler.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_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/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/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:zhiying_base_widget/widgets/search/widget/my_tab.dart'; | ||||
import 'package:flutter_bloc/flutter_bloc.dart'; | import 'package:flutter_bloc/flutter_bloc.dart'; | ||||
import 'package:zhiying_comm/zhiying_comm.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'; | import 'model/search_tab_model.dart'; | ||||
@@ -34,9 +35,14 @@ class SearchTabWidget extends StatefulWidget { | |||||
class _SearchTabWidgetState extends State<SearchTabWidget> { | class _SearchTabWidgetState extends State<SearchTabWidget> { | ||||
TabController _tabController; | TabController _tabController; | ||||
String _type = 'taobao'; | |||||
/// 联想列表的item点击事件 | /// 联想列表的item点击事件 | ||||
_onThinkItemClick(SearchThinkModel model){ | _onThinkItemClick(SearchThinkModel model){ | ||||
model.type = _type; | |||||
RouterUtil.hideKeyboard(context); | |||||
Provider.of<SearchTagNotifier>(context, listen: false).addTag(model?.keywords); | |||||
BlocProvider.of<SearchThinkBloc>(context).add(SearchThinkShowBaseViewEvent()); | |||||
Navigator.push(context, CupertinoPageRoute( | Navigator.push(context, CupertinoPageRoute( | ||||
builder: (_)=> SearchResultPage(model.toJson()..['tag'] = 'search_page') | builder: (_)=> SearchResultPage(model.toJson()..['tag'] = 'search_page') | ||||
)); | )); | ||||
@@ -46,13 +52,22 @@ class _SearchTabWidgetState extends State<SearchTabWidget> { | |||||
void initState() { | void initState() { | ||||
_tabController = TabController(length: widget?.model?.search_icon_list?.length ?? 0, vsync: ScrollableState())..addListener((){ | _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<SearchThinkBloc>(context).add(SearchThinkChangeTypeEvent(type)); | |||||
// String type = ''; | |||||
// try{ | |||||
// type = widget.model.search_icon_list[_tabController.index].type; | |||||
// }catch(_){} | |||||
// if(!EmptyUtil.isEmpty(type)) { | |||||
// BlocProvider.of<SearchThinkBloc>(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(); | super.initState(); | ||||
} | } | ||||
@@ -82,7 +82,7 @@ class SearchResultGoodsListBloc extends Bloc<SearchResultGoodsListEvent, SearchR | |||||
if (!EmptyUtil.isEmpty(result)) { | if (!EmptyUtil.isEmpty(result)) { | ||||
yield SearchResultGoodsListLoadedState(model: result); | yield SearchResultGoodsListLoadedState(model: result); | ||||
} else { | } else { | ||||
yield SearchResultGoodsListErrorState(); | |||||
yield SearchResultGoodsListInitErrorState(); | |||||
} | } | ||||
} | } | ||||
@@ -92,7 +92,7 @@ class SearchResultGoodsListBloc extends Bloc<SearchResultGoodsListEvent, SearchR | |||||
if (!EmptyUtil.isEmpty(result)) { | if (!EmptyUtil.isEmpty(result)) { | ||||
yield SearchResultGoodsListLoadedState(model: result); | yield SearchResultGoodsListLoadedState(model: result); | ||||
} else { | } else { | ||||
yield SearchResultGoodsListErrorState(); | |||||
// yield SearchResultGoodsListErrorState(); | |||||
} | } | ||||
} | } | ||||
@@ -102,7 +102,7 @@ class SearchResultGoodsListBloc extends Bloc<SearchResultGoodsListEvent, SearchR | |||||
if (!EmptyUtil.isEmpty(result)) { | if (!EmptyUtil.isEmpty(result)) { | ||||
yield SearchResultGoodsListLoadedState(model: result); | yield SearchResultGoodsListLoadedState(model: result); | ||||
} else { | } else { | ||||
yield SearchResultGoodsListErrorState(); | |||||
// yield SearchResultGoodsListErrorState(); | |||||
} | } | ||||
} | } | ||||
@@ -112,7 +112,7 @@ class SearchResultGoodsListBloc extends Bloc<SearchResultGoodsListEvent, SearchR | |||||
if (!EmptyUtil.isEmpty(result)) { | if (!EmptyUtil.isEmpty(result)) { | ||||
yield SearchResultGoodsListChangeStyleState(result['style'], result['datas']); | yield SearchResultGoodsListChangeStyleState(result['style'], result['datas']); | ||||
} else { | } else { | ||||
yield SearchResultGoodsListErrorState(); | |||||
// yield SearchResultGoodsListErrorState(); | |||||
} | } | ||||
} | } | ||||
@@ -132,7 +132,7 @@ class SearchResultGoodsListBloc extends Bloc<SearchResultGoodsListEvent, SearchR | |||||
if (!EmptyUtil.isEmpty(result)) { | if (!EmptyUtil.isEmpty(result)) { | ||||
yield SearchResultGoodsListLoadedState(model: result); | yield SearchResultGoodsListLoadedState(model: result); | ||||
} else { | } else { | ||||
yield SearchResultGoodsListErrorState(); | |||||
// yield SearchResultGoodsListErrorState(); | |||||
} | } | ||||
} | } | ||||
@@ -27,6 +27,9 @@ class SearchResultGoodsListLoadedState extends SearchResultGoodsListState { | |||||
List<Object> get props => [this.model]; | List<Object> get props => [this.model]; | ||||
} | } | ||||
/// 初始化失败 | |||||
class SearchResultGoodsListInitErrorState extends SearchResultGoodsListState{} | |||||
/// 数据加载出错 | /// 数据加载出错 | ||||
class SearchResultGoodsListErrorState extends SearchResultGoodsListState {} | class SearchResultGoodsListErrorState extends SearchResultGoodsListState {} | ||||
@@ -2,6 +2,7 @@ import 'dart:convert'; | |||||
import 'package:flutter/material.dart'; | import 'package:flutter/material.dart'; | ||||
import 'package:zhiying_base_widget/pages/goods_details_page/goods_details_page.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.dart'; | ||||
import 'package:zhiying_base_widget/widgets/home/home_goods/home_goods_item_single.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'; | import 'package:zhiying_base_widget/widgets/home/home_goods/models/home_goods_model.dart'; | ||||
@@ -98,6 +99,7 @@ class _SearchResultGoodsListWidgetContainerState extends State<SearchResultGoods | |||||
// }, | // }, | ||||
// ); | // ); | ||||
return BlocBuilder<SearchResultGoodsListBloc, SearchResultGoodsListState>( | return BlocBuilder<SearchResultGoodsListBloc, SearchResultGoodsListState>( | ||||
builder: (context, state) { | builder: (context, state) { | ||||
if (state is SearchResultGoodsListLoadedState) { | if (state is SearchResultGoodsListLoadedState) { | ||||
@@ -107,7 +109,10 @@ class _SearchResultGoodsListWidgetContainerState extends State<SearchResultGoods | |||||
_isShowOneColumn = state.isShowOneColumn; | _isShowOneColumn = state.isShowOneColumn; | ||||
return _getMainWidget(state?.model, widget?.style); | return _getMainWidget(state?.model, widget?.style); | ||||
} | } | ||||
return SliverToBoxAdapter(child: HomeGoodsSkeleton(),); | |||||
if (state is SearchResultGoodsListInitErrorState){ | |||||
return SliverPadding(padding: const EdgeInsets.only(top: 80), sliver: SliverToBoxAdapter(child: EmptyWidget())); | |||||
} | |||||
return SliverToBoxAdapter(child: HomeGoodsSkeleton()); | |||||
}, | }, | ||||
); | ); | ||||
} | } | ||||
@@ -1,8 +1,11 @@ | |||||
import 'dart:convert'; | import 'dart:convert'; | ||||
import 'package:flutter/cupertino.dart'; | |||||
import 'package:flutter/material.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/bloc/search_think_bloc.dart'; | import 'package:zhiying_base_widget/pages/search_think_page/bloc/search_think_bloc.dart'; | ||||
import 'package:zhiying_base_widget/widgets/search_result/goods_list/bloc/search_result_goods_list_bloc.dart'; | |||||
import 'package:provider/provider.dart'; | |||||
import 'package:zhiying_base_widget/widgets/search_result/search_input/model/search_result_input_model.dart'; | import 'package:zhiying_base_widget/widgets/search_result/search_input/model/search_result_input_model.dart'; | ||||
import 'package:zhiying_comm/zhiying_comm.dart'; | import 'package:zhiying_comm/zhiying_comm.dart'; | ||||
import 'dart:ui'; | import 'dart:ui'; | ||||
@@ -30,34 +33,69 @@ class SearchResultInputWidget extends StatefulWidget { | |||||
class _SearchResultInputWidgetState extends State<SearchResultInputWidget> { | class _SearchResultInputWidgetState extends State<SearchResultInputWidget> { | ||||
TextEditingController _textEditingController; | TextEditingController _textEditingController; | ||||
FocusNode _focusNode; | FocusNode _focusNode; | ||||
bool _canSearchTag = true; | |||||
/// 返回事件 | /// 返回事件 | ||||
void _openPop() { | void _openPop() { | ||||
Navigator.maybePop(context); | Navigator.maybePop(context); | ||||
} | } | ||||
/// 搜索事件 | |||||
/// 搜索框的联想 | |||||
void _onSearchButtomClick() { | void _onSearchButtomClick() { | ||||
print('搜索商品'); | print('搜索商品'); | ||||
String keywords = _textEditingController?.text?.toString()?.trim(); | |||||
if(!EmptyUtil.isEmpty(keywords)){ | |||||
// BlocProvider.of<SearchResultGoodsListBloc>(context).add(SearchResultGoodsListSubmitEvent(keywords)); | |||||
RouterUtil.hideKeyboard(context); | |||||
/// 搜索 | |||||
if(!_canSearchTag){ | |||||
BlocProvider.of<SearchThinkBloc>(context).add(SearchThinkShowBaseViewEvent()); | |||||
} | |||||
} | |||||
/// 搜索事件 | |||||
void _onSearchInputSubmit(){ | |||||
String text = _textEditingController?.text?.toString()?.trim(); | |||||
if(!EmptyUtil.isEmpty(text)) { | |||||
Provider.of<SearchTagNotifier>(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<SearchThinkBloc>(context).add(SearchThinkKeyWrodsChangeEvent(text)); | |||||
// }else{ | |||||
// BlocProvider.of<SearchThinkBloc>(context).add(SearchThinkShowBaseViewEvent()); | |||||
// } | |||||
// } | |||||
void _onChanged(String text){ | |||||
Logger.log('onChanged input text = $text'); | |||||
if(!EmptyUtil.isEmpty(text)){ | |||||
BlocProvider.of<SearchThinkBloc>(context).add(SearchThinkKeyWrodsChangeEvent(text)); | |||||
}else{ | |||||
BlocProvider.of<SearchThinkBloc>(context).add(SearchThinkShowBaseViewEvent()); | |||||
} | |||||
} | |||||
@override | @override | ||||
void initState() { | void initState() { | ||||
_textEditingController = TextEditingController(text: widget?.model?.keywords ?? ''); | _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<SearchThinkBloc>(context).add(SearchThinkKeyWrodsChangeEvent(text)); | |||||
} | |||||
setState(() { | |||||
_canSearchTag = false; | |||||
}); | |||||
}else{ | |||||
setState(() { | |||||
_canSearchTag =true; | |||||
}); | |||||
} | |||||
}); | |||||
super.initState(); | super.initState(); | ||||
} | } | ||||
@@ -69,6 +107,7 @@ class _SearchResultInputWidgetState extends State<SearchResultInputWidget> { | |||||
super.dispose(); | super.dispose(); | ||||
} | } | ||||
@override | @override | ||||
Widget build(BuildContext context) { | Widget build(BuildContext context) { | ||||
return Container( | return Container( | ||||
@@ -123,8 +162,8 @@ class _SearchResultInputWidgetState extends State<SearchResultInputWidget> { | |||||
left: 10, /*right: 12.5*/ | left: 10, /*right: 12.5*/ | ||||
), | ), | ||||
child: Text( | 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<SearchResultInputWidget> { | |||||
), | ), | ||||
padding: const EdgeInsets.only(left: 12.5, right: 12.5), | padding: const EdgeInsets.only(left: 12.5, right: 12.5), | ||||
child: TextField( | child: TextField( | ||||
onTap: ()=> Navigator.maybePop(context), | |||||
// onChanged: (str) => _onChanged(str), | |||||
// onTap: ()=> _onInputClick(), | |||||
onChanged: (str) => _onChanged(str), | |||||
showCursor: true, | showCursor: true, | ||||
cursorWidth: 1, | cursorWidth: 1, | ||||
onSubmitted: (text) => _onSearchButtomClick(), | |||||
onSubmitted: (text) => _onSearchInputSubmit(), | |||||
controller: _textEditingController, | controller: _textEditingController, | ||||
focusNode: _focusNode, | focusNode: _focusNode, | ||||
style: TextStyle(fontSize: 14, color: HexColor.fromHex('#333333'), textBaseline: TextBaseline.alphabetic), | style: TextStyle(fontSize: 14, color: HexColor.fromHex('#333333'), textBaseline: TextBaseline.alphabetic), | ||||
@@ -1,14 +1,17 @@ | |||||
import 'dart:convert'; | import 'dart:convert'; | ||||
import 'package:flutter/cupertino.dart'; | |||||
import 'package:flutter/material.dart'; | import 'package:flutter/material.dart'; | ||||
import 'package:cached_network_image/cached_network_image.dart'; | import 'package:cached_network_image/cached_network_image.dart'; | ||||
import 'package:tab_indicator_styler/tab_indicator_styler.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/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/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/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/tabbar/search_tab_sk.dart'; | ||||
import 'package:zhiying_base_widget/widgets/search/widget/my_tab.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:flutter_bloc/flutter_bloc.dart'; | ||||
import 'package:zhiying_comm/zhiying_comm.dart'; | import 'package:zhiying_comm/zhiying_comm.dart'; | ||||
@@ -34,11 +37,18 @@ class SearchResultTabWidget extends StatefulWidget { | |||||
class _SearchResultTabWidgetState extends State<SearchResultTabWidget> { | class _SearchResultTabWidgetState extends State<SearchResultTabWidget> { | ||||
TabController _tabController; | TabController _tabController; | ||||
String _type = 'taobao'; | |||||
/// 联想点击事件 | /// 联想点击事件 | ||||
_onThinkItemClick(SearchThinkModel model){ | _onThinkItemClick(SearchThinkModel model){ | ||||
model.type = _type; | |||||
RouterUtil.hideKeyboard(context); | |||||
Provider.of<SearchTagNotifier>(context, listen: false).addTag(model?.keywords); | |||||
// TODO ❌ 如果使用咸鱼,则这里需要改成 push | |||||
Navigator.pushReplacement(context, CupertinoPageRoute( | |||||
builder: (_)=> SearchResultPage(model.toJson()..['tag'] = 'search_page') | |||||
)); | |||||
// BlocProvider.of<SearchThinkBloc>(context).add(SearchThinkShowBaseViewEvent()); | |||||
} | } | ||||
@override | @override | ||||
@@ -49,12 +59,24 @@ class _SearchResultTabWidgetState extends State<SearchResultTabWidget> { | |||||
for(int i = 0; i<length; i++){ | for(int i = 0; i<length; i++){ | ||||
SearchResultTabItemModel item = widget.model.search_icon_list[i]; | SearchResultTabItemModel item = widget.model.search_icon_list[i]; | ||||
if(item.type == widget.model.type.toString()){ | if(item.type == widget.model.type.toString()){ | ||||
_type = item.type; | |||||
initIndex = i; | initIndex = i; | ||||
break; | break; | ||||
} | } | ||||
} | } | ||||
}catch(_){} | }catch(_){} | ||||
_tabController = TabController(length: length, vsync: ScrollableState(), initialIndex: initIndex); | |||||
_tabController = TabController(length: length, vsync: ScrollableState(), initialIndex: initIndex) | |||||
..addListener(() { | |||||
try{ | |||||
if(!_tabController.indexIsChanging) { | |||||
_type = widget.model.search_icon_list[_tabController.index].type; | |||||
} | |||||
}catch(e, s){ | |||||
Logger.error(e, s); | |||||
} | |||||
}); | |||||
// ..addListener((){ | // ..addListener((){ | ||||
// String type = ''; | // String type = ''; | ||||
// try{ | // try{ | ||||
@@ -64,6 +86,7 @@ class _SearchResultTabWidgetState extends State<SearchResultTabWidget> { | |||||
// BlocProvider.of<SearchThinkBloc>(context).add(SearchThinkChangeTypeEvent(type)); | // BlocProvider.of<SearchThinkBloc>(context).add(SearchThinkChangeTypeEvent(type)); | ||||
// } | // } | ||||
// }); | // }); | ||||
super.initState(); | super.initState(); | ||||
} | } | ||||
@@ -96,6 +119,7 @@ class _SearchResultTabWidgetState extends State<SearchResultTabWidget> { | |||||
crossAxisAlignment: CrossAxisAlignment.start, | crossAxisAlignment: CrossAxisAlignment.start, | ||||
children: <Widget>[ | children: <Widget>[ | ||||
TabBar( | TabBar( | ||||
onTap: (index)=> RouterUtil.hideKeyboard(context), | |||||
controller: _tabController, | controller: _tabController, | ||||
isScrollable: true, | isScrollable: true, | ||||
labelStyle: TextStyle(fontSize: 14, fontWeight: FontWeight.bold), | labelStyle: TextStyle(fontSize: 14, fontWeight: FontWeight.bold), | ||||
@@ -140,21 +164,21 @@ class _SearchResultTabWidgetState extends State<SearchResultTabWidget> { | |||||
/// tabBraviwe | /// tabBraviwe | ||||
_getTabBarViewWidget(model), | _getTabBarViewWidget(model), | ||||
// BlocConsumer<SearchThinkBloc, SearchThinkState>( | |||||
// 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<SearchThinkBloc, SearchThinkState>( | |||||
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(); | |||||
}, | |||||
), | |||||
], | ], | ||||
); | ); | ||||
@@ -31,7 +31,7 @@ class _TeamRecommendWidgetContainer extends StatefulWidget { | |||||
TeamDataModel dataModel; | TeamDataModel dataModel; | ||||
_TeamRecommendWidgetContainer(this.styleModel, dataModel); | |||||
_TeamRecommendWidgetContainer(this.styleModel, dataModel, {Key key}) : super(key: key); | |||||
@override | @override | ||||
__TeamRecommendWidgetState createState() => __TeamRecommendWidgetState(); | __TeamRecommendWidgetState createState() => __TeamRecommendWidgetState(); | ||||