From c6c2f923dc130d9e23674f6bb4cf4de34fe6b0bd Mon Sep 17 00:00:00 2001 From: "23028876916@qq.com" Date: Fri, 15 Jan 2021 17:46:36 +0800 Subject: [PATCH] =?UTF-8?q?0115=20=20=E6=90=9C=E7=B4=A2=E6=A1=86=E9=80=89?= =?UTF-8?q?=E6=8B=A9=E9=BB=98=E8=AE=A4tab=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../custom_page/bloc/custom_page_bloc.dart | 3 +- lib/pages/search_page/search_page.dart | 83 ++++++++++--------- .../custom/search/custom_search_widget.dart | 2 +- .../search/model/custom_search_model.dart | 4 + .../search/tabbar/search_tab_widget.dart | 5 ++ 5 files changed, 58 insertions(+), 39 deletions(-) diff --git a/lib/pages/custom_page/bloc/custom_page_bloc.dart b/lib/pages/custom_page/bloc/custom_page_bloc.dart index 32c63a6..467bcf1 100644 --- a/lib/pages/custom_page/bloc/custom_page_bloc.dart +++ b/lib/pages/custom_page/bloc/custom_page_bloc.dart @@ -1,4 +1,5 @@ import 'dart:async'; +import 'dart:convert'; import 'package:bloc/bloc.dart'; import 'custom_page_event.dart'; @@ -55,7 +56,7 @@ class CustomPageBloc extends Bloc { var result = await repository.fetchInitData(); List> mdata = result.modList; for (int i = 0; i < mdata.length; i++) { - Logger.log("页面数据: " + mdata[i].toString()); + Logger.log("页面数据: " + json.encode(mdata[i])); } if (!EmptyUtil.isEmpty(result) && result is CustomPageData) { yield CustomPageLoadedState(model: result.modList,backgroundModel: result.backgroundModel); diff --git a/lib/pages/search_page/search_page.dart b/lib/pages/search_page/search_page.dart index d80a23a..046deff 100644 --- a/lib/pages/search_page/search_page.dart +++ b/lib/pages/search_page/search_page.dart @@ -1,3 +1,5 @@ +import 'dart:convert'; + import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:zhiying_base_widget/pages/search_page/notifier/search_tag_notifier.dart'; @@ -20,14 +22,10 @@ class SearchPage extends StatelessWidget { @override Widget build(BuildContext context) { - Logger.log("数据: "+data.toString()); return MultiProvider( - providers: [ - ChangeNotifierProvider.value(value: SearchTagNotifier()) - ], + providers: [ChangeNotifierProvider.value(value: SearchTagNotifier())], child: MultiProvider( providers: [ - /// 搜索页面的bloc BlocProvider( create: (_) => SearchBloc(repository: SearchRepository())..add(SearchInitEvent(model: data)), @@ -35,11 +33,12 @@ class SearchPage extends StatelessWidget { /// 输入框联想的bloc BlocProvider( - create: (_)=> SearchThinkBloc(SearchThinkRepository()), + create: (_) => SearchThinkBloc(SearchThinkRepository()), ), - ], - child: SearchPageContianer(), + child: SearchPageContianer( + data: data, + ), ), // child: BlocProvider( // create: (_) => SearchBloc(repository: SearchRepository())..add(SearchInitEvent(model: data)), @@ -50,6 +49,10 @@ class SearchPage extends StatelessWidget { } class SearchPageContianer extends StatefulWidget { + final Map data; + + const SearchPageContianer({Key key, this.data}) : super(key: key); + @override _SearchPageContianerState createState() => _SearchPageContianerState(); } @@ -72,6 +75,12 @@ class _SearchPageContianerState extends State { @override Widget build(BuildContext context) { + //设置搜索bar应该选择哪个type的item + Logger.log("数据2: " + json.encode(widget.data)); + Logger.log("类型: " + widget.data['default_pvd']); + if(!EmptyUtil.isEmpty(widget.data['default_pvd'])){ + Provider.of(context, listen: false).setType(widget.data['default_pvd']); + } return MediaQuery.removePadding( removeTop: true, context: context, @@ -158,33 +167,33 @@ class _SearchPageContianerState extends State { return list; } - // List _createContent(BuildContext context, List> datas) { - // List list = List(); - // - // int length = datas?.length ?? 0; - // - // if (length <= 0) { - // list.add(SliverToBoxAdapter( - // child: Container( - // height: 200, - // child: Center( - // child: Text('暂时无数据哦~'), - // ), - // ), - // )); - // return list; - // } - // - // for (int i = 0; i < 3; i++) { - // WidgetModel item = WidgetModel.fromJson(Map.from(datas[i])); - // print('item.modName ${item.modName}'); - // list.addAll(WidgetFactory.create( - // item.modName, - // isSliver: true, - // model: datas[i], - // )); - // } - // - // return list; - // } +// List _createContent(BuildContext context, List> datas) { +// List list = List(); +// +// int length = datas?.length ?? 0; +// +// if (length <= 0) { +// list.add(SliverToBoxAdapter( +// child: Container( +// height: 200, +// child: Center( +// child: Text('暂时无数据哦~'), +// ), +// ), +// )); +// return list; +// } +// +// for (int i = 0; i < 3; i++) { +// WidgetModel item = WidgetModel.fromJson(Map.from(datas[i])); +// print('item.modName ${item.modName}'); +// list.addAll(WidgetFactory.create( +// item.modName, +// isSliver: true, +// model: datas[i], +// )); +// } +// +// return list; +// } } diff --git a/lib/widgets/custom/search/custom_search_widget.dart b/lib/widgets/custom/search/custom_search_widget.dart index 50ff855..19ee21f 100644 --- a/lib/widgets/custom/search/custom_search_widget.dart +++ b/lib/widgets/custom/search/custom_search_widget.dart @@ -22,7 +22,7 @@ class CustomSearchWidget extends StatelessWidget { // 点击事件 void _onClickListener(BuildContext context, SkipModel skipModel) { if (!EmptyUtil.isEmpty(skipModel)) { - RouterUtil.route(skipModel, skipModel.toJson(), context); + RouterUtil.route(skipModel, model.toJson(), context); } } diff --git a/lib/widgets/custom/search/model/custom_search_model.dart b/lib/widgets/custom/search/model/custom_search_model.dart index 4dda439..ee3d54a 100644 --- a/lib/widgets/custom/search/model/custom_search_model.dart +++ b/lib/widgets/custom/search/model/custom_search_model.dart @@ -15,6 +15,7 @@ class CustomSearchModel { String bottomLeftRadius; String bottomRightRadius; String bgColor; + String default_pvd; ListStyle listStyle; CustomSearchModel({ @@ -28,6 +29,7 @@ class CustomSearchModel { this.topMargin, this.leftRightMargin, this.bgColor, + this.default_pvd, this.listStyle, this.topLeftRadius, this.topRightRadius, @@ -46,6 +48,7 @@ class CustomSearchModel { topMargin = json['top_margin']; leftRightMargin = json['left_right_margin']; bgColor = json['bg_color']; + default_pvd=json['default_pvd']; topLeftRadius = json['top_left_radius']; topRightRadius = json['top_right_radius']; bottomLeftRadius = json['bottom_left_radius']; @@ -65,6 +68,7 @@ class CustomSearchModel { data['top_margin'] = this.topMargin; data['left_right_margin'] = this.leftRightMargin; data['bg_color'] = this.bgColor; + data['default_pvd']=this.default_pvd; data['top_left_radius'] = this.topLeftRadius; data['top_right_radius'] = this.topRightRadius; data['bottom_left_radius'] = this.bottomLeftRadius; diff --git a/lib/widgets/search/tabbar/search_tab_widget.dart b/lib/widgets/search/tabbar/search_tab_widget.dart index 8e889f6..4d48a29 100644 --- a/lib/widgets/search/tabbar/search_tab_widget.dart +++ b/lib/widgets/search/tabbar/search_tab_widget.dart @@ -68,6 +68,11 @@ class _SearchTabWidgetState extends State { } } }); + for (int i = 0; i < widget?.model?.search_icon_list?.length ?? 0; i++) { + if (Provider.of(context, listen: false).getType() == widget?.model?.search_icon_list[i].type) { + _tabController.animateTo(i); + } + } WidgetsBinding.instance.addPostFrameCallback((_) => setTabSelect()); super.initState(); }