@@ -4,20 +4,30 @@ import 'package:zhiying_comm/util/log/let_log.dart'; | |||||
class TeamPageNotifier with ChangeNotifier { | class TeamPageNotifier with ChangeNotifier { | ||||
/// taBar选中的index | /// taBar选中的index | ||||
int tabSelectIndex = 0; | int tabSelectIndex = 0; | ||||
bool isSearch = false; | |||||
String keyword; | |||||
/// 筛选的条件 | /// 筛选的条件 | ||||
Map<String, String> reqArgs = {}; | Map<String, String> reqArgs = {}; | ||||
/// 更新筛选条件 | /// 更新筛选条件 | ||||
void updateSortCondition(String key, String args) { | void updateSortCondition(String key, String args) { | ||||
reqArgs[key] = args; | |||||
Logger.log('updateSortCondition reqArgs = ${reqArgs?.toString()}'); | |||||
this.isSearch = false; | |||||
this.reqArgs[key] = args; | |||||
notifyListeners(); | |||||
} | |||||
/// 重置 | |||||
void searchReset(String keyword) { | |||||
this.isSearch = true; | |||||
this.keyword = keyword; | |||||
this.reqArgs.clear(); | |||||
notifyListeners(); | notifyListeners(); | ||||
} | } | ||||
/// 更新选中Index | /// 更新选中Index | ||||
void updateTabIndex(int index) { | void updateTabIndex(int index) { | ||||
print('111111'); | |||||
isSearch = false; | |||||
this.tabSelectIndex = index; | this.tabSelectIndex = index; | ||||
} | } | ||||
@@ -30,4 +40,13 @@ class TeamPageNotifier with ChangeNotifier { | |||||
int getTabIndex() { | int getTabIndex() { | ||||
return this.tabSelectIndex; | return this.tabSelectIndex; | ||||
} | } | ||||
/// 获取搜索关键字 | |||||
String getKeyword(){ | |||||
return this.keyword; | |||||
} | |||||
/// 获取是否是搜索方式 | |||||
bool getSearch() { | |||||
return this.isSearch; | |||||
} | |||||
} | } |
@@ -127,7 +127,7 @@ class _TeamPageContainerState extends State<_TeamPageContainer> { | |||||
SliverToBoxAdapter(child: SizedBox(height: 8)), | SliverToBoxAdapter(child: SizedBox(height: 8)), | ||||
/// 输入框 | /// 输入框 | ||||
SliverPersistentHeader(delegate: CustomSliverPersistentHeaderDelegate(min: 34, max: 34, child: TeamInputWidget(styleModel)), pinned: true), | |||||
SliverPersistentHeader(delegate: CustomSliverPersistentHeaderDelegate(min: 34, max: 34, child: TeamInputWidget(styleModel, _controller)), pinned: true), | |||||
/// 悬停TabBar | /// 悬停TabBar | ||||
SliverPersistentHeader( | SliverPersistentHeader( | ||||
@@ -50,6 +50,12 @@ class TeamListFansBloc extends Bloc<TeamListFansEvent, TeamListFansState> { | |||||
if (event is TeamListFansFilterEvent) { | if (event is TeamListFansFilterEvent) { | ||||
yield* _mapFilterEventToState(event); | yield* _mapFilterEventToState(event); | ||||
} | } | ||||
/// 搜索 | |||||
if(event is TeamListFansSearchEvent){ | |||||
yield* _mapSearchEventToState(event); | |||||
} | |||||
} | } | ||||
/// 初始化 | /// 初始化 | ||||
@@ -103,4 +109,15 @@ class TeamListFansBloc extends Bloc<TeamListFansEvent, TeamListFansState> { | |||||
yield TeamListFansErrorState(); | yield TeamListFansErrorState(); | ||||
} | } | ||||
} | } | ||||
/// 搜索 | |||||
Stream<TeamListFansState> _mapSearchEventToState(TeamListFansSearchEvent event) async*{ | |||||
var result = await repository.fetchSearchData(event?.keyword); | |||||
if (!EmptyUtil.isEmpty(result)) { | |||||
yield TeamListFansLoadedState(model: result); | |||||
} else { | |||||
yield TeamListFansErrorState(); | |||||
} | |||||
} | |||||
} | } |
@@ -40,4 +40,12 @@ class TeamListFansFilterEvent extends TeamListFansEvent{ | |||||
const TeamListFansFilterEvent({@required this.args}); | const TeamListFansFilterEvent({@required this.args}); | ||||
@override | @override | ||||
List<Object> get props => [this.args]; | List<Object> get props => [this.args]; | ||||
} | |||||
/// 搜索 | |||||
class TeamListFansSearchEvent extends TeamListFansEvent{ | |||||
final String keyword; | |||||
TeamListFansSearchEvent(this.keyword); | |||||
@override | |||||
List<Object> get props => [this.keyword]; | |||||
} | } |
@@ -16,6 +16,24 @@ class TeamListFansRepository { | |||||
TeamListFansRepository({this.type = 'all'}); | TeamListFansRepository({this.type = 'all'}); | ||||
/// 搜索对方法 | |||||
Future<TeamFansListModel> fetchSearchData(String keyword) async { | |||||
try { | |||||
if (!EmptyUtil.isEmpty(keyword)) { | |||||
var result = await NetUtil.post('/api/v1/user/fans/search', params: {'keyword': keyword}, method: NetMethod.POST); | |||||
if (NetUtil.isSuccess(result) && !EmptyUtil.isEmpty(result[GlobalConfig.HTTP_RESPONSE_KEY_DATA])) { | |||||
TeamFansListModel model = TeamFansListModel.fromJson(result[GlobalConfig.HTTP_RESPONSE_KEY_DATA]); | |||||
if (null != model && !EmptyUtil.isEmpty(model?.fans) && model.fans.length > 0) { | |||||
return model; | |||||
} | |||||
} | |||||
} | |||||
} catch (e, s) { | |||||
Logger.error(e, s); | |||||
} | |||||
return null; | |||||
} | |||||
/// 初始化方法 | /// 初始化方法 | ||||
Future<TeamFansListModel> fetchInitData() async { | Future<TeamFansListModel> fetchInitData() async { | ||||
_currentPage = 1; | _currentPage = 1; | ||||
@@ -49,8 +67,8 @@ class TeamListFansRepository { | |||||
} | } | ||||
/// 整体筛选排序的方法 | /// 整体筛选排序的方法 | ||||
Future<TeamFansListModel> fetchFilter(final Map<String ,String > reqArgs) async{ | |||||
if(!EmptyUtil.isEmpty(reqArgs)) { | |||||
Future<TeamFansListModel> fetchFilter(final Map<String, String> reqArgs) async { | |||||
if (!EmptyUtil.isEmpty(reqArgs)) { | |||||
_reqArgs = reqArgs; | _reqArgs = reqArgs; | ||||
return fetchInitData(); | return fetchInitData(); | ||||
} | } | ||||
@@ -102,7 +120,7 @@ class TeamListFansRepository { | |||||
_reqArgs.forEach((key, value) { | _reqArgs.forEach((key, value) { | ||||
// sb.write(key); | // sb.write(key); | ||||
// sb.write('='); | // sb.write('='); | ||||
if(!EmptyUtil.isEmpty(value)) { | |||||
if (!EmptyUtil.isEmpty(value)) { | |||||
sb.write(value); | sb.write(value); | ||||
sb.write('&'); | sb.write('&'); | ||||
} | } | ||||
@@ -78,11 +78,19 @@ class __TeamFansWidgetContainerState extends State<_TeamFansWidgetContainer> { | |||||
TeamPageNotifier notifier = Provider.of<TeamPageNotifier>(context); | TeamPageNotifier notifier = Provider.of<TeamPageNotifier>(context); | ||||
if (null != notifier) { | if (null != notifier) { | ||||
tabSelectIndex = notifier?.getTabIndex() ?? 0; | tabSelectIndex = notifier?.getTabIndex() ?? 0; | ||||
Map<String, String> reqArgs = notifier?.getReqArgs() ?? null; | |||||
if (widget.tabCurrentIndex == tabSelectIndex && !EmptyUtil.isEmpty(reqArgs)) { | |||||
Logger.log('didChangeDependencies, currentTabIndex = ${widget?.tabCurrentIndex}, tabSelectIndex = $tabSelectIndex , reqArgs = ${reqArgs?.toString()}'); | |||||
// _refreshController.refreshToIdle(); | |||||
BlocProvider.of<TeamListFansBloc>(context).add(TeamListFansFilterEvent(args: reqArgs)); | |||||
bool isSearch = notifier?.getSearch() ?? false; | |||||
Logger.log('isSearch ==== $isSearch'); | |||||
/// 如果是搜索框 | |||||
if(isSearch){ | |||||
BlocProvider.of<TeamListFansBloc>(context).add(TeamListFansSearchEvent(notifier?.getKeyword())); | |||||
}else { | |||||
Map<String, String> reqArgs = notifier?.getReqArgs() ?? null; | |||||
if (widget.tabCurrentIndex == tabSelectIndex && !EmptyUtil.isEmpty(reqArgs)) { | |||||
Logger.log('didChangeDependencies, currentTabIndex = ${widget?.tabCurrentIndex}, tabSelectIndex = $tabSelectIndex , reqArgs = ${reqArgs?.toString()}'); | |||||
// _refreshController.refreshToIdle(); | |||||
BlocProvider.of<TeamListFansBloc>(context).add(TeamListFansFilterEvent(args: reqArgs)); | |||||
} | |||||
} | } | ||||
} | } | ||||
super.didChangeDependencies(); | super.didChangeDependencies(); | ||||
@@ -43,6 +43,26 @@ class _TeamFilterWidgetState extends State<TeamFilterWidget> { | |||||
setState(() {}); | setState(() {}); | ||||
} | } | ||||
@override | |||||
void didChangeDependencies() { | |||||
super.didChangeDependencies(); | |||||
try { | |||||
TeamPageNotifier notifier = Provider.of<TeamPageNotifier>(context); | |||||
if (null != notifier) { | |||||
bool needRebuild = notifier?.getSearch()?? false; | |||||
if(needRebuild){ | |||||
widget.styleModel.teamViewSortList.forEach((element) { | |||||
element.selectState = 0; | |||||
}); | |||||
setState(() {}); | |||||
} | |||||
} | |||||
}catch(e, s){ | |||||
Logger.error(e, s); | |||||
} | |||||
} | |||||
@override | @override | ||||
Widget build(BuildContext context) { | Widget build(BuildContext context) { | ||||
return Container( | return Container( | ||||
@@ -1,12 +1,15 @@ | |||||
import 'package:flutter/material.dart'; | import 'package:flutter/material.dart'; | ||||
import 'package:zhiying_base_widget/pages/team_page/model/team_style_model.dart'; | import 'package:zhiying_base_widget/pages/team_page/model/team_style_model.dart'; | ||||
import 'package:cached_network_image/cached_network_image.dart'; | import 'package:cached_network_image/cached_network_image.dart'; | ||||
import 'package:zhiying_base_widget/pages/team_page/notifier/team_page_notifier.dart'; | |||||
import 'package:zhiying_comm/zhiying_comm.dart'; | import 'package:zhiying_comm/zhiying_comm.dart'; | ||||
import 'package:provider/provider.dart'; | |||||
class TeamInputWidget extends StatefulWidget { | class TeamInputWidget extends StatefulWidget { | ||||
TeamStyleModel styleModel; | TeamStyleModel styleModel; | ||||
TabController tabController; | |||||
TeamInputWidget(this.styleModel); | |||||
TeamInputWidget(this.styleModel, this.tabController); | |||||
@override | @override | ||||
_TeamInputWidgetState createState() => _TeamInputWidgetState(); | _TeamInputWidgetState createState() => _TeamInputWidgetState(); | ||||
@@ -18,22 +21,28 @@ class _TeamInputWidgetState extends State<TeamInputWidget> { | |||||
bool _showCancel = false; | bool _showCancel = false; | ||||
/// 搜索方法 | /// 搜索方法 | ||||
void _onSearchClick() {} | |||||
void _onSearchClick() { | |||||
String text = _controller?.text?.toString()?.trim(); | |||||
if (!EmptyUtil.isEmpty(text) && text.length > 0) { | |||||
widget?.tabController?.index = 0; | |||||
Provider.of<TeamPageNotifier>(context, listen: false).searchReset(text); | |||||
} | |||||
} | |||||
/// 点击取消输入 | /// 点击取消输入 | ||||
void _cancel() { | void _cancel() { | ||||
_controller?.clear(); | _controller?.clear(); | ||||
} | } | ||||
void _onChange(text){ | |||||
if(!EmptyUtil.isEmpty(text)){ | |||||
if(!_showCancel){ | |||||
void _onChange(text) { | |||||
if (!EmptyUtil.isEmpty(text)) { | |||||
if (!_showCancel) { | |||||
setState(() { | setState(() { | ||||
_showCancel = true; | _showCancel = true; | ||||
}); | }); | ||||
} | } | ||||
}else{ | |||||
if(_showCancel) { | |||||
} else { | |||||
if (_showCancel) { | |||||
setState(() { | setState(() { | ||||
_showCancel = false; | _showCancel = false; | ||||
}); | }); | ||||
@@ -105,6 +114,7 @@ class _TeamInputWidgetState extends State<TeamInputWidget> { | |||||
controller: _controller, | controller: _controller, | ||||
focusNode: _focusNode, | focusNode: _focusNode, | ||||
onChanged: _onChange, | onChanged: _onChange, | ||||
onSubmitted: (text) => _onSearchClick(), | |||||
style: TextStyle(fontSize: 11, color: HexColor.fromHex(widget?.styleModel?.headerNoReferrerInputColor ?? '#000000'), textBaseline: TextBaseline.alphabetic), | style: TextStyle(fontSize: 11, color: HexColor.fromHex(widget?.styleModel?.headerNoReferrerInputColor ?? '#000000'), textBaseline: TextBaseline.alphabetic), | ||||
decoration: InputDecoration( | decoration: InputDecoration( | ||||
focusedBorder: InputBorder.none, | focusedBorder: InputBorder.none, | ||||