From 9a8c6b4051ccf5fbf9cc9861dba9301da721d07c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cyanghuaxuan=E2=80=9D?= <“646903573@qq.com”> Date: Wed, 21 Apr 2021 15:40:24 +0800 Subject: [PATCH] =?UTF-8?q?1.=E4=BC=98=E5=8C=96=E9=92=B1=E5=8C=85=E5=8A=A0?= =?UTF-8?q?=E8=BD=BD=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- example/lib/main.dart | 6 +- example/pubspec.yaml | 10 +- .../wallet/wallet_detail/wallet_detail.dart | 121 +++++------------- .../wallet_detail/wallet_detail_bloc.dart | 33 +++-- 4 files changed, 58 insertions(+), 112 deletions(-) diff --git a/example/lib/main.dart b/example/lib/main.dart index ad8f824..9fbd3b4 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -24,7 +24,8 @@ import 'package:zhiying_equity_card/zhiying_equity_card.dart'; import 'package:zhiying_official/register.dart'; import 'package:zhiying_base_widget/zhiying_base_widget.dart'; import 'package:zhiying_acquisition/register.dart'; -//import 'package:zhiying_credit_card/register.dart'; +import 'package:zhiying_shopping_mall/zhiying_shopping_mall.dart'; +import 'package:zhiying_credit_card/register.dart'; void main() { FlutterError.onError = (FlutterErrorDetails details) { @@ -68,7 +69,8 @@ class _MyAppState extends State { EquityCardRegister.init(); OfficialRegister.init(); AcquisitionRegister.init(); - // CreditCardRegister.init(); + ShoppingMallRegister.init(); + CreditCardRegister.init(); // print('初始化百川'); FlutterAlibc.initAlibc(version: "", appName: "").then((result) { print("百川" + '${result.errorCode} ${result.errorMessage}'); diff --git a/example/pubspec.yaml b/example/pubspec.yaml index d67667d..1b76dd1 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -34,8 +34,12 @@ dev_dependencies: path: ../../zhiying_official zhiying_acquisition: path: ../../zhiying_acquisition -# zhiying_credit_card: -# path: ../../zhiying_credit_card + zhiying_shopping_mall: + git: + ref: 0.0.4 + url: 'http://192.168.0.138:3000/FnuoOS_ZhiYing/zhiying_shopping_mall.git' + zhiying_credit_card: + path: ../../zhiying_credit_card #微信导师 zhiying_wechat_teacher: # path: ../../zhiying_wechat_teacher @@ -46,7 +50,7 @@ dev_dependencies: zhiying_moments: # path: ../../zhiying_moments git: - ref: 0.2.2 + ref: 0.2.3 url: http://192.168.0.138:3000/FnuoOS_ZhiYing/zhiying_moments.git #会员升级 zhiying_member_upgrade: diff --git a/lib/widgets/wallet/wallet_detail/wallet_detail.dart b/lib/widgets/wallet/wallet_detail/wallet_detail.dart index aa5344f..b8d92a4 100644 --- a/lib/widgets/wallet/wallet_detail/wallet_detail.dart +++ b/lib/widgets/wallet/wallet_detail/wallet_detail.dart @@ -23,8 +23,7 @@ class WalletDetail extends StatefulWidget { _WalletDetailState createState() => _WalletDetailState(); } -class _WalletDetailState extends State - with TickerProviderStateMixin { +class _WalletDetailState extends State with TickerProviderStateMixin { WalletDetailModel _model; TabController _tabController; @@ -35,24 +34,22 @@ class _WalletDetailState extends State void initState() { if (widget.data != null) { _model = WalletDetailModel.fromJson(json.decode(widget.data['data'])); - _tabController = - TabController(length: _model.providers.length, vsync: this); + _tabController = TabController(length: _model.providers.length, vsync: this); } _bloc = new WalletDetailBloc(); - _bloc.loadData(_model.providers[0].type); + _bloc.loadData(_model.providers[0].type, _bloc.selectDay); super.initState(); } - @override void didChangeDependencies() { RefreshListener.listen(context, (event) { if (event == "refresh") { if (_bloc.currentType == null) { - _bloc.loadData(_model.providers[0].type); + _bloc.loadData(_model.providers[0].type, _bloc.selectDay); } else { - _bloc.loadData(_bloc.currentType); + _bloc.loadData(_bloc.currentType, _bloc.selectDay); } } }); @@ -69,15 +66,13 @@ class _WalletDetailState extends State return StreamBuilder( stream: _bloc.outData, builder: (context, asyn) { - if (_bloc.listDataModel.length == 0) { + if (_bloc.currentWalletDetailDataModel == null) { ///骨架图 return WalletDetailSkeleton(); } return Container( - decoration: BoxDecoration( - color: Colors.white, borderRadius: BorderRadius.circular(8)), - margin: - EdgeInsets.only(left: 12.5, right: 12.5, top: 7.5, bottom: 7.5), + decoration: BoxDecoration(color: Colors.white, borderRadius: BorderRadius.circular(8)), + margin: EdgeInsets.only(left: 12.5, right: 12.5, top: 7.5, bottom: 7.5), padding: const EdgeInsets.only(bottom: 13), child: Column( crossAxisAlignment: CrossAxisAlignment.start, @@ -96,13 +91,10 @@ class _WalletDetailState extends State color: HexColor.fromHex(_model.providers[0].selectColor), ), isScrollable: true, - unselectedLabelColor: - HexColor.fromHex(_model.providers[0].unselectColor), - labelColor: - HexColor.fromHex(_model.providers[0].selectColor), + unselectedLabelColor: HexColor.fromHex(_model.providers[0].unselectColor), + labelColor: HexColor.fromHex(_model.providers[0].selectColor), controller: _tabController, - indicatorColor: - HexColor.fromHex(_model.providers[0].selectColor), + indicatorColor: HexColor.fromHex(_model.providers[0].selectColor), indicatorSize: TabBarIndicatorSize.label, onTap: (index) { ///变更平台 @@ -128,11 +120,7 @@ class _WalletDetailState extends State height: 63, margin: EdgeInsets.only(top: 16, left: 15, right: 15), width: double.infinity, - decoration: BoxDecoration( - image: DecorationImage( - image: CachedNetworkImageProvider( - _model.providerDashbord.finish.bgImg), - fit: BoxFit.fill)), + decoration: BoxDecoration(image: DecorationImage(image: CachedNetworkImageProvider(_model.providerDashbord.finish.bgImg), fit: BoxFit.fill)), child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ @@ -142,10 +130,7 @@ class _WalletDetailState extends State padding: const EdgeInsets.all(8.0), child: Text( _model.providerDashbord.finish.text, - style: TextStyle( - fontSize: 14, - color: HexColor.fromHex(_model - .providerDashbord.finish.textColor)), + style: TextStyle(fontSize: 14, color: HexColor.fromHex(_model.providerDashbord.finish.textColor)), ), ), Row( @@ -159,9 +144,7 @@ class _WalletDetailState extends State child: Padding( padding: const EdgeInsets.all(8.0), child: CachedNetworkImage( - imageUrl: - _model.providerDashbord.finish.tipIcon ?? - "", + imageUrl: _model.providerDashbord.finish.tipIcon ?? "", width: 10, height: 10, fit: BoxFit.fill, @@ -169,19 +152,13 @@ class _WalletDetailState extends State ), onTap: () { ///显示弹窗 - showTipDialog( - null, _model.providerDashbord.finish.tipText); + showTipDialog(null, _model.providerDashbord.finish.tipText); }) ], ), Text( _bloc.selectDateData.finish ?? "", - style: TextStyle( - color: Colors.red, - fontSize: 20, - fontFamily: 'Din', - package: 'zhiying_comm', - fontWeight: FontWeight.bold), + style: TextStyle(color: Colors.red, fontSize: 20, fontFamily: 'Din', package: 'zhiying_comm', fontWeight: FontWeight.bold), ) ], ), @@ -193,8 +170,7 @@ class _WalletDetailState extends State shrinkWrap: true, physics: NeverScrollableScrollPhysics(), itemBuilder: (context, index) { - return _buildBottomItem( - context, index, _model.providerDashbord); + return _buildBottomItem(context, index, _model.providerDashbord); }), ) ], @@ -224,41 +200,26 @@ class _WalletDetailState extends State child: Container( margin: EdgeInsets.only(top: 0, left: 8, right: 8), decoration: BoxDecoration( - image: DecorationImage( - image: CachedNetworkImageProvider( - item.type == _bloc.selectDateData.type - ? item.btnImg ?? "" - : item.btnNoColorImg ?? ""), - fit: BoxFit.fitWidth), + image: DecorationImage(image: CachedNetworkImageProvider(item.type == _bloc.selectDateData.type ? item.btnImg ?? "" : item.btnNoColorImg ?? ""), fit: BoxFit.fitWidth), ), child: Padding( padding: const EdgeInsets.only(left: 16, right: 16), child: Center( child: Text( item.text, - style: TextStyle( - fontSize: 11, - color: HexColor.fromHex(item.type == _bloc.selectDateData.type - ? item.textSelectColor - : item.textUnselectColor)), + style: TextStyle(fontSize: 11, color: HexColor.fromHex(item.type == _bloc.selectDateData.type ? item.textSelectColor : item.textUnselectColor)), )), ), ), onTap: () { - for (var select in _bloc.listDataModel) { - if (select.type == item.type) { - _bloc.selectDay = item.type; - _bloc.refresh(); - return; - } - } + _bloc.selectDay = item.type; + _bloc.loadData(_bloc.currentType, _bloc.selectDay); }, ); } ///底部显示 - Widget _buildBottomItem( - BuildContext context, int index, ProviderDashbord dashbord) { + Widget _buildBottomItem(BuildContext context, int index, ProviderDashbord dashbord) { SelfBuy item; if (index == 0) { item = dashbord.selfBuy; @@ -280,8 +241,7 @@ class _WalletDetailState extends State ? Container() : Text( item.title, - style: TextStyle( - color: HexColor.fromHex(item.titleColor), fontSize: 14), + style: TextStyle(color: HexColor.fromHex(item.titleColor), fontSize: 14), ), SizedBox( height: 7.5, @@ -294,11 +254,7 @@ class _WalletDetailState extends State height: 61.5, margin: EdgeInsets.only(right: 8, left: 15), padding: EdgeInsets.only(left: 10), - decoration: BoxDecoration( - image: DecorationImage( - image: CachedNetworkImageProvider( - item.itemList[0].bgImg ?? ""), - fit: BoxFit.fill)), + decoration: BoxDecoration(image: DecorationImage(image: CachedNetworkImageProvider(item.itemList[0].bgImg ?? ""), fit: BoxFit.fill)), child: Column( mainAxisAlignment: MainAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.start, @@ -307,10 +263,7 @@ class _WalletDetailState extends State children: [ Text( item.itemList[0].text ?? "", - style: TextStyle( - fontSize: 11, - color: HexColor.fromHex( - item.itemList[0].textColor)), + style: TextStyle(fontSize: 11, color: HexColor.fromHex(item.itemList[0].textColor)), ), InkWell( child: Padding( @@ -335,8 +288,7 @@ class _WalletDetailState extends State package: 'zhiying_comm', fontWeight: FontWeight.bold, fontSize: 17, - color: - HexColor.fromHex(item.itemList[1].valueColor), + color: HexColor.fromHex(item.itemList[1].valueColor), )) ], )), @@ -349,11 +301,7 @@ class _WalletDetailState extends State right: 15, ), padding: EdgeInsets.only(left: 10), - decoration: BoxDecoration( - image: DecorationImage( - image: CachedNetworkImageProvider( - item.itemList[1].bgImg ?? ""), - fit: BoxFit.fill)), + decoration: BoxDecoration(image: DecorationImage(image: CachedNetworkImageProvider(item.itemList[1].bgImg ?? ""), fit: BoxFit.fill)), child: Column( mainAxisAlignment: MainAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.start, @@ -362,10 +310,7 @@ class _WalletDetailState extends State children: [ Text( item.itemList[1].text ?? "", - style: TextStyle( - fontSize: 11, - color: - HexColor.fromHex(item.itemList[1].textColor)), + style: TextStyle(fontSize: 11, color: HexColor.fromHex(item.itemList[1].textColor)), ), InkWell( child: Padding( @@ -386,12 +331,7 @@ class _WalletDetailState extends State ), Text( dataMap[item.itemList[1].vauleKey], - style: TextStyle( - fontSize: 17, - color: HexColor.fromHex(item.itemList[1].valueColor), - fontFamily: 'Din', - package: 'zhiying_comm', - fontWeight: FontWeight.bold), + style: TextStyle(fontSize: 17, color: HexColor.fromHex(item.itemList[1].valueColor), fontFamily: 'Din', package: 'zhiying_comm', fontWeight: FontWeight.bold), ) ], ), @@ -405,7 +345,8 @@ class _WalletDetailState extends State ///变更平台 void changeProvider(String type) { - _bloc.loadData(type); + _bloc.currentType = type; + _bloc.loadData(type, _bloc.selectDay); } ///显示提示框 diff --git a/lib/widgets/wallet/wallet_detail/wallet_detail_bloc.dart b/lib/widgets/wallet/wallet_detail/wallet_detail_bloc.dart index 3bfbf64..f23c372 100644 --- a/lib/widgets/wallet/wallet_detail/wallet_detail_bloc.dart +++ b/lib/widgets/wallet/wallet_detail/wallet_detail_bloc.dart @@ -7,8 +7,7 @@ import 'package:zhiying_comm/zhiying_comm.dart'; import 'model/wallet_detail_data_model.dart'; class WalletDetailBloc extends BlocBase { - StreamController _dataController = - StreamController(); + StreamController _dataController = StreamController(); Stream get outData => _dataController.stream; @@ -21,6 +20,8 @@ class WalletDetailBloc extends BlocBase { String currentType; + WalletDetailDataModel currentWalletDetailDataModel; + @override void dispose() { _dataController.close(); @@ -30,25 +31,23 @@ class WalletDetailBloc extends BlocBase { /// /// 加载头部数据 /// - loadData(String type) async { - await NetUtil.request("/api/v1/user/wallet/" + type, onSuccess: (data) { - currentType = type; - listDataModel.clear(); - listDataModel.addAll(List.from(data).map((v) { - return WalletDetailDataModel.fromJson(v); - }).toList()); - refresh(); + loadData(String type, String time) async { + currentType = type; + await NetUtil.request("/api/v1/user/wallet/" + type + "?time=" + time, onSuccess: (data) { + if (currentType == type) { + listDataModel.clear(); + listDataModel.addAll(List.from(data).map((v) { + return WalletDetailDataModel.fromJson(v); + }).toList()); + currentWalletDetailDataModel = listDataModel[0]; + refresh(); + } }); } ///刷新页面 refresh() { - for (var item in listDataModel) { - if (selectDay == item.type) { - selectDateData = item; - _dataController.add(selectDateData); - return; - } - } + selectDateData = currentWalletDetailDataModel; + _dataController.add(selectDateData); } }