浏览代码

1、键盘取消

2、搜索的页面的联想页优化
tags/0.0.1
PH2 4 年前
父节点
当前提交
8c6f4baffb
共有 19 个文件被更改,包括 234 次插入136 次删除
  1. +13
    -2
      lib/pages/search_page/notifier/search_tag_notifier.dart
  2. +5
    -2
      lib/pages/search_page/search_page.dart
  3. +25
    -23
      lib/pages/search_result_page/item/search_result_item_page.dart
  4. +19
    -12
      lib/pages/search_result_page/search_result_page.dart
  5. +3
    -2
      lib/pages/search_think_page/bloc/search_think_bloc.dart
  6. +1
    -0
      lib/widgets/home/home_goods/home_goods_item.dart
  7. +1
    -0
      lib/widgets/home/home_goods/home_goods_item_single.dart
  8. +1
    -1
      lib/widgets/mine/mine_data/mine_data_container.dart
  9. +1
    -1
      lib/widgets/mine/mine_header/mine_header_container.dart
  10. +4
    -6
      lib/widgets/search/history_tag/search_history_tag.dart
  11. +1
    -1
      lib/widgets/search/hot_tag/search_hot_tag_widget.dart
  12. +23
    -35
      lib/widgets/search/input/search_input_widget.dart
  13. +22
    -7
      lib/widgets/search/tabbar/search_tab_widget.dart
  14. +5
    -5
      lib/widgets/search_result/goods_list/bloc/search_result_goods_list_bloc.dart
  15. +3
    -0
      lib/widgets/search_result/goods_list/bloc/search_result_goods_list_state.dart
  16. +6
    -1
      lib/widgets/search_result/goods_list/search_result_goods_list_widget.dart
  17. +57
    -18
      lib/widgets/search_result/search_input/search_result_input.dart
  18. +43
    -19
      lib/widgets/search_result/tarbar/search_result_tab_widget.dart
  19. +1
    -1
      lib/widgets/team/recommend/team_recommend_widget.dart

+ 13
- 2
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]);


+ 5
- 2
lib/pages/search_page/search_page.dart 查看文件

@@ -117,8 +117,11 @@ class _SearchPageContianerState extends State<SearchPageContianer> {
Widget _getMainWidget(List<Map<String, dynamic>> datas) {
return Scaffold(
backgroundColor: Colors.white,
body: Column(
children: _createContentWidget(datas),
body: Listener(
onPointerDown: (down) => RouterUtil.hideKeyboard(context),
child: Column(
children: _createContentWidget(datas),
),
),
);
}


+ 25
- 23
lib/pages/search_result_page/item/search_result_item_page.dart 查看文件

@@ -61,7 +61,6 @@ class _SearchResultItemPageContianerState extends State<SearchResultItemPageCont
void initState() {
_refreshController = RefreshController();
_controller = ScrollController();

_controller.addListener(() {
// print('${_controller.offset} ${_controller.position.maxScrollExtent}');
if (_controller.offset >= _controller.position.maxScrollExtent && !_isEnded) {
@@ -127,31 +126,34 @@ class _SearchResultItemPageContianerState extends State<SearchResultItemPageCont
Widget _getMainWidget(List<Map<String, dynamic>> datas) {
return Scaffold(
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),
],
),
),
);
}


+ 19
- 12
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<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(),
),
);
}
}


+ 3
- 2
lib/pages/search_think_page/bloc/search_think_bloc.dart 查看文件

@@ -30,7 +30,7 @@ class SearchThinkBloc extends Bloc<SearchThinkEvent, SearchThinkState> {

/// 修改渠道关键字
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);
yield state;
}
}

+ 1
- 0
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())));
}


+ 1
- 0
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())));
}


+ 1
- 1
lib/widgets/mine/mine_data/mine_data_container.dart 查看文件

@@ -32,7 +32,7 @@ class _MineDataContainerState extends State<MineDataContainer> {
MineProfileModel profile = snapshot.data;
return profile == null
? MineDataSkeleton()
: MineDataWidget(profile, widget.data);
: MineDataWidget(profile, widget?.data);
});
}
}

+ 1
- 1
lib/widgets/mine/mine_header/mine_header_container.dart 查看文件

