From 16f7349c338cc071563d3c9ed5a10f1323255ab2 Mon Sep 17 00:00:00 2001 From: Weller <1812208341@qq.com> Date: Thu, 17 Sep 2020 20:32:57 +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?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .dart_tool/package_config.json | 2 +- .../mine_detail_page/mine_detail_page.dart | 3 + lib/pages/setting_page/setting_page.dart | 17 ++++ lib/register.dart | 33 +++++--- lib/widgets/mine/mine_data/mine_data.dart | 77 +++++++++++-------- .../mine/mine_data/mine_data_container.dart | 38 +++++++++ .../mine/mine_data/model/mine_data_model.dart | 5 ++ .../mine_data/model/mine_data_model.g.dart | 6 ++ lib/widgets/mine/mine_header/mine_header.dart | 16 +--- .../mine_header/mine_header_container.dart | 5 +- 10 files changed, 140 insertions(+), 62 deletions(-) create mode 100644 lib/pages/setting_page/setting_page.dart create mode 100644 lib/widgets/mine/mine_data/mine_data_container.dart diff --git a/.dart_tool/package_config.json b/.dart_tool/package_config.json index fbcec99..594b302 100644 --- a/.dart_tool/package_config.json +++ b/.dart_tool/package_config.json @@ -710,7 +710,7 @@ "languageVersion": "2.1" } ], - "generated": "2020-09-17T03:20:15.312540Z", + "generated": "2020-09-17T12:08:09.612292Z", "generator": "pub", "generatorVersion": "2.7.2" } diff --git a/lib/pages/mine_detail_page/mine_detail_page.dart b/lib/pages/mine_detail_page/mine_detail_page.dart index c48e487..73ea51c 100644 --- a/lib/pages/mine_detail_page/mine_detail_page.dart +++ b/lib/pages/mine_detail_page/mine_detail_page.dart @@ -94,6 +94,9 @@ class _MineDetailContainerState extends State<_MineDetailContainer> { stream: _bloc.outData, builder: (BuildContext context, AsyncSnapshot snapshot) { MineDetailModel user = snapshot.data; + if (user == null) { + return Container(); + } int birthday = int.tryParse(user?.birthday) ?? 0; int registTime = int.tryParse(user?.registerTime) ?? 0; _nickController.text = user?.nickname ?? ''; diff --git a/lib/pages/setting_page/setting_page.dart b/lib/pages/setting_page/setting_page.dart new file mode 100644 index 0000000..4425023 --- /dev/null +++ b/lib/pages/setting_page/setting_page.dart @@ -0,0 +1,17 @@ +import 'package:flutter/material.dart'; + +class SettingPage extends StatefulWidget { + final Map data; + + const SettingPage(this.data, {Key key}) : super(key: key); + + @override + _SettingPageState createState() => _SettingPageState(); +} + +class _SettingPageState extends State { + @override + Widget build(BuildContext context) { + return Scaffold(); + } +} diff --git a/lib/register.dart b/lib/register.dart index 341337d..1202d8a 100644 --- a/lib/register.dart +++ b/lib/register.dart @@ -1,6 +1,7 @@ import 'package:zhiying_base_widget/pages/home_page/home_page.dart'; import 'package:zhiying_base_widget/pages/main_page/main_page.dart'; import 'package:zhiying_base_widget/pages/mine_detail_page/mine_detail_page.dart'; +import 'package:zhiying_base_widget/pages/setting_page/setting_page.dart'; import 'package:zhiying_base_widget/pages/wallet_page/wallet_page.dart'; import 'package:zhiying_base_widget/widgets/home/home_banner/home_banner_creater.dart'; import 'package:zhiying_base_widget/widgets/home/home_banner/home_banner_widget.dart'; @@ -20,7 +21,6 @@ import 'package:zhiying_comm/zhiying_comm.dart'; import 'widgets/home/home_quick_entry/home_quick_entry.dart'; - class BaseWidgetRegister { /// 初始化方法 static void init() { @@ -41,6 +41,7 @@ class BaseWidgetRegister { PageFactory.regist( 'pub.flutter.profile_settings', (model) => MineDetailPage()); + PageFactory.regist('pub.flutter.settings', (model) => SettingPage(model)); } // 注册控件 @@ -58,7 +59,8 @@ class BaseWidgetRegister { WidgetFactory.regist('index_carousel', HomeSlideBannerCreater()); WidgetFactory.regist('index_recommend_list', GoodsListCreater()); // /// 首页快速入口 - WidgetFactory.regist('multi_nav', DefaultWidgetCreater((model) => HomeQuickEntry(model))); + WidgetFactory.regist( + 'multi_nav', DefaultWidgetCreater((model) => HomeQuickEntry(model))); // // /// 不可以滚动banner WidgetFactory.regist('index_banner_one', HomeBannerCreater()); @@ -66,17 +68,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(model))); - WidgetFactory.regist('profile_functions', DefaultWidgetCreater((model) => MineQuickEntry(model))); - WidgetFactory.regist('profile_my_functions', DefaultWidgetCreater((model) => MineQuickEntry(model))); - 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(model))); + WidgetFactory.regist('profile_my_functions', + DefaultWidgetCreater((model) => MineQuickEntry(model))); + 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 3fdd90a..5917327 100644 --- a/lib/widgets/mine/mine_data/mine_data.dart +++ b/lib/widgets/mine/mine_data/mine_data.dart @@ -1,9 +1,15 @@ +import 'dart:convert' as convert; + import 'package:flutter/material.dart'; +import 'package:provider/provider.dart'; +import 'package:zhiying_base_widget/widgets/mine/mine_data/mine_data_container.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_data/model/mine_data_model.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'; +import 'package:zhiying_comm/zhiying_comm.dart'; class MineData extends StatefulWidget { final Map data; @@ -15,43 +21,48 @@ class MineData extends StatefulWidget { } class _MineDataState extends State { + UserInfoModel _user; + bool _isSketelon = true; + @override Widget build(BuildContext context) { + if (_isSketelon) { + Provider.of(context).getUserInfoModel().then((user) { + setState(() { + _user = user; + _isSketelon = false; + }); + }); + } + + if (_isSketelon) { + return MineDataSkeleton(); + } + if (_user == null) { + String value = '123'; + int result = int.tryParse(value); + + // 未登录 + String d = widget.data['data']; + Map json = convert.jsonDecode(d); + MineDataModel style = + MineDataModel.fromJson(Map.from(json)); + MineProfileModel profile = MineProfileModel( + '', + '', + '', + '', + '', + '¥0', + style.datas.map((item) { + return MineProfileDataModel(item.name, '¥0'); + }).toList(), + ); + return MineDataWidget(profile, widget.data); + } return BlocProvider( bloc: MineHeaderBloc(), - child: _MineDataContainer(widget.data), + 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_container.dart b/lib/widgets/mine/mine_data/mine_data_container.dart new file mode 100644 index 0000000..4e36668 --- /dev/null +++ b/lib/widgets/mine/mine_data/mine_data_container.dart @@ -0,0 +1,38 @@ +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 MineDataContainer extends StatefulWidget { + final Map data; + + const MineDataContainer(this.data, {Key key}) : super(key: key); + + @override + _MineDataContainerState createState() => _MineDataContainerState(); +} + +class _MineDataContainerState 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 + ? MineDataSkeleton() + : MineDataWidget(profile, widget.data); + }); + } +} diff --git a/lib/widgets/mine/mine_data/model/mine_data_model.dart b/lib/widgets/mine/mine_data/model/mine_data_model.dart index 25fd08f..6db6567 100644 --- a/lib/widgets/mine/mine_data/model/mine_data_model.dart +++ b/lib/widgets/mine/mine_data/model/mine_data_model.dart @@ -1,4 +1,5 @@ import 'package:json_annotation/json_annotation.dart'; +import 'package:zhiying_base_widget/widgets/mine/mine_header/model/mine_profile_model.dart'; part 'mine_data_model.g.dart'; @@ -40,6 +41,9 @@ class MineDataModel extends Object { @JsonKey(name: 'grid_view_value_color') String gridViewValueColor; + @JsonKey(name: 'grid_view') + List datas; + MineDataModel( this.accumulatedEarningsNameColor, this.accumulatedEarningsColor, @@ -53,6 +57,7 @@ class MineDataModel extends Object { this.gridViewBgColor, this.gridViewNameColor, this.gridViewValueColor, + this.datas, ); factory MineDataModel.fromJson(Map srcJson) => 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 index 298662b..a3c4fa7 100644 --- a/lib/widgets/mine/mine_data/model/mine_data_model.g.dart +++ b/lib/widgets/mine/mine_data/model/mine_data_model.g.dart @@ -20,6 +20,11 @@ MineDataModel _$MineDataModelFromJson(Map json) { json['grid_view_bg_color'] as String, json['grid_view_name_color'] as String, json['grid_view_value_color'] as String, + (json['grid_view'] as List) + ?.map((e) => e == null + ? null + : MineProfileDataModel.fromJson(e as Map)) + ?.toList(), ); } @@ -37,4 +42,5 @@ Map _$MineDataModelToJson(MineDataModel instance) => 'grid_view_bg_color': instance.gridViewBgColor, 'grid_view_name_color': instance.gridViewNameColor, 'grid_view_value_color': instance.gridViewValueColor, + 'grid_view': instance.datas, }; diff --git a/lib/widgets/mine/mine_header/mine_header.dart b/lib/widgets/mine/mine_header/mine_header.dart index bcf0108..902e16d 100644 --- a/lib/widgets/mine/mine_header/mine_header.dart +++ b/lib/widgets/mine/mine_header/mine_header.dart @@ -21,23 +21,8 @@ class _MineHeaderState extends State { UserInfoModel _user; bool _isSketelon = true; - @override - void initState() { - super.initState(); - } - @override Widget build(BuildContext context) { -// return Consumer(builder: (context, user, child) { -// print('user ${user.toString()}'); -// if (user == null) { -// return MineStaticContainer(widget.data); -// } -// return BlocProvider( -// bloc: MineHeaderBloc(), -// child: MineHeaderContainer(widget.data), -// ); -// }); if (_isSketelon) { Provider.of(context).getUserInfoModel().then((user) { setState(() { @@ -51,6 +36,7 @@ class _MineHeaderState extends State { return MineHeaderSkeleton(); } if (_user == null) { + // 未登录 return MineStaticContainer(widget.data); } return BlocProvider( diff --git a/lib/widgets/mine/mine_header/mine_header_container.dart b/lib/widgets/mine/mine_header/mine_header_container.dart index e742c4c..b6323b7 100644 --- a/lib/widgets/mine/mine_header/mine_header_container.dart +++ b/lib/widgets/mine/mine_header/mine_header_container.dart @@ -63,8 +63,9 @@ class _MineHeaderContainerState extends State { ), ), ), - onTap: () { - RouterUtil.route(widget.json, context); + onTap: () async { + await RouterUtil.route(widget.json, context); + _bloc.loadData(); }, ), Expanded(