Bläddra i källkod

1.添加custom的背景色

2.变更商品列表的请求方式
tags/0.0.3+8^0
“yanghuaxuan” 3 år sedan
förälder
incheckning
8aa289e62e
16 ändrade filer med 206 tillägg och 67 borttagningar
  1. +6
    -6
      lib/pages/custom_page/bloc/custom_page_bloc.dart
  2. +29
    -5
      lib/pages/custom_page/bloc/custom_page_repository.dart
  3. +3
    -1
      lib/pages/custom_page/bloc/custom_page_state.dart
  4. +35
    -14
      lib/pages/custom_page/custom_page.dart
  5. +32
    -18
      lib/pages/main_page/main_page.dart
  6. +6
    -1
      lib/pages/main_page/main_page_bloc.dart
  7. +47
    -0
      lib/pages/main_page/model/background_model.dart
  8. +2
    -2
      lib/widgets/custom/goods/category_goods/custom_goods2.dart
  9. +2
    -2
      lib/widgets/custom/goods/category_goods/custom_goods_header.dart
  10. +2
    -2
      lib/widgets/custom/goods/category_goods/custom_goods_header2.dart
  11. +1
    -1
      lib/widgets/custom/slide_banner/custom_slide_banner.dart
  12. +5
    -3
      lib/widgets/home/home_goods/bloc/home_goods_bloc.dart
  13. +1
    -1
      lib/widgets/home/home_goods/home_goods.dart
  14. +1
    -1
      lib/widgets/home/home_goods/home_goods_creater.dart
  15. +2
    -2
      lib/widgets/home/home_goods/home_goods_header.dart
  16. +32
    -8
      lib/widgets/home/home_goods/models/home_goods_header_model.dart

+ 6
- 6
lib/pages/custom_page/bloc/custom_page_bloc.dart Visa fil