@@ -79,7 +79,7 @@ class _MineHeaderContainerState extends State<MineHeaderContainer> {
Row(
children: <Widget>[
Text(
profile.username,
profile?.username ?? '',
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(


+ 4
- 6
lib/widgets/search/history_tag/search_history_tag.dart 查看文件

@@ -41,6 +41,7 @@ class _SearchHistoryTagWidgetState extends State<SearchHistoryTagWidget> {
/// 点击历史标签
void _historyTagClick(String tag) {
if (!EmptyUtil.isEmpty(tag)) {
Provider.of<SearchTagNotifier>(context, listen: false).addTag(tag);
Navigator.push(context, CupertinoPageRoute(builder: (_) => SearchResultPage({'keywords': tag ?? '', 'tag': 'search_page'})));
}
}
@@ -82,10 +83,8 @@ class _SearchHistoryTagWidgetState extends State<SearchHistoryTagWidget> {

/// 点击清除所有历史记录
void _clearTag() async {
await Provider.of<SearchTagNotifier>(context, listen: false).clear();
setState(() {

});
Provider.of<SearchTagNotifier>(context, listen: false).clear();
setState(() {});
}

@override
@@ -96,8 +95,7 @@ class _SearchHistoryTagWidgetState extends State<SearchHistoryTagWidget> {

_initHistoryTag() async {
_tagList = await Provider.of<SearchTagNotifier>(context, listen: false).getHistoryTag();
setState(() {
});
setState(() {});
}

@override


+ 1
- 1
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<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'})));
}


+ 23
- 35
lib/widgets/search/input/search_input_widget.dart 查看文件

@@ -35,19 +35,18 @@ class SearchInputWidget extends StatefulWidget {
}

class _SearchInputWidgetState extends State<SearchInputWidget> {
FocusNode _focusNode;
TextEditingController _editingController;

/// 点击搜索按钮
void _onSearchButtomClick() async {
String content = _editingController?.text?.toString()?.trim() ?? '';

/// TODO 保存历史标签
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 {
Fluttertoast.showToast(msg: '输入内容不能为空!');
}
@@ -55,8 +54,7 @@ class _SearchInputWidgetState extends State<SearchInputWidget> {

/// 【弃用】打开搜索联想页面
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)) {
// 进行网络更新
print('输入框的内容是 $text');
BlocProvider.of<SearchThinkBloc>(context)
.add(SearchThinkKeyWrodsChangeEvent(text));
BlocProvider.of<SearchThinkBloc>(context).add(SearchThinkKeyWrodsChangeEvent(text));
} else {
/// 输入框为空的时候,隐藏联想视图,显示原本的视图
BlocProvider.of<SearchThinkBloc>(context)
.add(SearchThinkShowBaseViewEvent());
BlocProvider.of<SearchThinkBloc>(context).add(SearchThinkShowBaseViewEvent());
}
}

FocusNode _focusNode;
TextEditingController _editingController;
void _onEditingComplete() {
Logger.log('=======我输入完毕拉!!!!');
}

@override
void didChangeDependencies() {
@@ -110,10 +107,7 @@ class _SearchInputWidgetState extends State<SearchInputWidget> {
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: <Widget>[
/// 返回键
@@ -186,9 +180,7 @@ class _SearchInputWidgetState extends State<SearchInputWidget> {
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<SearchInputWidget> {
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<SearchInputWidget> {
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<SearchInputWidget> {
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(


+ 22
- 7
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<SearchTabWidget> {
TabController _tabController;
String _type = 'taobao';

/// 联想列表的item点击事件
_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(
builder: (_)=> SearchResultPage(model.toJson()..['tag'] = 'search_page')
));
@@ -46,13 +52,22 @@ class _SearchTabWidgetState extends State<SearchTabWidget> {
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<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();
}


+ 5
- 5
lib/widgets/search_result/goods_list/bloc/search_result_goods_list_bloc.dart 查看文件

@@ -82,7 +82,7 @@ class SearchResultGoodsListBloc extends Bloc<SearchResultGoodsListEvent, SearchR
if (!EmptyUtil.isEmpty(result)) {
yield SearchResultGoodsListLoadedState(model: result);
} else {
yield SearchResultGoodsListErrorState();
yield SearchResultGoodsListInitErrorState();
}
}

@@ -92,7 +92,7 @@ class SearchResultGoodsListBloc extends Bloc<SearchResultGoodsListEvent, SearchR
if (!EmptyUtil.isEmpty(result)) {
yield SearchResultGoodsListLoadedState(model: result);
} else {
yield SearchResultGoodsListErrorState();
// yield SearchResultGoodsListErrorState();
}
}

@@ -102,7 +102,7 @@ class SearchResultGoodsListBloc extends Bloc<SearchResultGoodsListEvent, SearchR
if (!EmptyUtil.isEmpty(result)) {
yield SearchResultGoodsListLoadedState(model: result);
} else {
yield SearchResultGoodsListErrorState();
// yield SearchResultGoodsListErrorState();
}
}

@@ -112,7 +112,7 @@ class SearchResultGoodsListBloc extends Bloc<SearchResultGoodsListEvent, SearchR
if (!EmptyUtil.isEmpty(result)) {
yield SearchResultGoodsListChangeStyleState(result['style'], result['datas']);
} else {
yield SearchResultGoodsListErrorState();
// yield SearchResultGoodsListErrorState();
}
}

@@ -132,7 +132,7 @@ class SearchResultGoodsListBloc extends Bloc<SearchResultGoodsListEvent, SearchR
if (!EmptyUtil.isEmpty(result)) {
yield SearchResultGoodsListLoadedState(model: result);
} else {
yield SearchResultGoodsListErrorState();
// yield SearchResultGoodsListErrorState();
}
}



+ 3
- 0
lib/widgets/search_result/goods_list/bloc/search_result_goods_list_state.dart 查看文件

@@ -27,6 +27,9 @@ class SearchResultGoodsListLoadedState extends SearchResultGoodsListState {
List<Object> get props => [this.model];
}

/// 初始化失败
class SearchResultGoodsListInitErrorState extends SearchResultGoodsListState{}

/// 数据加载出错
class SearchResultGoodsListErrorState extends SearchResultGoodsListState {}



+ 6
- 1
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<SearchResultGoods
// },
// );


return BlocBuilder<SearchResultGoodsListBloc, SearchResultGoodsListState>(
builder: (context, state) {
if (state is SearchResultGoodsListLoadedState) {
@@ -107,7 +109,10 @@ class _SearchResultGoodsListWidgetContainerState extends State<SearchResultGoods
_isShowOneColumn = state.isShowOneColumn;
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());
},
);
}


+ 57
- 18
lib/widgets/search_result/search_input/search_result_input.dart 查看文件

@@ -1,8 +1,11 @@
import 'dart:convert';

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/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_comm/zhiying_comm.dart';
import 'dart:ui';
@@ -30,34 +33,69 @@ class SearchResultInputWidget extends StatefulWidget {
class _SearchResultInputWidgetState extends State<SearchResultInputWidget> {
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<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
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<SearchThinkBloc>(context).add(SearchThinkKeyWrodsChangeEvent(text));
}
setState(() {
_canSearchTag = false;
});
}else{
setState(() {
_canSearchTag =true;
});
}
});
super.initState();
}

@@ -69,6 +107,7 @@ class _SearchResultInputWidgetState extends State<SearchResultInputWidget> {
super.dispose();
}


@override
Widget build(BuildContext context) {
return Container(
@@ -123,8 +162,8 @@ class _SearchResultInputWidgetState extends State<SearchResultInputWidget> {
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<SearchResultInputWidget> {
),
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),


+ 43
- 19
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<SearchResultTabWidget> {
TabController _tabController;
String _type = 'taobao';

/// 联想点击事件
_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
@@ -49,12 +59,24 @@ class _SearchResultTabWidgetState extends State<SearchResultTabWidget> {
for(int i = 0; i<length; i++){
SearchResultTabItemModel item = widget.model.search_icon_list[i];
if(item.type == widget.model.type.toString()){
_type = item.type;
initIndex = i;
break;
}
}
}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((){
// String type = '';
// try{
@@ -64,6 +86,7 @@ class _SearchResultTabWidgetState extends State<SearchResultTabWidget> {
// BlocProvider.of<SearchThinkBloc>(context).add(SearchThinkChangeTypeEvent(type));
// }
// });

super.initState();
}

@@ -96,6 +119,7 @@ class _SearchResultTabWidgetState extends State<SearchResultTabWidget> {
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
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<SearchResultTabWidget> {
/// tabBraviwe
_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();
},
),

],
);


+ 1
- 1
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();


正在加载...
取消
保存