diff --git a/lib/pages/custom_page/bloc/custom_page_bloc.dart b/lib/pages/custom_page/bloc/custom_page_bloc.dart index b81f058..32c63a6 100644 --- a/lib/pages/custom_page/bloc/custom_page_bloc.dart +++ b/lib/pages/custom_page/bloc/custom_page_bloc.dart @@ -37,7 +37,7 @@ class CustomPageBloc extends Bloc { var result = await repository.fetchInitData(); if (!EmptyUtil.isEmpty(result)) { yield CustomPageRefreshSuccessState(); - yield CustomPageLoadedState(model: result); + yield CustomPageLoadedState(model: result.modList,backgroundModel: result.backgroundModel); } else { yield CustomPageRefreshErrorState(); yield CustomPageErrorState(); @@ -48,17 +48,17 @@ class CustomPageBloc extends Bloc { Stream _mapInitToState(CustomPageInitEvent event) async* { // 获取缓存数据 var cache = await repository.fetchCacheData(); - if (!EmptyUtil.isEmpty(cache) && cache is List) { - yield CustomPageLoadedState(model: cache); + if (!EmptyUtil.isEmpty(cache) && cache is CustomPageData) { + yield CustomPageLoadedState(model: cache.modList,backgroundModel: cache.backgroundModel); } // 获取网络数据 var result = await repository.fetchInitData(); - List> mdata = result; + List> mdata = result.modList; for (int i = 0; i < mdata.length; i++) { Logger.log("页面数据: " + mdata[i].toString()); } - if (!EmptyUtil.isEmpty(result) && result is List) { - yield CustomPageLoadedState(model: result); + if (!EmptyUtil.isEmpty(result) && result is CustomPageData) { + yield CustomPageLoadedState(model: result.modList,backgroundModel: result.backgroundModel); } else { if (EmptyUtil.isEmpty(cache)) { yield CustomPageInitErrorState(); diff --git a/lib/pages/custom_page/bloc/custom_page_repository.dart b/lib/pages/custom_page/bloc/custom_page_repository.dart index c6db1be..c729484 100644 --- a/lib/pages/custom_page/bloc/custom_page_repository.dart +++ b/lib/pages/custom_page/bloc/custom_page_repository.dart @@ -1,3 +1,6 @@ +import 'dart:convert'; + +import 'package:zhiying_base_widget/pages/main_page/model/background_model.dart'; import 'package:zhiying_comm/zhiying_comm.dart'; class CustomPageRepository { @@ -6,7 +9,8 @@ class CustomPageRepository { CustomPageRepository({this.data}); /// 初始化 - Future>> fetchInitData() async { + Future fetchInitData() async { + CustomPageData customPageData=CustomPageData(); try { String skipIdentifier = !EmptyUtil.isEmpty(data) && data.containsKey(GlobalConfig.SKIP_IDENTIFIER) && !EmptyUtil.isEmpty(data[GlobalConfig.SKIP_IDENTIFIER]) ? data[GlobalConfig.SKIP_IDENTIFIER] : null; @@ -16,7 +20,11 @@ class CustomPageRepository { if (NetUtil.isSuccess(result) && !EmptyUtil.isEmpty(result[GlobalConfig.HTTP_RESPONSE_KEY_DATA])) { List mobList = List.from(result[GlobalConfig.HTTP_RESPONSE_KEY_DATA]['mod_list']); if (!EmptyUtil.isEmpty(mobList)) { - return mobList.map((e) => Map.from(e)).toList(); + customPageData.modList= mobList.map((e) => Map.from(e)).toList(); + if(result.containsKey('out_data')){ + customPageData.backgroundModel=BackgroundModel.fromJson(json.decode(result['out_data'])); + } + return customPageData; } } } @@ -27,17 +35,27 @@ class CustomPageRepository { } /// 缓存数据 - Future>> fetchCacheData() async { + Future fetchCacheData() async { + CustomPageData customPageData=CustomPageData(); try { String skipIdentifier = !EmptyUtil.isEmpty(data) && data.containsKey(GlobalConfig.SKIP_IDENTIFIER) && !EmptyUtil.isEmpty(data[GlobalConfig.SKIP_IDENTIFIER]) ? data[GlobalConfig.SKIP_IDENTIFIER] : null; // String skipIdentifier = 'pub.flutter.index.84'; if (!EmptyUtil.isEmpty(skipIdentifier)) { - var result = await NetUtil.getRequestCachedData('/api/v1/mod/$skipIdentifier'); + Map result = await NetUtil.getRequestCachedData('/api/v1/mod/$skipIdentifier'); if (!EmptyUtil.isEmpty(result)) { List mobList = result['mod_list']; + customPageData.modList=List(); if (!EmptyUtil.isEmpty(mobList)) { - return mobList.map((e) => Map.from(e)).toList(); + for(var item in mobList){ + customPageData.modList.add(Map.from(item)); + } + if(result.containsKey('out_data')){ + var jsonData=json.decode(result['out_data']); + print(jsonData); + customPageData.backgroundModel=BackgroundModel.fromJson(jsonData); + } + return customPageData; } } } @@ -47,3 +65,9 @@ class CustomPageRepository { return null; } } + + +class CustomPageData{ + BackgroundModel backgroundModel; + List> modList; +} \ No newline at end of file diff --git a/lib/pages/custom_page/bloc/custom_page_state.dart b/lib/pages/custom_page/bloc/custom_page_state.dart index 7d9bf3b..2327d34 100644 --- a/lib/pages/custom_page/bloc/custom_page_state.dart +++ b/lib/pages/custom_page/bloc/custom_page_state.dart @@ -1,5 +1,6 @@ import 'package:meta/meta.dart'; import 'package:equatable/equatable.dart'; +import 'package:zhiying_base_widget/pages/main_page/model/background_model.dart'; @immutable abstract class CustomPageState extends Equatable{ @@ -12,8 +13,9 @@ class CustomPageInitialState extends CustomPageState {} /// 数据加载成功 class CustomPageLoadedState extends CustomPageState { + BackgroundModel backgroundModel; List> model; - CustomPageLoadedState({this.model}); + CustomPageLoadedState({this.model,this.backgroundModel}); @override List get props => [this.model]; } diff --git a/lib/pages/custom_page/custom_page.dart b/lib/pages/custom_page/custom_page.dart index bb5cdb6..57bc1ad 100644 --- a/lib/pages/custom_page/custom_page.dart +++ b/lib/pages/custom_page/custom_page.dart @@ -4,6 +4,7 @@ import 'package:flutter/cupertino.dart'; import 'package:pull_to_refresh/pull_to_refresh.dart'; import 'package:tab_indicator_styler/tab_indicator_styler.dart'; import 'package:zhiying_base_widget/pages/custom_page/custom_item_page.dart'; +import 'package:zhiying_base_widget/pages/main_page/model/background_model.dart'; import 'package:zhiying_base_widget/pages/main_page/notifier/main_page_bg_notifier.dart'; import 'package:zhiying_base_widget/widgets/custom/search/custom_search_widget.dart'; import 'package:zhiying_base_widget/widgets/empty/empty_widget.dart'; @@ -101,7 +102,7 @@ class __CommonPageContainerState extends State<_CommonPageContainer> with Single /// 有数据 if (state is CustomPageLoadedState) { if (EmptyUtil.isEmpty(state.model)) return _buildEmptyWidget(); - return _buildMainWidget(state.model); + return _buildMainWidget(state.model,state.backgroundModel); } /// 初始化失败 @@ -117,20 +118,22 @@ class __CommonPageContainerState extends State<_CommonPageContainer> with Single } /// 有数据 - Widget _buildMainWidget(List> model) { - return Stack( - children: [ - Scaffold( - appBar: _buildAppbar(model?.first), - backgroundColor: HexColor.fromHex('#F9F9F9'), - // floatingActionButton: _buildFloatWidget(), - floatingActionButtonLocation: _CustomFloatingActionButtonLocation(FloatingActionButtonLocation.endFloat, 0, -100), - body: Column(children: _buildFirstWidget(model)), - ), - ], + Widget _buildMainWidget(List> model,BackgroundModel backgroundModel) { + return Scaffold( + appBar: _buildAppbar(model?.first), + backgroundColor: HexColor.fromHex(backgroundModel?.bgColor??""), + // floatingActionButton: _buildFloatWidget(), + floatingActionButtonLocation: _CustomFloatingActionButtonLocation(FloatingActionButtonLocation.endFloat, 0, -100), + body: Stack( + children: [ + _buildBackground(backgroundModel), + Column(children: _buildFirstWidget(model)), + ], + ), ); } + /// 骨架图 Widget _buildSkeletonWidget() { return Scaffold(); @@ -223,8 +226,8 @@ class __CommonPageContainerState extends State<_CommonPageContainer> with Single } // 没有appbar并且没有tabbar,则给第一个元素加边距 - if (!_isHasAppbar && !_isHasTabBar) { - result.insert(0, SizedBox(height: MediaQueryData.fromWindow(window).padding.top, child: Container(color: HexColor.fromHex('#FF4242'),),)); + if (!_isHasAppbar) { + result.insert(0, SizedBox(height: MediaQueryData.fromWindow(window).padding.top, child: Container(color: HexColor.fromHex(''),),)); } return result; @@ -340,6 +343,24 @@ class __CommonPageContainerState extends State<_CommonPageContainer> with Single return result; } + _buildBackground(BackgroundModel backgroundModel) { + if (backgroundModel != null) { + var headerBg = backgroundModel.headerBg; + return Container( + height: double.tryParse(headerBg?.height)?? 0, + width: double.infinity, + decoration: BoxDecoration( + gradient: LinearGradient( + begin: Alignment.topCenter, + end: Alignment.bottomCenter, + colors: [HexColor.fromHex(headerBg?.mainColor ?? ""), HexColor.fromHex(headerBg?.assistColor ?? ""), HexColor.fromHex(headerBg?.minorColor ?? "")])), + ); + }else{ + return Container(); + } + } + + // /// 悬浮按钮 // Widget _buildFloatWidget() { // return Visibility( diff --git a/lib/pages/main_page/main_page.dart b/lib/pages/main_page/main_page.dart index 3e813ff..210e276 100644 --- a/lib/pages/main_page/main_page.dart +++ b/lib/pages/main_page/main_page.dart @@ -114,7 +114,7 @@ class _MainPageContainerState extends State<_MainPageContainer> { _refreshController.refreshCompleted(); Widget bgWidget = validateBgWidget(context, snapshot.data ?? []); return Scaffold( - backgroundColor: Color(0xfff9f9f9), + backgroundColor: HexColor.fromHex("#fff9f9f9"), floatingActionButton: _floatWidget, floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked, body: MediaQuery.removePadding( @@ -180,15 +180,16 @@ class _MainPageContainerState extends State<_MainPageContainer> { return list; } - - ///处理特殊背景图 Widget validateBgWidget(BuildContext context, List> datas) { + + + for (int i = 0; i < datas.length; i++) { WidgetModel item = WidgetModel.fromJson(Map.from(datas[i])); if (item.modName == "profile_background") { final double statusBarHeight = MediaQuery.of(context).padding.top; - String url=json.decode(item.data)['img']; + String url = json.decode(item.data)['img']; return Container( width: double.infinity, height: statusBarHeight + 250, @@ -198,21 +199,34 @@ class _MainPageContainerState extends State<_MainPageContainer> { ), ); } - if (item.modName == "member_info") { - final double statusBarHeight = MediaQuery.of(context).padding.top; - String url=json.decode(item.data)['bg_image']; - String bgColor=json.decode(item.data)['bg_color']; - return Container( - width: double.infinity, - height: statusBarHeight + 250, - color: HexColor.fromHex(bgColor??""), - child: CachedNetworkImage( - imageUrl: url??"", - fit: BoxFit.fitHeight, - ), - ); - } + // if (item.modName == "member_info") { + // final double statusBarHeight = MediaQuery.of(context).padding.top; + // String url = json.decode(item.data)['bg_image']; + // String bgColor = json.decode(item.data)['bg_color']; + // return Container( + // width: double.infinity, + // height: statusBarHeight + 250, + // color: HexColor.fromHex(bgColor ?? ""), + // child: CachedNetworkImage( + // imageUrl: url ?? "", + // fit: BoxFit.fitHeight, + // ), + // ); + // } + } + + if (_bloc.backgroundModel != null) { + var headerBg = _bloc.backgroundModel.headerBg; + return Container( + height: double.tryParse(_bloc?.backgroundModel?.headerBg?.height)?? 0, + decoration: BoxDecoration( + gradient: LinearGradient( + begin: Alignment.topCenter, + end: Alignment.bottomCenter, + colors: [HexColor.fromHex(headerBg?.mainColor ?? ""), HexColor.fromHex(headerBg?.assistColor ?? ""), HexColor.fromHex(headerBg?.minorColor ?? "")])), + ); } + return null; } } diff --git a/lib/pages/main_page/main_page_bloc.dart b/lib/pages/main_page/main_page_bloc.dart index 6cbe1ab..cb6f9be 100644 --- a/lib/pages/main_page/main_page_bloc.dart +++ b/lib/pages/main_page/main_page_bloc.dart @@ -1,7 +1,9 @@ import 'dart:async'; +import 'package:zhiying_base_widget/pages/main_page/model/background_model.dart'; import 'package:zhiying_comm/util/base_bloc.dart'; import 'package:zhiying_comm/zhiying_comm.dart'; +import 'dart:convert' as Con; class MainPageBloc extends BlocBase { List> _pageData = List(); @@ -11,6 +13,8 @@ class MainPageBloc extends BlocBase { Stream>> get outData => _mainController.stream; + BackgroundModel backgroundModel; + @override void dispose() { _mainController.close(); @@ -18,6 +22,7 @@ class MainPageBloc extends BlocBase { } void loadData(String skipIdentifier) { + print("加载mainPage"+skipIdentifier); NetUtil.request('/api/v1/mod/${skipIdentifier}', method: NetMethod.GET, onCache: (data) { _loadData(data); @@ -33,7 +38,7 @@ class MainPageBloc extends BlocBase { _pageData = list.map((item) { return Map.from(item); }).toList(); - + backgroundModel=BackgroundModel.fromJson(Con.json.decode(json['out_data'])); _mainController.add(_pageData); } } diff --git a/lib/pages/main_page/model/background_model.dart b/lib/pages/main_page/model/background_model.dart new file mode 100644 index 0000000..88d278d --- /dev/null +++ b/lib/pages/main_page/model/background_model.dart @@ -0,0 +1,47 @@ +class BackgroundModel { + HeaderBg headerBg; + String bgColor; + + BackgroundModel({this.headerBg, this.bgColor}); + + BackgroundModel.fromJson(Map json) { + headerBg = json['header_bg'] != null + ? new HeaderBg.fromJson(json['header_bg']) + : null; + bgColor = json['bg_color']; + } + + Map toJson() { + final Map data = new Map(); + if (this.headerBg != null) { + data['header_bg'] = this.headerBg.toJson(); + } + data['bg_color'] = this.bgColor; + return data; + } +} + +class HeaderBg { + String height; + String mainColor; + String assistColor; + String minorColor; + + HeaderBg({this.height, this.mainColor, this.assistColor, this.minorColor}); + + HeaderBg.fromJson(Map json) { + height = json['height']; + mainColor = json['main_color']; + assistColor = json['assist_color']; + minorColor = json['minor_color']; + } + + Map toJson() { + final Map data = new Map(); + data['height'] = this.height; + data['main_color'] = this.mainColor; + data['assist_color'] = this.assistColor; + data['minor_color'] = this.minorColor; + return data; + } +} diff --git a/lib/widgets/custom/goods/category_goods/custom_goods2.dart b/lib/widgets/custom/goods/category_goods/custom_goods2.dart index 208becb..594af20 100644 --- a/lib/widgets/custom/goods/category_goods/custom_goods2.dart +++ b/lib/widgets/custom/goods/category_goods/custom_goods2.dart @@ -56,7 +56,7 @@ class CustomGoodsContainer2 extends StatefulWidget { class CustomGoodsContainer2State extends State { HomeGoodsBloc _bloc; - String _provider = ''; + dynamic _provider; HomeGoodsStyleModel _style; @override @@ -128,7 +128,7 @@ class CustomGoodsContainer2State extends State { } // Global Key - void changeProviderOrLoadMore(String provider) { + void changeProviderOrLoadMore(dynamic provider) { Logger.warn('_CustomGoodsContainer2State ======================= provider = $provider'); _provider = provider; _bloc?.loadMore(_bloc.providerss); diff --git a/lib/widgets/custom/goods/category_goods/custom_goods_header.dart b/lib/widgets/custom/goods/category_goods/custom_goods_header.dart index aee8ed8..430743c 100644 --- a/lib/widgets/custom/goods/category_goods/custom_goods_header.dart +++ b/lib/widgets/custom/goods/category_goods/custom_goods_header.dart @@ -80,7 +80,7 @@ class _CustomGoodsHeaderContainerState extends State _tabController = TabController(length: _style?.recommendList?.length ?? 0, vsync: this); if (_style.recommendList.first != null) { // TODO - widget.callBack.onTap(0, _style.recommendList.first.type); + widget.callBack.onTap(0, _style.recommendList.first.data); } super.initState(); } @@ -110,7 +110,7 @@ class _CustomGoodsHeaderContainerState extends State tabs: _widgets, onTap: (index) { //TODO - widget.callBack.onTap(index, _style.recommendList[index].type); + widget.callBack.onTap(index, _style.recommendList[index].data); setState(() { _currentIndex = index; }); diff --git a/lib/widgets/custom/goods/category_goods/custom_goods_header2.dart b/lib/widgets/custom/goods/category_goods/custom_goods_header2.dart index aba957b..35b14a3 100644 --- a/lib/widgets/custom/goods/category_goods/custom_goods_header2.dart +++ b/lib/widgets/custom/goods/category_goods/custom_goods_header2.dart @@ -84,7 +84,7 @@ class _CustomGoodsHeaderContainer2State extends State child: Container( width: double.infinity, height: double.infinity, - color: size > 1 ? HexColor.fromHex(datas?.bgColor2??"#FFFF4242") : Colors.transparent, + color: size > 1 ? HexColor.fromHex(datas?.bgColor2??"#00000000") : Colors.transparent, // color: Colors.yellow, ), ), diff --git a/lib/widgets/home/home_goods/bloc/home_goods_bloc.dart b/lib/widgets/home/home_goods/bloc/home_goods_bloc.dart index dfe750d..005b198 100644 --- a/lib/widgets/home/home_goods/bloc/home_goods_bloc.dart +++ b/lib/widgets/home/home_goods/bloc/home_goods_bloc.dart @@ -1,4 +1,5 @@ import 'dart:async'; +import 'dart:convert'; import 'package:zhiying_base_widget/widgets/custom/goods/category_goods/category_goods_callback.dart'; import 'package:zhiying_base_widget/widgets/home/home_goods/models/home_goods_model.dart'; @@ -8,7 +9,7 @@ import 'package:zhiying_comm/zhiying_comm.dart'; class HomeGoodsBloc extends BlocBase implements CategoryGoodsOnClickCallBack{ List _goods = List(); - String _provider = ''; + dynamic _provider ; String providerss = ''; int _page = 1; @@ -22,7 +23,7 @@ class HomeGoodsBloc extends BlocBase implements CategoryGoodsOnClickCallBack{ _goodsController = null; } - void loadMore(String provider) { + void loadMore(dynamic provider) { if (provider != _provider) { _page = 1; } @@ -32,7 +33,8 @@ class HomeGoodsBloc extends BlocBase implements CategoryGoodsOnClickCallBack{ _goods.clear(); } - NetUtil.request('/api/v1/rec/${provider.toString()}?page=${_page.toString()}', + NetUtil.request('/api/v1/rec?page=${_page.toString()}', + queryParameters: _provider, method: NetMethod.GET, onCache: _page == 1 ? (data) { diff --git a/lib/widgets/home/home_goods/home_goods.dart b/lib/widgets/home/home_goods/home_goods.dart index 0e5e2dc..7bb1d6d 100644 --- a/lib/widgets/home/home_goods/home_goods.dart +++ b/lib/widgets/home/home_goods/home_goods.dart @@ -51,7 +51,7 @@ class _HomeGoodsContainer extends StatefulWidget { class _HomeGoodsContainerState extends State<_HomeGoodsContainer> { HomeGoodsBloc _bloc; - String _provider = ''; + dynamic _provider ; HomeGoodsStyleModel _style; bool _isFirstLoading = true; diff --git a/lib/widgets/home/home_goods/home_goods_creater.dart b/lib/widgets/home/home_goods/home_goods_creater.dart index 7b10ec2..a46e004 100644 --- a/lib/widgets/home/home_goods/home_goods_creater.dart +++ b/lib/widgets/home/home_goods/home_goods_creater.dart @@ -31,7 +31,7 @@ class GoodsListCreater extends WidgetCreater { } class HomeGoodsHeaderEvent { - String provider; + dynamic provider; HomeGoodsHeaderEvent(this.provider); } diff --git a/lib/widgets/home/home_goods/home_goods_header.dart b/lib/widgets/home/home_goods/home_goods_header.dart index cc701aa..e73b4f8 100644 --- a/lib/widgets/home/home_goods/home_goods_header.dart +++ b/lib/widgets/home/home_goods/home_goods_header.dart @@ -81,7 +81,7 @@ class _HomeGoodsHeaderState extends State<_HomeGoodsHeader> TabController(length: _style?.recommendList?.length ?? 0, vsync: this); if (_style.recommendList.first != null) { widget.eventBus - .fire(HomeGoodsHeaderEvent(_style.recommendList.first.type)); + .fire(HomeGoodsHeaderEvent(_style.recommendList.first.data)); } super.initState(); } @@ -121,7 +121,7 @@ class _HomeGoodsHeaderState extends State<_HomeGoodsHeader> tabs: _widgets, onTap: (index) { widget.eventBus - .fire(HomeGoodsHeaderEvent(_style.recommendList[index].type)); + .fire(HomeGoodsHeaderEvent(_style.recommendList[index].data)); setState(() { _currentIndex = index; }); diff --git a/lib/widgets/home/home_goods/models/home_goods_header_model.dart b/lib/widgets/home/home_goods/models/home_goods_header_model.dart index 1f8872f..cdef13a 100644 --- a/lib/widgets/home/home_goods/models/home_goods_header_model.dart +++ b/lib/widgets/home/home_goods/models/home_goods_header_model.dart @@ -1,25 +1,49 @@ class HomeGoodsHeaderModel { - String type; + // String type; String title; String subtitle; + int index; + dynamic data; - HomeGoodsHeaderModel({ - this.type, - this.title, - this.subtitle, - }); + HomeGoodsHeaderModel( + { this.title, this.subtitle, this.index, this.data}); HomeGoodsHeaderModel.fromJson(Map json) { - type = json['type']; + /// type = json['type']; title = json['title']; subtitle = json['subtitle']; + index = json['index']; + data = json['data']; } Map toJson() { final Map data = new Map(); - data['type'] = this.type; + //data['type'] = this.type; data['title'] = this.title; data['subtitle'] = this.subtitle; + data['index'] = this.index; + if (this.data != null) { + data['data'] = this.data.toJson(); + } + return data; + } +} + +class Data { + String pvd; + String categoryId; + + Data({this.pvd, this.categoryId}); + + Data.fromJson(Map json) { + pvd = json['pvd']; + categoryId = json['category_id']; + } + + Map toJson() { + final Map data = new Map(); + data['pvd'] = this.pvd; + data['category_id'] = this.categoryId; return data; } }