@@ -37,7 +37,7 @@ class CustomPageBloc extends Bloc<CustomPageEvent, CustomPageState> {
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<CustomPageEvent, CustomPageState> {
Stream<CustomPageState> _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<Map<String, dynamic>> mdata = result;
List<Map<String, dynamic>> 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();


+ 29
- 5
lib/pages/custom_page/bloc/custom_page_repository.dart Visa fil

@@ -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<List<Map<String, dynamic>>> fetchInitData() async {
Future<CustomPageData> 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<String, dynamic>.from(e)).toList();
customPageData.modList= mobList.map((e) => Map<String, dynamic>.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<List<Map<String, dynamic>>> fetchCacheData() async {
Future<CustomPageData> 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<String,dynamic> 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<String, dynamic>.from(e)).toList();
for(var item in mobList){
customPageData.modList.add(Map<String, dynamic>.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<Map<String, dynamic>> modList;
}

+ 3
- 1
lib/pages/custom_page/bloc/custom_page_state.dart Visa fil

@@ -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<Map<String, dynamic>> model;
CustomPageLoadedState({this.model});
CustomPageLoadedState({this.model,this.backgroundModel});
@override
List<Object> get props => [this.model];
}


+ 35
- 14
lib/pages/custom_page/custom_page.dart Visa fil

@@ -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<Map<String, dynamic>> model) {
return Stack(
children: <Widget>[
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<Map<String, dynamic>> 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: <Widget>[
_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(


+ 32
- 18
lib/pages/main_page/main_page.dart Visa fil

@@ -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<Map<String, dynamic>> datas) {



for (int i = 0; i < datas.length; i++) {
WidgetModel item = WidgetModel.fromJson(Map<String, dynamic>.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;
}
}

+ 6
- 1
lib/pages/main_page/main_page_bloc.dart Visa fil

@@ -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<Map<String, dynamic>> _pageData = List();
@@ -11,6 +13,8 @@ class MainPageBloc extends BlocBase {

Stream<List<Map<String, dynamic>>> 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<String, dynamic>.from(item);
}).toList();
backgroundModel=BackgroundModel.fromJson(Con.json.decode(json['out_data']));
_mainController.add(_pageData);
}
}

+ 47
- 0
lib/pages/main_page/model/background_model.dart Visa fil

@@ -0,0 +1,47 @@
class BackgroundModel {
HeaderBg headerBg;
String bgColor;

BackgroundModel({this.headerBg, this.bgColor});

BackgroundModel.fromJson(Map<String, dynamic> json) {
headerBg = json['header_bg'] != null
? new HeaderBg.fromJson(json['header_bg'])
: null;
bgColor = json['bg_color'];
}

Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
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<String, dynamic> json) {
height = json['height'];
mainColor = json['main_color'];
assistColor = json['assist_color'];
minorColor = json['minor_color'];
}

Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
data['height'] = this.height;
data['main_color'] = this.mainColor;
data['assist_color'] = this.assistColor;
data['minor_color'] = this.minorColor;
return data;
}
}

+ 2
- 2
lib/widgets/custom/goods/category_goods/custom_goods2.dart Visa fil

@@ -56,7 +56,7 @@ class CustomGoodsContainer2 extends StatefulWidget {

class CustomGoodsContainer2State extends State<CustomGoodsContainer2> {
HomeGoodsBloc _bloc;
String _provider = '';
dynamic _provider;
HomeGoodsStyleModel _style;

@override
@@ -128,7 +128,7 @@ class CustomGoodsContainer2State extends State<CustomGoodsContainer2> {
}

// Global Key
void changeProviderOrLoadMore(String provider) {
void changeProviderOrLoadMore(dynamic provider) {
Logger.warn('_CustomGoodsContainer2State ======================= provider = $provider');
_provider = provider;
_bloc?.loadMore(_bloc.providerss);


+ 2
- 2
lib/widgets/custom/goods/category_goods/custom_goods_header.dart Visa fil

@@ -80,7 +80,7 @@ class _CustomGoodsHeaderContainerState extends State<CustomGoodsHeaderContainer>
_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<CustomGoodsHeaderContainer>
tabs: _widgets,
onTap: (index) {
//TODO
widget.callBack.onTap(index, _style.recommendList[index].type);
widget.callBack.onTap(index, _style.recommendList[index].data);
setState(() {
_currentIndex = index;
});


+ 2
- 2
lib/widgets/custom/goods/category_goods/custom_goods_header2.dart Visa fil

@@ -84,7 +84,7 @@ class _CustomGoodsHeaderContainer2State extends State<CustomGoodsHeaderContainer
_tabController = TabController(length: _style?.recommendList?.length ?? 0, vsync: this);
if (_style.recommendList.first != null) {
// TODO
widget?.globalKey?.currentState?.changeProviderOrLoadMore(_style.recommendList.first.type);
widget?.globalKey?.currentState?.changeProviderOrLoadMore(_style.recommendList.first.data);
}
super.initState();
}
@@ -117,7 +117,7 @@ class _CustomGoodsHeaderContainer2State extends State<CustomGoodsHeaderContainer
setState(() {
_currentIndex = index;
});
widget?.globalKey?.currentState?.changeProviderOrLoadMore(_style.recommendList[index].type);
widget?.globalKey?.currentState?.changeProviderOrLoadMore(_style.recommendList[index].data);
},
),
);


+ 1
- 1
lib/widgets/custom/slide_banner/custom_slide_banner.dart Visa fil

@@ -123,7 +123,7 @@ class _CustomSlideBannerContainerState extends State<CustomSlideBannerContainer>
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,
),
),


+ 5
- 3
lib/widgets/home/home_goods/bloc/home_goods_bloc.dart Visa fil

@@ -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<HomeGoodsModel> _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) {


+ 1
- 1
lib/widgets/home/home_goods/home_goods.dart Visa fil

@@ -51,7 +51,7 @@ class _HomeGoodsContainer extends StatefulWidget {

class _HomeGoodsContainerState extends State<_HomeGoodsContainer> {
HomeGoodsBloc _bloc;
String _provider = '';
dynamic _provider ;
HomeGoodsStyleModel _style;
bool _isFirstLoading = true;



+ 1
- 1
lib/widgets/home/home_goods/home_goods_creater.dart Visa fil

@@ -31,7 +31,7 @@ class GoodsListCreater extends WidgetCreater {
}

class HomeGoodsHeaderEvent {
String provider;
dynamic provider;

HomeGoodsHeaderEvent(this.provider);
}

+ 2
- 2
lib/widgets/home/home_goods/home_goods_header.dart Visa fil

@@ -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;
});


+ 32
- 8
lib/widgets/home/home_goods/models/home_goods_header_model.dart Visa fil

@@ -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<String, dynamic> json) {
type = json['type'];
/// type = json['type'];
title = json['title'];
subtitle = json['subtitle'];
index = json['index'];
data = json['data'];
}

Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
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<String, dynamic> json) {
pvd = json['pvd'];
categoryId = json['category_id'];
}

Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
data['pvd'] = this.pvd;
data['category_id'] = this.categoryId;
return data;
}
}

Laddar…
Avbryt
Spara