From 6c70123e033dfc45b4cf39befa789f7814b9510b Mon Sep 17 00:00:00 2001 From: Weller <1812208341@qq.com> Date: Fri, 11 Sep 2020 19:55:41 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E9=A1=B5=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .dart_tool/package_config.json | 2 +- lib/pages/home_page/home_page_bloc.dart | 21 ++++--- lib/pages/main_page/main_page.dart | 61 +++++++++---------- lib/pages/main_page/main_page_bloc.dart | 38 ++++++++---- lib/register.dart | 21 ++++++- lib/widgets/mine/mine_header/mine_header.dart | 28 +++++++-- .../mine/mine_header/mine_header_bloc.dart | 37 +++++++++++ .../mine/mine_header/mine_header_creater.dart | 12 ---- lib/widgets/mine/mine_nav/mine_nav.dart | 54 +++++++++++----- lib/widgets/mine/mine_nav/mine_nav_bg.dart | 44 +++++++++++++ .../mine/mine_nav/mine_nav_creater.dart | 2 +- lib/widgets/mine/mine_nav/mine_nav_sk.dart | 0 .../mine_quick_entry_creater.dart | 12 ---- lib/widgets/others/mine_header_bg_widget.dart | 43 ------------- 14 files changed, 234 insertions(+), 141 deletions(-) create mode 100644 lib/widgets/mine/mine_header/mine_header_bloc.dart delete mode 100644 lib/widgets/mine/mine_header/mine_header_creater.dart create mode 100644 lib/widgets/mine/mine_nav/mine_nav_bg.dart delete mode 100644 lib/widgets/mine/mine_nav/mine_nav_sk.dart delete mode 100644 lib/widgets/mine/mine_quick_entry/mine_quick_entry_creater.dart diff --git a/.dart_tool/package_config.json b/.dart_tool/package_config.json index 2573ab5..69f77f3 100644 --- a/.dart_tool/package_config.json +++ b/.dart_tool/package_config.json @@ -680,7 +680,7 @@ "languageVersion": "2.1" } ], - "generated": "2020-09-10T07:09:00.863118Z", + "generated": "2020-09-11T04:26:30.812379Z", "generator": "pub", "generatorVersion": "2.7.2" } diff --git a/lib/pages/home_page/home_page_bloc.dart b/lib/pages/home_page/home_page_bloc.dart index db348fc..4f2d133 100644 --- a/lib/pages/home_page/home_page_bloc.dart +++ b/lib/pages/home_page/home_page_bloc.dart @@ -1,13 +1,14 @@ import 'dart:async'; -import 'package:zhiying_comm/zhiying_comm.dart'; import 'package:zhiying_comm/util/base_bloc.dart'; +import 'package:zhiying_comm/zhiying_comm.dart'; class HomePageBloc extends BlocBase { List> _tabs = List(); StreamController>> _tabController = StreamController>>(); + Stream>> get outData => _tabController.stream; @override @@ -17,12 +18,18 @@ class HomePageBloc extends BlocBase { } void refresh() { - NetUtil.request('/api/v1/config.json', onSuccess: (data) { - List list = data; - _tabs = list.map((item) { - return Map.from(item); - }).toList(); - _tabController.add(_tabs); + NetUtil.request('/api/v1/config.json', onCache: (data) { + _refresh(data); + }, onSuccess: (data) { + _refresh(data); }); } + + void _refresh(dynamic data) { + List list = data; + _tabs = list.map((item) { + return Map.from(item); + }).toList(); + _tabController.add(_tabs); + } } diff --git a/lib/pages/main_page/main_page.dart b/lib/pages/main_page/main_page.dart index 1a7af63..6b458e6 100644 --- a/lib/pages/main_page/main_page.dart +++ b/lib/pages/main_page/main_page.dart @@ -71,6 +71,10 @@ class _MainPageContainerState extends State<_MainPageContainer> { @override void initState() { _bloc = BlocProvider.of(context); + if (widget.data.containsKey('mod_id')) { + _bloc.loadData(widget.data['mod_id']); + } + _controller.addListener(() { // print('${_controller.offset} ${_controller.position.maxScrollExtent}'); if (_controller.offset >= _controller.position.maxScrollExtent && @@ -89,21 +93,21 @@ class _MainPageContainerState extends State<_MainPageContainer> { @override Widget build(BuildContext context) { - return StreamBuilder>( - stream: _bloc.outData, - builder: (BuildContext context, AsyncSnapshot snapshot) { - return MediaQuery.removePadding( - removeTop: true, - context: context, - child: SmartRefresher( - enablePullDown: false, - enablePullUp: false, - header: WaterDropHeader(), - controller: _refreshController, - onLoading: _onLoading, - child: Container( - width: double.infinity, - child: Stack( + return MediaQuery.removePadding( + removeTop: true, + context: context, + child: SmartRefresher( + enablePullDown: false, + enablePullUp: false, + header: WaterDropHeader(), + controller: _refreshController, + onLoading: _onLoading, + child: Container( + width: double.infinity, + child: StreamBuilder>>( + stream: _bloc.outData, + builder: (BuildContext context, AsyncSnapshot snapshot) { + return Stack( fit: StackFit.passthrough, children: [ MineHeaderBgWidget( @@ -111,34 +115,29 @@ class _MainPageContainerState extends State<_MainPageContainer> { ), CustomScrollView( controller: _controller, - slivers: _createContent(context), + slivers: _createContent(context, snapshot.data ?? []), ) ], - ), - ), - )); - }, + ); + }, + ), + )), ); } - List _createContent(BuildContext context) { - WidgetModel model = WidgetModel.fromJson(widget.data); - + List _createContent( + BuildContext context, List> datas) { List list = List(); - for (int i = 0; i < model.components.length; i++) { - WidgetModel item = model.components[i]; - Map data = Map(); - if (widget.data.containsKey('components')) { - data = widget.data['components'][i]; - } + for (int i = 0; i < datas.length; i++) { + WidgetModel item = + WidgetModel.fromJson(Map.from(datas[i])); list.addAll(WidgetFactory.create( item.modName, isSliver: true, - model: data, + model: datas[i], )); } - model.components.forEach((item) {}); return list; } } diff --git a/lib/pages/main_page/main_page_bloc.dart b/lib/pages/main_page/main_page_bloc.dart index 0cda2f5..21f14c9 100644 --- a/lib/pages/main_page/main_page_bloc.dart +++ b/lib/pages/main_page/main_page_bloc.dart @@ -1,14 +1,15 @@ import 'dart:async'; -import 'package:zhiying_comm/zhiying_comm.dart'; import 'package:zhiying_comm/util/base_bloc.dart'; +import 'package:zhiying_comm/zhiying_comm.dart'; class MainPageBloc extends BlocBase { - Map _mains = Map(); + List> _pageData = List(); - StreamController> _mainController = - StreamController>(); - Stream> get outData => _mainController.stream; + StreamController>> _mainController = + StreamController>>(); + + Stream>> get outData => _mainController.stream; @override void dispose() { @@ -16,13 +17,28 @@ class MainPageBloc extends BlocBase { _mainController = null; } - void loadData(List ids) { - NetUtil.request('/api/v1/config.json', onSuccess: (data) { - List list = data; - List> tabs = list.map((item) { + void loadData(int id) { + NetUtil.request('/api/v1/mod', + method: NetMethod.POST, + params: Map.from({ + 'ids': [id] + }), onCache: (data) { + _loadData(id, data); + }, onSuccess: (data) { + _loadData(id, data); + }); + } + + void _loadData(int id, dynamic data) { + String key = id.toString(); + Map json = Map.from(data); + if (json.containsKey(key)) { + List list = json[key]; + _pageData = list.map((item) { return Map.from(item); }).toList(); - _mainController.add(tabs.first); - }); + } + + _mainController.add(_pageData); } } diff --git a/lib/register.dart b/lib/register.dart index b14d4ff..95794de 100644 --- a/lib/register.dart +++ b/lib/register.dart @@ -1,12 +1,16 @@ import 'package:zhiying_base_widget/pages/home_page/home_page.dart'; -import 'package:zhiying_base_widget/pages/login_page/login_page.dart'; import 'package:zhiying_base_widget/pages/main_page/main_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'; import 'package:zhiying_base_widget/widgets/home/home_goods/home_goods_creater.dart'; import 'package:zhiying_base_widget/widgets/home/home_quick_entry/home_quick_entry_creater.dart'; import 'package:zhiying_base_widget/widgets/home/home_slide_banner/home_slide_banner_creater.dart'; +import 'package:zhiying_base_widget/widgets/mine/mine_data/mine_data.dart'; import 'package:zhiying_base_widget/widgets/mine/mine_header/mine_header.dart'; +import 'package:zhiying_base_widget/widgets/mine/mine_nav/mine_nav_bg.dart'; +import 'package:zhiying_base_widget/widgets/mine/mine_nav/mine_nav_creater.dart'; +import 'package:zhiying_base_widget/widgets/mine/mine_quick_entry/mine_quick_entry.dart'; import 'package:zhiying_base_widget/widgets/others/normal_nav/normal_nav_creater.dart'; import 'package:zhiying_base_widget/widgets/wallet/wallet_data/wallet_data.dart'; import 'package:zhiying_base_widget/widgets/wallet/wallet_detail/wallet_detail.dart'; @@ -24,7 +28,7 @@ class BaseWidgetRegister { static void registPage() { PageFactory.regist('homePage', (model) => HomePage()); PageFactory.regist('index', (model) => MainPage(model)); - PageFactory.regist('login', (model) => LoginPage(model)); + PageFactory.regist('profile', (model) => MainPage(model)); PageFactory.regist('category', (model) => WalletPage()); } @@ -49,8 +53,19 @@ class BaseWidgetRegister { WidgetFactory.regist('index_banner_two', HomeBannerCreater()); // ==================== 个人中心 + WidgetFactory.regist('profile_appbar', MineNavCreater()); + WidgetFactory.regist('profile_background', + DefaultWidgetCreater((model) => MineNavBg(model))); WidgetFactory.regist( - 'index_title', DefaultWidgetCreater((model) => MineHeader())); + '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( diff --git a/lib/widgets/mine/mine_header/mine_header.dart b/lib/widgets/mine/mine_header/mine_header.dart index 2114779..21e276a 100644 --- a/lib/widgets/mine/mine_header/mine_header.dart +++ b/lib/widgets/mine/mine_header/mine_header.dart @@ -3,12 +3,30 @@ import 'package:flutter/material.dart'; import 'mine_header_sk.dart'; -class MineHeader extends StatelessWidget { +class MineHeader extends StatefulWidget { + final Map data; + + const MineHeader(this.data, {Key key}) : super(key: key); + + @override + _MineHeaderState createState() => _MineHeaderState(); +} + +class _MineHeaderState extends State { + @override + Widget build(BuildContext context) { + return _MineContainer(); + } +} + +class _MineContainer extends StatefulWidget { + @override + _MineContainerState createState() => _MineContainerState(); +} + +class _MineContainerState extends State<_MineContainer> { @override Widget build(BuildContext context) { - return Container( - width: double.infinity, - child: MineHeaderSkeleton(), - ); + return MineHeaderSkeleton(); } } diff --git a/lib/widgets/mine/mine_header/mine_header_bloc.dart b/lib/widgets/mine/mine_header/mine_header_bloc.dart new file mode 100644 index 0000000..fe2b178 --- /dev/null +++ b/lib/widgets/mine/mine_header/mine_header_bloc.dart @@ -0,0 +1,37 @@ +import 'dart:async'; + +import 'package:zhiying_comm/util/base_bloc.dart'; +import 'package:zhiying_comm/zhiying_comm.dart'; + +class MineHeaderBloc extends BlocBase { + Map _mineData; + + StreamController> _mineController = + StreamController>(); + + Stream> get outData => _mineController.stream; + + @override + void dispose() { + _mineController.close(); + _mineController = null; + } + + void loadData(int id) { + NetUtil.request('/api/v1/mod', + method: NetMethod.POST, + params: Map.from({ + 'ids': [id] + }), + onCache: (data) {}, onSuccess: (data) { + _loadData(id, data); + }); + } + + 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_creater.dart b/lib/widgets/mine/mine_header/mine_header_creater.dart deleted file mode 100644 index 1a08672..0000000 --- a/lib/widgets/mine/mine_header/mine_header_creater.dart +++ /dev/null @@ -1,12 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:zhiying_base_widget/widgets/mine/mine_header/mine_header.dart'; -import 'package:zhiying_comm/zhiying_comm.dart'; - -class MineHeaderCreater extends WidgetCreater { - @override - List createWidgets(Map model) { - return [ - MineHeader(), - ]; - } -} diff --git a/lib/widgets/mine/mine_nav/mine_nav.dart b/lib/widgets/mine/mine_nav/mine_nav.dart index f1cac58..c8b14da 100644 --- a/lib/widgets/mine/mine_nav/mine_nav.dart +++ b/lib/widgets/mine/mine_nav/mine_nav.dart @@ -1,22 +1,53 @@ +import 'dart:convert' as convert; import 'dart:ui'; +import 'package:cached_network_image/cached_network_image.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; +import 'package:zhiying_comm/zhiying_comm.dart'; class MineNavDelegate extends SliverPersistentHeaderDelegate { + final Map data; double _height; + Color _color; - MineNavDelegate() : super() { + List _icons = List(); + + MineNavDelegate(this.data) : super() { _height = MediaQueryData.fromWindow(window).padding.top + 44; + String d = data['data']; + Map json = convert.jsonDecode(d); + if (json.containsKey('app_bar_bg_color')) { + _color = HexColor.fromHex(json['app_bar_bg_color']); + } else { + _color = Colors.amber; + } + if (json.containsKey('app_bar_icons')) { + 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}'); + }, + ); + }).toList(); + } } @override Widget build( BuildContext context, double shrinkOffset, bool overlapsContent) { -// print('${shrinkOffset.toString()}'); double percent = shrinkOffset / _height; - print('${percent.toString()}'); - return MineNav(Colors.red.withOpacity(percent)); + return MineNav(_color.withOpacity(percent), _icons); } @override @@ -32,12 +63,14 @@ class MineNavDelegate extends SliverPersistentHeaderDelegate { class MineNav extends StatelessWidget { final Color color; + final List widgets; - MineNav(this.color); + MineNav(this.color, this.widgets); @override Widget build(BuildContext context) { return Container( + padding: EdgeInsets.only(left: 12, right: 12), color: color, child: Column( children: [ @@ -48,16 +81,7 @@ class MineNav extends StatelessWidget { child: Row( mainAxisAlignment: MainAxisAlignment.end, crossAxisAlignment: CrossAxisAlignment.center, - children: [ - Icon( - Icons.settings, - color: Colors.white, - ), - Icon( - Icons.chat, - color: Colors.white, - ) - ], + children: this.widgets, ), ) ], diff --git a/lib/widgets/mine/mine_nav/mine_nav_bg.dart b/lib/widgets/mine/mine_nav/mine_nav_bg.dart new file mode 100644 index 0000000..45f31c9 --- /dev/null +++ b/lib/widgets/mine/mine_nav/mine_nav_bg.dart @@ -0,0 +1,44 @@ +import 'package:cached_network_image/cached_network_image.dart'; +import 'package:flutter/material.dart'; +import 'package:provider/provider.dart'; +import 'package:zhiying_base_widget/pages/main_page/notifier/main_page_bg_notifier.dart'; + +class MineNavBg extends StatefulWidget { + final Map data; + + const MineNavBg(this.data, {Key key}) : super(key: key); + + @override + _MineNavBgState createState() => _MineNavBgState(); +} + +class _MineNavBgState extends State { + @override + void initState() { + super.initState(); + } + + void _updateBg() { + final double statusBarHeight = MediaQuery.of(context).padding.top; + if (widget.data.containsKey('img')) { + Provider.of(context, listen: false).switchBg( + Container( + width: double.infinity, + height: statusBarHeight + 250, + child: CachedNetworkImage( + imageUrl: widget.data['img'], + fit: BoxFit.fitHeight, + ), + ), + ); + } + } + + @override + Widget build(BuildContext context) { + Future.delayed(Duration.zero, () { + _updateBg(); + }); + return Container(); + } +} diff --git a/lib/widgets/mine/mine_nav/mine_nav_creater.dart b/lib/widgets/mine/mine_nav/mine_nav_creater.dart index 1341cbf..d0a2753 100644 --- a/lib/widgets/mine/mine_nav/mine_nav_creater.dart +++ b/lib/widgets/mine/mine_nav/mine_nav_creater.dart @@ -9,7 +9,7 @@ class MineNavCreater extends WidgetCreater { SliverPersistentHeader( pinned: true, floating: false, - delegate: MineNavDelegate(), + delegate: MineNavDelegate(model), ), ]; } diff --git a/lib/widgets/mine/mine_nav/mine_nav_sk.dart b/lib/widgets/mine/mine_nav/mine_nav_sk.dart deleted file mode 100644 index e69de29..0000000 diff --git a/lib/widgets/mine/mine_quick_entry/mine_quick_entry_creater.dart b/lib/widgets/mine/mine_quick_entry/mine_quick_entry_creater.dart deleted file mode 100644 index 3721a2b..0000000 --- a/lib/widgets/mine/mine_quick_entry/mine_quick_entry_creater.dart +++ /dev/null @@ -1,12 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:zhiying_base_widget/widgets/mine/mine_quick_entry/mine_quick_entry.dart'; -import 'package:zhiying_comm/zhiying_comm.dart'; - -class MineQuickEntryCreater extends WidgetCreater { - @override - List createWidgets(Map model) { - return [ - MineQuickEntry(), - ]; - } -} diff --git a/lib/widgets/others/mine_header_bg_widget.dart b/lib/widgets/others/mine_header_bg_widget.dart index aae595f..0ec0ef5 100644 --- a/lib/widgets/others/mine_header_bg_widget.dart +++ b/lib/widgets/others/mine_header_bg_widget.dart @@ -37,56 +37,13 @@ class _MineHeaderBgWidgetState extends State { } } - @override - void dispose() { - super.dispose(); - } - - @override - void didChangeDependencies() { - super.didChangeDependencies(); - print('didChangeDependencies'); - -// if (isNeedLoadMore && _provider != '') { -// print('HomeGoods loadmore...'); -// _bloc.loadMore(_provider); - } - @override Widget build(BuildContext context) { - print('mine_header_bg_widget build ${_offsetY.toString()}'); return Transform.translate( offset: Offset(0, _offsetY), child: _content, ); } - -// @override -// Widget build(BuildContext context) { -// return Container( -// height: 300, -// width: double.infinity, -// child: Stack( -// children: imageUrls -// .asMap() -// .keys -// .map((i) => AnimatedOpacity( -// curve: Curves.easeIn, -// duration: Duration(milliseconds: 1600), -// opacity: i == zIndex ? 1 : 0, -// child: Container( -//// color: Color(int.parse(list[i], radix: 16)) -//// .withAlpha(255), -// child: CachedNetworkImage( -// imageUrl: imageUrls[i], -// fit: BoxFit.fill, -// ), -// height: 300, //100% -// ), -// )) -// .toList(), -// )); -// } } class _MineHeaderBgContainer extends StatefulWidget {