From 3185c81eb1d011e7e7a78aefb772eef6cbefa711 Mon Sep 17 00:00:00 2001 From: Weller <1812208341@qq.com> Date: Tue, 15 Sep 2020 20:26:16 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E4=BC=9A=E5=91=98=E4=B8=AD?= =?UTF-8?q?=E5=BF=83=E6=95=B0=E6=8D=AE=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .dart_tool/package_config.json | 2 +- lib/register.dart | 31 ++- lib/widgets/mine/mine_data/mine_data.dart | 45 ++- .../mine/mine_data/mine_data_creater.dart | 12 - .../mine/mine_data/mine_data_widget.dart | 262 ++++++++++++++++++ .../mine/mine_data/model/mine_data_model.dart | 62 +++++ .../mine_data/model/mine_data_model.g.dart | 40 +++ lib/widgets/mine/mine_header/mine_header.dart | 98 ++----- .../mine/mine_header/mine_header_bloc.dart | 31 +-- .../mine_header/mine_header_container.dart | 154 ++++++++++ .../mine_header_static_container.dart | 77 +++++ .../mine_header/model/mine_header_model.dart | 6 + .../model/mine_header_model.g.dart | 6 +- .../mine_header/model/mine_profile_model.dart | 57 ++++ .../model/mine_profile_model.g.dart | 48 ++++ lib/widgets/mine/mine_nav/mine_nav.dart | 39 ++- 16 files changed, 842 insertions(+), 128 deletions(-) delete mode 100644 lib/widgets/mine/mine_data/mine_data_creater.dart create mode 100644 lib/widgets/mine/mine_data/mine_data_widget.dart create mode 100644 lib/widgets/mine/mine_data/model/mine_data_model.dart create mode 100644 lib/widgets/mine/mine_data/model/mine_data_model.g.dart create mode 100644 lib/widgets/mine/mine_header/mine_header_container.dart create mode 100644 lib/widgets/mine/mine_header/mine_header_static_container.dart create mode 100644 lib/widgets/mine/mine_header/model/mine_profile_model.dart create mode 100644 lib/widgets/mine/mine_header/model/mine_profile_model.g.dart diff --git a/.dart_tool/package_config.json b/.dart_tool/package_config.json index 7165310..bd497aa 100644 --- a/.dart_tool/package_config.json +++ b/.dart_tool/package_config.json @@ -680,7 +680,7 @@ "languageVersion": "2.1" } ], - "generated": "2020-09-15T02:01:44.342412Z", + "generated": "2020-09-15T07:31:12.840893Z", "generator": "pub", "generatorVersion": "2.7.2" } diff --git a/lib/register.dart b/lib/register.dart index ead646b..a901c01 100644 --- a/lib/register.dart +++ b/lib/register.dart @@ -15,9 +15,8 @@ import 'package:zhiying_base_widget/widgets/others/normal_nav/normal_nav_creater import 'package:zhiying_base_widget/widgets/wallet/wallet_data/wallet_data.dart'; import 'package:zhiying_base_widget/widgets/wallet/wallet_detail/wallet_detail.dart'; import 'package:zhiying_base_widget/widgets/wallet/wallet_income/wallet_income.dart'; -import 'package:zhiying_comm/zhiying_comm.dart'; import 'package:zhiying_comm/util/defalut_widget_creater.dart'; - +import 'package:zhiying_comm/zhiying_comm.dart'; class BaseWidgetRegister { /// 初始化方法 @@ -52,6 +51,7 @@ class BaseWidgetRegister { // /// 可滚动banner WidgetFactory.regist('index_carousel', HomeSlideBannerCreater()); WidgetFactory.regist('index_recommend_list', GoodsListCreater()); + /// 首页快速入口 WidgetFactory.regist('home_quick_entry', HomeQuickEntryCreater()); // @@ -64,17 +64,26 @@ class BaseWidgetRegister { // ==================== 个人中心 WidgetFactory.regist('profile_appbar', MineNavCreater()); - WidgetFactory.regist('profile_background', DefaultWidgetCreater((model) => MineNavBg(model))); - WidgetFactory.regist('profile_header', DefaultWidgetCreater((model) => MineHeader(model))); - WidgetFactory.regist('profile_earning', DefaultWidgetCreater((model) => MineData())); - WidgetFactory.regist('profile_functions', DefaultWidgetCreater((model) => MineQuickEntry())); - WidgetFactory.regist('profile_my_functions', DefaultWidgetCreater((model) => MineQuickEntry())); - WidgetFactory.regist('profile_carousel', DefaultWidgetCreater((model) => HomeBannerWidget(model))); + WidgetFactory.regist('profile_background', + DefaultWidgetCreater((model) => MineNavBg(model))); + WidgetFactory.regist( + 'profile_header', DefaultWidgetCreater((model) => MineHeader(model))); + WidgetFactory.regist( + 'profile_earning', DefaultWidgetCreater((model) => MineData(model))); + WidgetFactory.regist( + 'profile_functions', DefaultWidgetCreater((model) => MineQuickEntry())); + WidgetFactory.regist('profile_my_functions', + DefaultWidgetCreater((model) => MineQuickEntry())); + WidgetFactory.regist('profile_carousel', + DefaultWidgetCreater((model) => HomeBannerWidget(model))); // ==================== 钱包 - WidgetFactory.regist('wallet_data', DefaultWidgetCreater((model) => WalletData())); - WidgetFactory.regist('wallet_detail', DefaultWidgetCreater((model) => WalletDetail())); + WidgetFactory.regist( + 'wallet_data', DefaultWidgetCreater((model) => WalletData())); + WidgetFactory.regist( + 'wallet_detail', DefaultWidgetCreater((model) => WalletDetail())); - WidgetFactory.regist('wallet_income', DefaultWidgetCreater((model) => WalletIncome())); + WidgetFactory.regist( + 'wallet_income', DefaultWidgetCreater((model) => WalletIncome())); } } diff --git a/lib/widgets/mine/mine_data/mine_data.dart b/lib/widgets/mine/mine_data/mine_data.dart index b24b94c..3fdd90a 100644 --- a/lib/widgets/mine/mine_data/mine_data.dart +++ b/lib/widgets/mine/mine_data/mine_data.dart @@ -1,7 +1,15 @@ import 'package:flutter/material.dart'; import 'package:zhiying_base_widget/widgets/mine/mine_data/mine_data_sk.dart'; +import 'package:zhiying_base_widget/widgets/mine/mine_data/mine_data_widget.dart'; +import 'package:zhiying_base_widget/widgets/mine/mine_header/mine_header_bloc.dart'; +import 'package:zhiying_base_widget/widgets/mine/mine_header/model/mine_profile_model.dart'; +import 'package:zhiying_comm/util/base_bloc.dart'; class MineData extends StatefulWidget { + final Map data; + + const MineData(this.data, {Key key}) : super(key: key); + @override _MineDataState createState() => _MineDataState(); } @@ -9,6 +17,41 @@ class MineData extends StatefulWidget { class _MineDataState extends State { @override Widget build(BuildContext context) { - return MineDataSkeleton(); + return BlocProvider( + bloc: MineHeaderBloc(), + child: _MineDataContainer(widget.data), + ); + } +} + +class _MineDataContainer extends StatefulWidget { + final Map data; + + const _MineDataContainer(this.data, {Key key}) : super(key: key); + + @override + _MineDataContainerState createState() => _MineDataContainerState(); +} + +class _MineDataContainerState extends State<_MineDataContainer> { + MineHeaderBloc _bloc; + + @override + void initState() { + _bloc = BlocProvider.of(context); + _bloc.loadData(); + super.initState(); + } + + @override + Widget build(BuildContext context) { + return StreamBuilder( + stream: _bloc.outData, + builder: (BuildContext context, AsyncSnapshot snapshot) { + MineProfileModel profile = snapshot.data; + return profile == null + ? MineDataSkeleton() + : MineDataWidget(profile, widget.data); + }); } } diff --git a/lib/widgets/mine/mine_data/mine_data_creater.dart b/lib/widgets/mine/mine_data/mine_data_creater.dart deleted file mode 100644 index 91cfe8b..0000000 --- a/lib/widgets/mine/mine_data/mine_data_creater.dart +++ /dev/null @@ -1,12 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:zhiying_base_widget/widgets/mine/mine_data/mine_data.dart'; -import 'package:zhiying_comm/zhiying_comm.dart'; - -class MineDataCreater extends WidgetCreater { - @override - List createWidgets(Map model) { - return [ - MineData(), - ]; - } -} diff --git a/lib/widgets/mine/mine_data/mine_data_widget.dart b/lib/widgets/mine/mine_data/mine_data_widget.dart new file mode 100644 index 0000000..15971c4 --- /dev/null +++ b/lib/widgets/mine/mine_data/mine_data_widget.dart @@ -0,0 +1,262 @@ +import 'dart:convert' as convert; + +import 'package:cached_network_image/cached_network_image.dart'; +import 'package:flutter/material.dart'; +import 'package:zhiying_base_widget/widgets/mine/mine_data/model/mine_data_model.dart'; +import 'package:zhiying_base_widget/widgets/mine/mine_header/model/mine_profile_model.dart'; +import 'package:zhiying_comm/zhiying_comm.dart'; + +class MineDataWidget extends StatelessWidget { + final Map data; + final MineProfileModel profile; + Map _json; + MineDataModel _style; + + MineDataWidget( + this.profile, + this.data, { + Key key, + }) : super(key: key) { + String d = data['data']; + _json = convert.jsonDecode(d); + _style = MineDataModel.fromJson(Map.from(_json)); + } + + @override + Widget build(BuildContext context) { + return Container( + margin: EdgeInsets.only(left: 12.5, right: 12.5), + decoration: BoxDecoration( + color: HexColor.fromHex(_style.gridViewBgColor), + borderRadius: BorderRadius.circular(7.5)), + child: Column( + children: [ + _createTop(context), + _createCenter(), + ], + ), + ); + } + + Widget _createTop(BuildContext context) { + return Container( + width: double.infinity, + height: 62, + child: Stack( + children: [ + Container( + width: double.infinity, + height: double.infinity, + child: ClipRRect( + borderRadius: BorderRadius.only( + topLeft: Radius.circular(7.5), + topRight: Radius.circular(7.5)), + child: CachedNetworkImage( + imageUrl: _style.accumulatedEarningsBgImg, + fit: BoxFit.cover, + ), + ), + ), + Container( + width: double.infinity, + height: double.infinity, + child: Row( + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + Expanded( + child: Container( + margin: EdgeInsets.only(left: 15, right: 15), + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + '累计收益', + style: TextStyle( + fontSize: 11, + fontWeight: FontWeight.w600, + color: HexColor.fromHex( + _style.accumulatedEarningsNameColor), + ), + ), + Text( + '${profile.total}', + style: TextStyle( + fontSize: 18, + fontWeight: FontWeight.w800, + color: HexColor.fromHex( + _style.accumulatedEarningsNameColor), + fontFamily: 'Din', + package: 'zhiying_base_widget', + ), + ), + ], + ), + ), + ), + GestureDetector( + child: Container( + margin: EdgeInsets.only(right: 30), + width: 64, + height: 24, + child: Stack( + children: [ + CachedNetworkImage( + imageUrl: _style.btnImg, + fit: BoxFit.cover, + ), + Center( + child: Text( + _style.btnText, + style: TextStyle( + fontSize: 12, + color: HexColor.fromHex(_style.btnTextColor)), + ), + ) + ], + ), + ), + onTap: () { + RouterUtil.route(_json, context); + }, + ) + ], + ), + ) + ], + ), + ); + } + + Widget _createCenter() { + List datas = profile.datas; + int maxColumn = 2; + int row = (datas.length / 2).ceil(); + if (row % 3 == 0) { + maxColumn = 3; + } + List rows = List(); + List columns = List(); + int i = 0; + for (; i < row; i++) { + rows.add( + _createrCenterItem(datas[i].name, datas[i].value), + ); + if (i % maxColumn == maxColumn - 1 || i == row - 1) { + columns.add(Row( + crossAxisAlignment: CrossAxisAlignment.center, + mainAxisAlignment: MainAxisAlignment.center, + children: rows, + )); + rows = List(); + } else { + rows.add(Container( + height: 33, + width: 0.5, + color: HexColor.fromHex('#ebebeb'), + )); + } + } + + if (i < datas.length) { + columns.add(Container( + height: 0.5, + color: HexColor.fromHex('#ebebeb'), + )); + } + + for (; i < datas.length; i++) { + rows.add( + _createBottomItem(datas[i].name, datas[i].value), + ); + if ((i - row) % maxColumn == maxColumn - 1 || + i == row - 1 || + i == datas.length - 1) { + columns.add(Row( + crossAxisAlignment: CrossAxisAlignment.center, + mainAxisAlignment: MainAxisAlignment.center, + children: rows, + )); + rows = List(); + } else { + rows.add(Container( + height: 33, + width: 0.5, + color: HexColor.fromHex('#ebebeb'), + )); + } + } + + return Container( + width: double.infinity, + child: Column( + children: columns, + ), + ); + } + + Widget _createrCenterItem(String name, String value) { + return Expanded( + child: Container( + padding: EdgeInsets.only(left: 15, right: 15), + height: 72, + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + name, + style: TextStyle( + fontSize: 11, + color: HexColor.fromHex(_style.gridViewNameColor)), + ), + Padding( + padding: const EdgeInsets.only(top: 2), + child: Text( + value, + style: TextStyle( + fontSize: 18, + color: HexColor.fromHex(_style.gridViewValueColor), + fontFamily: 'Din', + package: 'zhiying_base_widget'), + ), + ), + ], + ), + ), + ); + } + + Widget _createBottomItem(String name, String value) { + return Expanded( + child: Container( + padding: EdgeInsets.only(left: 15, right: 15), + height: 46, + child: Row( + mainAxisAlignment: MainAxisAlignment.start, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + Text( + name, + style: TextStyle( + fontSize: 12, + color: HexColor.fromHex(_style.gridViewNameColor)), + ), + Padding( + padding: const EdgeInsets.only(left: 2), + child: Text( + value, + style: TextStyle( + fontSize: 12, + color: HexColor.fromHex(_style.gridViewValueColor), + fontFamily: 'Din', + package: 'zhiying_base_widget'), + ), + ), + ], + ), + ), + ); + } +} diff --git a/lib/widgets/mine/mine_data/model/mine_data_model.dart b/lib/widgets/mine/mine_data/model/mine_data_model.dart new file mode 100644 index 0000000..25fd08f --- /dev/null +++ b/lib/widgets/mine/mine_data/model/mine_data_model.dart @@ -0,0 +1,62 @@ +import 'package:json_annotation/json_annotation.dart'; + +part 'mine_data_model.g.dart'; + +@JsonSerializable() +class MineDataModel extends Object { + @JsonKey(name: 'accumulated_earnings_name_color') + String accumulatedEarningsNameColor; + + @JsonKey(name: 'accumulated_earnings_color') + String accumulatedEarningsColor; + + @JsonKey(name: 'accumulated_earnings_bg_img') + String accumulatedEarningsBgImg; + + @JsonKey(name: 'btn_text') + String btnText; + + @JsonKey(name: 'btn_text_color') + String btnTextColor; + + @JsonKey(name: 'btn_img') + String btnImg; + + @JsonKey(name: 'required_login') + String requiredLogin; + + @JsonKey(name: 'required_taobao_auth') + String requiredTaobaoAuth; + + @JsonKey(name: 'skip_identifier') + String skipIdentifier; + + @JsonKey(name: 'grid_view_bg_color') + String gridViewBgColor; + + @JsonKey(name: 'grid_view_name_color') + String gridViewNameColor; + + @JsonKey(name: 'grid_view_value_color') + String gridViewValueColor; + + MineDataModel( + this.accumulatedEarningsNameColor, + this.accumulatedEarningsColor, + this.accumulatedEarningsBgImg, + this.btnText, + this.btnTextColor, + this.btnImg, + this.requiredLogin, + this.requiredTaobaoAuth, + this.skipIdentifier, + this.gridViewBgColor, + this.gridViewNameColor, + this.gridViewValueColor, + ); + + factory MineDataModel.fromJson(Map srcJson) => + _$MineDataModelFromJson(srcJson); + + Map toJson() => _$MineDataModelToJson(this); +} diff --git a/lib/widgets/mine/mine_data/model/mine_data_model.g.dart b/lib/widgets/mine/mine_data/model/mine_data_model.g.dart new file mode 100644 index 0000000..298662b --- /dev/null +++ b/lib/widgets/mine/mine_data/model/mine_data_model.g.dart @@ -0,0 +1,40 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'mine_data_model.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +MineDataModel _$MineDataModelFromJson(Map json) { + return MineDataModel( + json['accumulated_earnings_name_color'] as String, + json['accumulated_earnings_color'] as String, + json['accumulated_earnings_bg_img'] as String, + json['btn_text'] as String, + json['btn_text_color'] as String, + json['btn_img'] as String, + json['required_login'] as String, + json['required_taobao_auth'] as String, + json['skip_identifier'] as String, + json['grid_view_bg_color'] as String, + json['grid_view_name_color'] as String, + json['grid_view_value_color'] as String, + ); +} + +Map _$MineDataModelToJson(MineDataModel instance) => + { + 'accumulated_earnings_name_color': instance.accumulatedEarningsNameColor, + 'accumulated_earnings_color': instance.accumulatedEarningsColor, + 'accumulated_earnings_bg_img': instance.accumulatedEarningsBgImg, + 'btn_text': instance.btnText, + 'btn_text_color': instance.btnTextColor, + 'btn_img': instance.btnImg, + 'required_login': instance.requiredLogin, + 'required_taobao_auth': instance.requiredTaobaoAuth, + 'skip_identifier': instance.skipIdentifier, + 'grid_view_bg_color': instance.gridViewBgColor, + 'grid_view_name_color': instance.gridViewNameColor, + 'grid_view_value_color': instance.gridViewValueColor, + }; diff --git a/lib/widgets/mine/mine_header/mine_header.dart b/lib/widgets/mine/mine_header/mine_header.dart index aeeba5a..b80ada6 100644 --- a/lib/widgets/mine/mine_header/mine_header.dart +++ b/lib/widgets/mine/mine_header/mine_header.dart @@ -1,9 +1,11 @@ -import 'dart:convert' as convert; - -import 'package:cached_network_image/cached_network_image.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; -import 'package:zhiying_base_widget/widgets/mine/mine_header/model/mine_header_model.dart'; +import 'package:provider/provider.dart'; +import 'package:zhiying_base_widget/widgets/mine/mine_header/mine_header_bloc.dart'; +import 'package:zhiying_base_widget/widgets/mine/mine_header/mine_header_container.dart'; +import 'package:zhiying_base_widget/widgets/mine/mine_header/mine_header_sk.dart'; +import 'package:zhiying_base_widget/widgets/mine/mine_header/mine_header_static_container.dart'; +import 'package:zhiying_comm/util/base_bloc.dart'; import 'package:zhiying_comm/zhiying_comm.dart'; class MineHeader extends StatefulWidget { @@ -16,76 +18,34 @@ class MineHeader extends StatefulWidget { } class _MineHeaderState extends State { - @override - Widget build(BuildContext context) { - return _MineContainer(widget.data); - } -} - -class _MineContainer extends StatefulWidget { - final Map data; - Map json; - MineHeaderModel staticModel; - - _MineContainer(this.data, {Key key}) : super(key: key) { - String d = data['data']; - json = convert.jsonDecode(d); - staticModel = MineHeaderModel.fromJson(json); - } + UserInfoModel _user; + bool _isSketelon = true; @override - _MineContainerState createState() => _MineContainerState(); -} + void initState() { + super.initState(); + } -class _MineContainerState extends State<_MineContainer> { @override Widget build(BuildContext context) { - return Container( - child: Row( - children: [ - GestureDetector( - child: Container( - margin: EdgeInsets.only(left: 20, top: 20, bottom: 20, right: 12), - width: 56, - height: 56, - child: ClipRRect( - borderRadius: BorderRadius.circular(28), - child: CachedNetworkImage( - imageUrl: widget.staticModel.defaultAvatar, - fit: BoxFit.cover)), - ), - onTap: () { - RouterUtil.route(widget.json, context); - }, - ), - Expanded( - child: Column( - mainAxisAlignment: MainAxisAlignment.start, - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Container( - width: 120, - height: 20, - child: Text( - widget.staticModel.loginName, - style: TextStyle( - color: HexColor.fromHex(widget.staticModel.loginColor), - fontSize: 17), - ), - ), - Container( - margin: EdgeInsets.only(top: 8), - width: 80, - child: Text( - widget.staticModel.loginNameHelpText, - style: TextStyle( - color: HexColor.fromHex(widget.staticModel.loginColor), - fontSize: 13), - )), - ], - )) - ], - ), + if (_isSketelon) { + Provider.of(context).getUserInfoModel().then((user) { + setState(() { + _user = user; + _isSketelon = false; + }); + }); + } + + if (_isSketelon) { + return MineHeaderSkeleton(); + } + if (_user == null) { + return MineStaticContainer(widget.data); + } + return BlocProvider( + bloc: MineHeaderBloc(), + child: MineHeaderContainer(widget.data), ); } } diff --git a/lib/widgets/mine/mine_header/mine_header_bloc.dart b/lib/widgets/mine/mine_header/mine_header_bloc.dart index 252b4f1..0dcef7f 100644 --- a/lib/widgets/mine/mine_header/mine_header_bloc.dart +++ b/lib/widgets/mine/mine_header/mine_header_bloc.dart @@ -1,37 +1,28 @@ import 'dart:async'; +import 'package:zhiying_base_widget/widgets/mine/mine_header/model/mine_profile_model.dart'; import 'package:zhiying_comm/util/base_bloc.dart'; import 'package:zhiying_comm/zhiying_comm.dart'; class MineHeaderBloc extends BlocBase { - Map _mineData; + MineProfileModel _profile; - StreamController> _mineController = - StreamController>(); + StreamController _profileController = + StreamController(); - Stream> get outData => _mineController.stream; + Stream get outData => _profileController.stream; @override void dispose() { - _mineController.close(); - _mineController = null; + _profileController.close(); + _profileController = null; } - void loadData(int id) { + void loadData() { NetUtil.request('/api/v1/user/profile', - method: NetMethod.POST, - params: Map.from({ - 'ids': [id] - }), - onCache: (data) {}, onSuccess: (data) { - _loadData(id, data); + method: NetMethod.GET, onCache: (data) {}, onSuccess: (data) { + _profile = MineProfileModel.fromJson(Map.from(data)); + _profileController.add(_profile); }); } - - void _loadData(int id, dynamic data) { - String key = id.toString(); - Map json = Map.from(data); - - _mineController.add(_mineData); - } } diff --git a/lib/widgets/mine/mine_header/mine_header_container.dart b/lib/widgets/mine/mine_header/mine_header_container.dart new file mode 100644 index 0000000..fb2f104 --- /dev/null +++ b/lib/widgets/mine/mine_header/mine_header_container.dart @@ -0,0 +1,154 @@ +import 'dart:convert' as convert; + +import 'package:cached_network_image/cached_network_image.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; +import 'package:fluttertoast/fluttertoast.dart'; +import 'package:zhiying_base_widget/widgets/mine/mine_header/mine_header_bloc.dart'; +import 'package:zhiying_base_widget/widgets/mine/mine_header/mine_header_sk.dart'; +import 'package:zhiying_base_widget/widgets/mine/mine_header/model/mine_header_model.dart'; +import 'package:zhiying_base_widget/widgets/mine/mine_header/model/mine_profile_model.dart'; +import 'package:zhiying_comm/util/base_bloc.dart'; +import 'package:zhiying_comm/zhiying_comm.dart'; + +class MineHeaderContainer extends StatefulWidget { + final Map data; + Map json; + MineHeaderModel staticModel; + + MineHeaderContainer(this.data, {Key key}) : super(key: key) { + String d = data['data']; + json = convert.jsonDecode(d); + staticModel = MineHeaderModel.fromJson(json); + } + + @override + _MineHeaderContainerState createState() => _MineHeaderContainerState(); +} + +class _MineHeaderContainerState extends State { + MineHeaderBloc _bloc; + + @override + void initState() { + _bloc = BlocProvider.of(context); + _bloc.loadData(); + super.initState(); + } + + @override + Widget build(BuildContext context) { + return StreamBuilder( + stream: _bloc.outData, + builder: (BuildContext context, AsyncSnapshot snapshot) { + MineProfileModel profile = snapshot.data; + return profile == null + ? MineHeaderSkeleton() + : Row( + children: [ + GestureDetector( + child: Container( + margin: EdgeInsets.only( + left: 20, top: 20, bottom: 20, right: 12), + width: 56, + height: 56, + child: CachedNetworkImage( + imageUrl: profile.avatar, + fit: BoxFit.cover, + ), + ), + onTap: () { + RouterUtil.route(widget.json, context); + }, + ), + Expanded( + child: Container( + margin: EdgeInsets.only(right: 12), + child: Column( + mainAxisAlignment: MainAxisAlignment.start, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Row( + children: [ + Text( + profile.username, + maxLines: 1, + overflow: TextOverflow.ellipsis, + style: TextStyle( + fontSize: 17, + color: HexColor.fromHex( + widget.staticModel.userNameColor)), + ), + Container( + height: 18, + margin: EdgeInsets.only(left: 6), + padding: EdgeInsets.only(left: 6, right: 6), + decoration: BoxDecoration( + color: HexColor.fromHex( + widget.staticModel.lvBgColor), + borderRadius: BorderRadius.circular(9)), + child: Row( + children: [ + Container( + width: 12, + height: 12, + margin: EdgeInsets.only(right: 2), + child: CachedNetworkImage( + imageUrl: profile.userLvIcon, + fit: BoxFit.contain, + ), + ), + Text( + profile.userLvName, + style: TextStyle( + fontSize: 10, + color: HexColor.fromHex( + widget.staticModel.lvNameColor)), + ) + ], + ), + ), + ], + ), + GestureDetector( + child: Container( + margin: EdgeInsets.only(top: 8), + child: Row( + children: [ + Text( + '邀请码:${profile.inviteCode}', + maxLines: 1, + style: TextStyle( + fontSize: 13, + color: HexColor.fromHex( + widget.staticModel.userNameColor), + fontFamily: 'Din', + package: 'zhiying_base_widget', + ), + ), + Container( + width: 12, + height: 12, + margin: EdgeInsets.only(left: 2), + child: CachedNetworkImage( + imageUrl: widget.staticModel.coypeIcon, + fit: BoxFit.contain, + ), + ), + ], + ), + ), + onTap: () { + Fluttertoast.showToast(msg: '复制成功'); + Clipboard.setData( + ClipboardData(text: profile.inviteCode)); + }, + ), + ], + ), + )) + ], + ); + }); + } +} diff --git a/lib/widgets/mine/mine_header/mine_header_static_container.dart b/lib/widgets/mine/mine_header/mine_header_static_container.dart new file mode 100644 index 0000000..ab68694 --- /dev/null +++ b/lib/widgets/mine/mine_header/mine_header_static_container.dart @@ -0,0 +1,77 @@ +import 'package:flutter/material.dart'; +import 'package:zhiying_base_widget/widgets/mine/mine_header/model/mine_header_model.dart'; +import 'package:zhiying_comm/zhiying_comm.dart'; + +import 'package:cached_network_image/cached_network_image.dart'; +import 'dart:convert' as convert; + +// 未登录状态个人中心头部 +class MineStaticContainer extends StatefulWidget { + final Map data; + Map json; + MineHeaderModel staticModel; + + MineStaticContainer(this.data, {Key key}) : super(key: key) { + String d = data['data']; + json = convert.jsonDecode(d); + staticModel = MineHeaderModel.fromJson(json); + } + + @override + _MineStaticContainerState createState() => _MineStaticContainerState(); +} + +class _MineStaticContainerState extends State { + @override + Widget build(BuildContext context) { + return Container( + child: Row( + children: [ + GestureDetector( + child: Container( + margin: EdgeInsets.only(left: 20, top: 20, bottom: 20, right: 12), + width: 56, + height: 56, + child: ClipRRect( + borderRadius: BorderRadius.circular(28), + child: CachedNetworkImage( + imageUrl: widget.staticModel.defaultAvatar, + fit: BoxFit.cover)), + ), + onTap: () { + RouterUtil.route(widget.json, context); + }, + ), + Expanded( + child: Column( + mainAxisAlignment: MainAxisAlignment.start, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Container( + width: 120, + height: 20, + child: Text( + widget.staticModel.loginName, + style: TextStyle( + color: HexColor.fromHex( + widget.staticModel.loginColor), + fontSize: 17), + ), + ), + Container( + margin: EdgeInsets.only(top: 8), + width: 80, + child: Text( + widget.staticModel.loginNameHelpText, + style: TextStyle( + color: HexColor.fromHex( + widget.staticModel.loginColor), + fontSize: 13), + )), + ], + )) + ], + ), + ); + } +} diff --git a/lib/widgets/mine/mine_header/model/mine_header_model.dart b/lib/widgets/mine/mine_header/model/mine_header_model.dart index eacedce..abe240b 100644 --- a/lib/widgets/mine/mine_header/model/mine_header_model.dart +++ b/lib/widgets/mine/mine_header/model/mine_header_model.dart @@ -4,6 +4,12 @@ part 'mine_header_model.g.dart'; @JsonSerializable() class MineHeaderModel extends Object { + @JsonKey(name: 'lv_bg_color') + String lvBgColor; + + @JsonKey(name: 'lv_name_color') + String lvNameColor; + @JsonKey(name: 'non_login_avatar') String defaultAvatar; diff --git a/lib/widgets/mine/mine_header/model/mine_header_model.g.dart b/lib/widgets/mine/mine_header/model/mine_header_model.g.dart index cc9b39b..6d34a76 100644 --- a/lib/widgets/mine/mine_header/model/mine_header_model.g.dart +++ b/lib/widgets/mine/mine_header/model/mine_header_model.g.dart @@ -19,11 +19,15 @@ MineHeaderModel _$MineHeaderModelFromJson(Map json) { json['required_login'] as String, json['required_taobao_auth'] as String, json['skip_identifier'] as String, - ); + ) + ..lvBgColor = json['lv_bg_color'] as String + ..lvNameColor = json['lv_name_color'] as String; } Map _$MineHeaderModelToJson(MineHeaderModel instance) => { + 'lv_bg_color': instance.lvBgColor, + 'lv_name_color': instance.lvNameColor, 'non_login_avatar': instance.defaultAvatar, 'user_name_color': instance.userNameColor, 'invited_code_text': instance.invitedCodeText, diff --git a/lib/widgets/mine/mine_header/model/mine_profile_model.dart b/lib/widgets/mine/mine_header/model/mine_profile_model.dart new file mode 100644 index 0000000..0f06e1e --- /dev/null +++ b/lib/widgets/mine/mine_header/model/mine_profile_model.dart @@ -0,0 +1,57 @@ +import 'package:json_annotation/json_annotation.dart'; + +part 'mine_profile_model.g.dart'; + +@JsonSerializable() +class MineProfileModel extends Object { + @JsonKey(name: 'username') + String username; + + @JsonKey(name: 'avatar') + String avatar; + + @JsonKey(name: 'InviteCode') + String inviteCode; + + @JsonKey(name: 'user_lv_name') + String userLvName; + + @JsonKey(name: 'user_lv_icon') + String userLvIcon; + + @JsonKey(name: 'total') + String total; + + @JsonKey(name: 'grid_views') + List datas; + + MineProfileModel(this.username, + this.avatar, + this.inviteCode, + this.userLvName, + this.userLvIcon, + this.total, + this.datas,); + + factory MineProfileModel.fromJson(Map srcJson) => + _$MineProfileModelFromJson(srcJson); + + Map toJson() => _$MineProfileModelToJson(this); +} + +@JsonSerializable() +class MineProfileDataModel extends Object { + @JsonKey(name: 'name') + String name; + + @JsonKey(name: 'value') + String value; + + MineProfileDataModel(this.name, + this.value,); + + factory MineProfileDataModel.fromJson(Map srcJson) => + _$MineProfileDataModelFromJson(srcJson); + + Map toJson() => _$MineProfileDataModelToJson(this); +} diff --git a/lib/widgets/mine/mine_header/model/mine_profile_model.g.dart b/lib/widgets/mine/mine_header/model/mine_profile_model.g.dart new file mode 100644 index 0000000..aef0889 --- /dev/null +++ b/lib/widgets/mine/mine_header/model/mine_profile_model.g.dart @@ -0,0 +1,48 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'mine_profile_model.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +MineProfileModel _$MineProfileModelFromJson(Map json) { + return MineProfileModel( + json['username'] as String, + json['avatar'] as String, + json['InviteCode'] as String, + json['user_lv_name'] as String, + json['user_lv_icon'] as String, + json['total'] as String, + (json['grid_views'] as List) + ?.map((e) => e == null + ? null + : MineProfileDataModel.fromJson(e as Map)) + ?.toList(), + ); +} + +Map _$MineProfileModelToJson(MineProfileModel instance) => + { + 'username': instance.username, + 'avatar': instance.avatar, + 'InviteCode': instance.inviteCode, + 'user_lv_name': instance.userLvName, + 'user_lv_icon': instance.userLvIcon, + 'total': instance.total, + 'grid_views': instance.datas, + }; + +MineProfileDataModel _$MineProfileDataModelFromJson(Map json) { + return MineProfileDataModel( + json['name'] as String, + json['value'] as String, + ); +} + +Map _$MineProfileDataModelToJson( + MineProfileDataModel instance) => + { + 'name': instance.name, + 'value': instance.value, + }; diff --git a/lib/widgets/mine/mine_nav/mine_nav.dart b/lib/widgets/mine/mine_nav/mine_nav.dart index c8b14da..eff9c3c 100644 --- a/lib/widgets/mine/mine_nav/mine_nav.dart +++ b/lib/widgets/mine/mine_nav/mine_nav.dart @@ -26,19 +26,7 @@ class MineNavDelegate extends SliverPersistentHeaderDelegate { List icons = json['app_bar_icons']; _icons = icons.map((icon) { SkipModel model = SkipModel.fromJson(Map.from(icon)); - return GestureDetector( - child: Container( - width: 24, - height: 24, - margin: EdgeInsets.only(left: 6), - child: CachedNetworkImage( - imageUrl: model.icon, - ), - ), - onTap: () { - print('页面跳转 ${model.skipIdentifier}'); - }, - ); + return MineNavIcon(model, json); }).toList(); } } @@ -88,3 +76,28 @@ class MineNav extends StatelessWidget { )); } } + +class MineNavIcon extends StatelessWidget { + final SkipModel model; + final Map data; + + const MineNavIcon(this.model, this.data, {Key key}) : super(key: key); + + @override + Widget build(BuildContext context) { + return GestureDetector( + child: Container( + width: 24, + height: 24, + margin: EdgeInsets.only(left: 6), + child: CachedNetworkImage( + imageUrl: model.icon, + ), + ), + onTap: () { + print('页面跳转 ${model.skipIdentifier}'); + RouterUtil.route(data, context); + }, + ); + } +}