From 87ec5a2915decdcf1f3441241c689bf8d42b1d28 Mon Sep 17 00:00:00 2001 From: PH2 <1293456824@qq.com> Date: Tue, 15 Sep 2020 12:06:17 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E7=94=A8=E6=88=B7=E4=BF=A1=E6=81=AF?= =?UTF-8?q?=E7=9A=84=E7=BC=93=E5=AD=98=EF=BC=8C=E9=AA=A8=E6=9E=B6=E5=B1=8F?= =?UTF-8?q?=E7=9A=84=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../MainActivity.java | 2 +- .../login_page/account/login_account_sk.dart | 30 +++++++ .../login_page/invite/login_invite_page.dart | 3 +- lib/pages/login_page/login_page.dart | 5 +- lib/pages/login_page/login_page_sk.dart | 87 +++++++++++++++++++ .../bloc/home_banner_repository.dart | 6 +- .../bloc/home_quick_entry_bloc.dart | 14 ++- .../bloc/home_quick_entry_event.dart | 9 +- .../bloc/home_quick_entry_repository.dart | 15 ++-- .../home_quick_entry_creater.dart | 2 +- .../home_quick_entry_widget.dart | 3 + .../bloc/home_slide_banner_repository.dart | 16 ++-- .../home_slide_banner/home_slide_banner.dart | 40 ++++----- pubspec.yaml | 4 +- 14 files changed, 182 insertions(+), 54 deletions(-) create mode 100644 lib/pages/login_page/account/login_account_sk.dart create mode 100644 lib/pages/login_page/login_page_sk.dart diff --git a/example/android/app/src/main/java/cn/zhios/zhiying_base_widget_example/MainActivity.java b/example/android/app/src/main/java/cn/zhios/zhiying_base_widget_example/MainActivity.java index 2bde311..627f458 100644 --- a/example/android/app/src/main/java/cn/zhios/zhiying_base_widget_example/MainActivity.java +++ b/example/android/app/src/main/java/cn/zhios/zhiying_base_widget_example/MainActivity.java @@ -41,7 +41,7 @@ public class MainActivity extends FlutterActivity implements ZhiyingFlutterCommN map.put("domain", "http://192.168.0.113:5000"); //"http://120.76.175.204:8989"); map.put("master_id", "123456"); map.put("secret_key", "123456"); - map.put("token", "123465"); +// map.put("token", "123465"); return map; } diff --git a/lib/pages/login_page/account/login_account_sk.dart b/lib/pages/login_page/account/login_account_sk.dart new file mode 100644 index 0000000..7e73143 --- /dev/null +++ b/lib/pages/login_page/account/login_account_sk.dart @@ -0,0 +1,30 @@ +import 'package:shimmer/shimmer.dart'; +import 'package:flutter/material.dart'; + +/// +/// +/// +class LoginAccountSkeleton extends StatelessWidget { + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar(), + body: Container( + width: double.infinity, + height: double.infinity, + ), + ); + } + + Widget _shimmerWidget({double width, double height, double radius = 0}) { + return Shimmer.fromColors( + baseColor: Colors.grey[300], + highlightColor: Colors.grey[100], + child: Container( + width: width, + height: height, + decoration: BoxDecoration(color: Colors.white, borderRadius: BorderRadius.circular(radius)), + ), + ); + } +} diff --git a/lib/pages/login_page/invite/login_invite_page.dart b/lib/pages/login_page/invite/login_invite_page.dart index 2df9f15..5b69339 100644 --- a/lib/pages/login_page/invite/login_invite_page.dart +++ b/lib/pages/login_page/invite/login_invite_page.dart @@ -82,7 +82,8 @@ class _LoginInvitePageContainerState extends State { String inviteNum = inviteUser?.userId ?? ''; /// 手机号 - String mobile = Provider.of(context, listen: false)?.getUserInfoModel()?.mobile ?? ''; + UserInfoModel model = await Provider.of(context, listen: false)?.getUserInfoModel(); + String mobile = model?.mobile ?? ''; if (!EmptyUtil.isEmpty(inviteNum) && !EmptyUtil.isEmpty(mobile)) { BlocProvider.of(context).add(LoginInviteSubmitEvent(mobile: mobile, num: inviteNum)); } diff --git a/lib/pages/login_page/login_page.dart b/lib/pages/login_page/login_page.dart index 5bfd947..dd595c0 100644 --- a/lib/pages/login_page/login_page.dart +++ b/lib/pages/login_page/login_page.dart @@ -9,6 +9,9 @@ import 'package:zhiying_base_widget/pages/login_page/model/login_model.dart'; import 'package:zhiying_comm/util/empty_util.dart'; import 'package:zhiying_comm/zhiying_comm.dart'; import 'package:cached_network_image/cached_network_image.dart'; +import 'package:provider/provider.dart'; + +import 'login_page_sk.dart'; /// /// 登陆页面 @@ -98,7 +101,7 @@ class _LoginPageContainerState extends State { if (state is LoginLoadedState) { return _getMainWidget(state.model); } - return Container(); + return LoginPageSkeleton(); // 骨架屏幕 }, ); } diff --git a/lib/pages/login_page/login_page_sk.dart b/lib/pages/login_page/login_page_sk.dart new file mode 100644 index 0000000..84acc17 --- /dev/null +++ b/lib/pages/login_page/login_page_sk.dart @@ -0,0 +1,87 @@ +import 'package:shimmer/shimmer.dart'; +import 'package:flutter/material.dart'; + +/// +/// 登陆页面的骨架屏 +/// +class LoginPageSkeleton extends StatelessWidget { + @override + Widget build(BuildContext context) { + return Scaffold( + body: Container( + padding: EdgeInsets.only(top: MediaQuery.of(context).padding.top), + width: double.infinity, + height: double.infinity, + child: Column( + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + Container( + height: 230, + child: Column( + children: [ + /// logn + Padding(padding: const EdgeInsets.only(top: 60), child: _logo()), + + /// appName + Padding(padding: const EdgeInsets.only(top: 12), child: _appName()), + ], + ), + ), + + /// btn + Padding(padding: const EdgeInsets.only(top: 50, left: 28, right: 28), child: _shimmerWidget(width: 320, height: 40, radius: 20)), + Padding(padding: const EdgeInsets.only(top: 8, left: 28, right: 28), child: _shimmerWidget(width: 320, height: 40, radius: 20)), + + /// 协议 + Padding(padding: const EdgeInsets.only(top: 9, left: 28, right: 28), child: _shimmerWidget(width: 250, height: 14, radius: 0)), + + Expanded( + child: Column( + mainAxisAlignment: MainAxisAlignment.end, + children: [ + Padding(padding: const EdgeInsets.only(bottom: 18), child: _shimmerWidget(width: 78, height: 18, radius: 0)), + ], + ), + ), + ], + ), + ), + ); + } + + Widget _logo() { + return Shimmer.fromColors( + baseColor: Colors.grey[300], + highlightColor: Colors.grey[100], + child: Container( + height: 80, + width: 80, + decoration: BoxDecoration(borderRadius: BorderRadius.circular(15), color: Colors.white), + ), + ); + } + + Widget _appName() { + return Shimmer.fromColors( + baseColor: Colors.grey[300], + highlightColor: Colors.grey[100], + child: Container( + width: 90, + height: 22.5, + color: Colors.white, + ), + ); + } + + Widget _shimmerWidget({double width, double height, double radius = 0}) { + return Shimmer.fromColors( + baseColor: Colors.grey[300], + highlightColor: Colors.grey[100], + child: Container( + width: width, + height: height, + decoration: BoxDecoration(color: Colors.white, borderRadius: BorderRadius.circular(radius)), + ), + ); + } +} diff --git a/lib/widgets/home/home_banner/bloc/home_banner_repository.dart b/lib/widgets/home/home_banner/bloc/home_banner_repository.dart index 296aaa6..9502f0b 100644 --- a/lib/widgets/home/home_banner/bloc/home_banner_repository.dart +++ b/lib/widgets/home/home_banner/bloc/home_banner_repository.dart @@ -1,15 +1,15 @@ import 'package:flutter/cupertino.dart'; import 'package:zhiying_base_widget/widgets/home/home_banner/model/HomeBannerModel.dart'; -import 'package:zhiying_comm/util/empty_util.dart'; +import 'package:zhiying_comm/zhiying_comm.dart'; import 'package:zhiying_comm/util/net_util.dart'; class HomeBannerRepository { /// 读取缓存数据 Future fetchCacheData({@required int modId}) async { - var reult = await NetUtil.getRequestCachedData('/api/v1/mod', params: { + var result = await NetUtil.getRequestCachedData('/api/v1/mod', params: { 'ids': [modId] }); - if (!EmptyUtil.isEmpty(reult)) { + if(NetUtil.isSuccess(result) && !EmptyUtil.isEmpty(result[GlobalConfig.HTTP_RESPONSE_KEY_DATA])){ return HomeBannerModel(); } return null; diff --git a/lib/widgets/home/home_quick_entry/bloc/home_quick_entry_bloc.dart b/lib/widgets/home/home_quick_entry/bloc/home_quick_entry_bloc.dart index 55245d4..c641259 100644 --- a/lib/widgets/home/home_quick_entry/bloc/home_quick_entry_bloc.dart +++ b/lib/widgets/home/home_quick_entry/bloc/home_quick_entry_bloc.dart @@ -1,4 +1,5 @@ import 'dart:async'; +import 'dart:math'; import 'package:bloc/bloc.dart'; import 'package:flutter/cupertino.dart'; @@ -7,8 +8,7 @@ import 'package:zhiying_comm/util/empty_util.dart'; import './bloc.dart'; -class HomeQuickEntryBloc - extends Bloc { +class HomeQuickEntryBloc extends Bloc { HomeQuickEntryRepository repository; HomeQuickEntryBloc({@required this.repository}); @@ -17,8 +17,7 @@ class HomeQuickEntryBloc HomeQuickEntryState get initialState => InitialHomeQuickEntryState(); @override - Stream mapEventToState( - HomeQuickEntryEvent event) async* { + Stream mapEventToState(HomeQuickEntryEvent event) async* { final currentState = state; if (event is HomeQuickEntryInitEvent) { yield* _mapHomeQuickEntryInitToState(event); @@ -26,14 +25,13 @@ class HomeQuickEntryBloc } /// 初始化 - Stream _mapHomeQuickEntryInitToState( - HomeQuickEntryInitEvent event) async* { + Stream _mapHomeQuickEntryInitToState(HomeQuickEntryInitEvent event) async* { /// 获取缓存数据 - var cached = await repository.fetchCachedData(); + var cached = await repository.fetchCachedData(event: event); if (!EmptyUtil.isEmpty(cached)) { yield HomeQuickEntryCachedState(); } - var result = await repository.fetchData(); + var result = await repository.fetchData(event: event); if (!EmptyUtil.isEmpty(result)) { yield HomeQuickEntryLoadedState(); } else { diff --git a/lib/widgets/home/home_quick_entry/bloc/home_quick_entry_event.dart b/lib/widgets/home/home_quick_entry/bloc/home_quick_entry_event.dart index 9f050d7..4f9aa5e 100644 --- a/lib/widgets/home/home_quick_entry/bloc/home_quick_entry_event.dart +++ b/lib/widgets/home/home_quick_entry/bloc/home_quick_entry_event.dart @@ -8,4 +8,11 @@ abstract class HomeQuickEntryEvent extends Equatable { } /// 初始事件 -class HomeQuickEntryInitEvent extends HomeQuickEntryEvent {} +class HomeQuickEntryInitEvent extends HomeQuickEntryEvent { + final Map model; + + const HomeQuickEntryInitEvent({this.model}); + + @override + List get props => [this.model]; +} diff --git a/lib/widgets/home/home_quick_entry/bloc/home_quick_entry_repository.dart b/lib/widgets/home/home_quick_entry/bloc/home_quick_entry_repository.dart index cccc7e4..e98643c 100644 --- a/lib/widgets/home/home_quick_entry/bloc/home_quick_entry_repository.dart +++ b/lib/widgets/home/home_quick_entry/bloc/home_quick_entry_repository.dart @@ -1,20 +1,23 @@ +import 'package:flutter/cupertino.dart'; import 'package:zhiying_comm/util/net_util.dart'; import 'package:zhiying_comm/util/empty_util.dart'; +import 'package:zhiying_comm/zhiying_comm.dart'; +import 'home_quick_entry_event.dart'; class HomeQuickEntryRepository { /// 获取数据 - Future fetchData() async { - var result = await NetUtil.post('/api/v1/mod', params: {'ids':[7]}, cache: true); - if(NetUtil.isSuccess(result)){ - + Future fetchData({@required HomeQuickEntryInitEvent event}) async { + var result = await NetUtil.post('/api/v1/mod', params: {'ids':[event.model['mod_id']]}, cache: true); + if(NetUtil.isSuccess(result) && !EmptyUtil.isEmpty(result[GlobalConfig.HTTP_RESPONSE_KEY_DATA])){ + } return null; } /// 获取缓存数据 - Future fetchCachedData() async{ - var result = await NetUtil.getRequestCachedData('/api/v1/mod', params: {'ids':[7]}); + Future fetchCachedData({@required HomeQuickEntryInitEvent event}) async{ + var result = await NetUtil.getRequestCachedData('/api/v1/mod', params: {'ids':[event.model['mod_id']]}); if(!EmptyUtil.isEmpty(result)){ return result; } diff --git a/lib/widgets/home/home_quick_entry/home_quick_entry_creater.dart b/lib/widgets/home/home_quick_entry/home_quick_entry_creater.dart index dbbbfd1..afbeb28 100644 --- a/lib/widgets/home/home_quick_entry/home_quick_entry_creater.dart +++ b/lib/widgets/home/home_quick_entry/home_quick_entry_creater.dart @@ -14,6 +14,6 @@ class HomeQuickEntryCreater extends WidgetCreater { @override List createWidgets(Map model) { - return [HomeQuickEntryWidget()]; + return [HomeQuickEntryWidget(model)]; } } diff --git a/lib/widgets/home/home_quick_entry/home_quick_entry_widget.dart b/lib/widgets/home/home_quick_entry/home_quick_entry_widget.dart index dd7fcc2..f876839 100644 --- a/lib/widgets/home/home_quick_entry/home_quick_entry_widget.dart +++ b/lib/widgets/home/home_quick_entry/home_quick_entry_widget.dart @@ -8,6 +8,9 @@ import 'package:zhiying_comm/zhiying_comm.dart'; /// class HomeQuickEntryWidget extends StatelessWidget { + final Map model; + HomeQuickEntryWidget(this.model); + var data = []; @override diff --git a/lib/widgets/home/home_slide_banner/bloc/home_slide_banner_repository.dart b/lib/widgets/home/home_slide_banner/bloc/home_slide_banner_repository.dart index 2e4fac5..87285d8 100644 --- a/lib/widgets/home/home_slide_banner/bloc/home_slide_banner_repository.dart +++ b/lib/widgets/home/home_slide_banner/bloc/home_slide_banner_repository.dart @@ -6,8 +6,7 @@ import 'package:zhiying_comm/util/net_util.dart'; class HomeSlideBannerRepository { /// 获取缓存数据 - Future> fetchCachedDate( - {@required int id}) async { + Future> fetchCachedDate({@required int id}) async { var cached = await NetUtil.getRequestCachedData('/api/v1/mod', params: { 'ids': [id] }); @@ -22,12 +21,13 @@ class HomeSlideBannerRepository { /// 获取数据 Future> fetchData({@required int id}) async { - var params = await NetUtil.post('/api/v1/mod', params: { - 'ids': [id] - }, cache: true); - if (!EmptyUtil.isEmpty(params) && NetUtil.isSuccess(params)) { - HomeSlideBannerModel model = HomeSlideBannerModel.fromJson( - params[GlobalConfig.HTTP_RESPONSE_KEY_DATA]); + var params = await NetUtil.post('/api/v1/mod', + params: { + 'ids': [id] + }, + cache: true); + if (NetUtil.isSuccess(params) && !EmptyUtil.isEmpty(params[GlobalConfig.HTTP_RESPONSE_KEY_DATA])) { + HomeSlideBannerModel model = HomeSlideBannerModel.fromJson(params[GlobalConfig.HTTP_RESPONSE_KEY_DATA]); if (null != model && !EmptyUtil.isEmpty(model.items)) { return model.items; } diff --git a/lib/widgets/home/home_slide_banner/home_slide_banner.dart b/lib/widgets/home/home_slide_banner/home_slide_banner.dart index facfab9..5bdbc73 100644 --- a/lib/widgets/home/home_slide_banner/home_slide_banner.dart +++ b/lib/widgets/home/home_slide_banner/home_slide_banner.dart @@ -3,6 +3,7 @@ import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_swiper/flutter_swiper.dart'; import 'package:provider/provider.dart'; import 'package:zhiying_base_widget/pages/main_page/notifier/main_page_bg_notifier.dart'; +import 'package:cached_network_image/cached_network_image.dart'; import 'package:zhiying_comm/zhiying_comm.dart'; import 'bloc/bloc.dart'; @@ -26,9 +27,7 @@ class _HomeSlideBannerState extends State { @override Widget build(BuildContext context) { return BlocProvider( - create: (_) => - HomeSlideBannerBloc(repository: HomeSlideBannerRepository()) - ..add(HomeBannerInitEvent(model: widget?.model)), + create: (_) => HomeSlideBannerBloc(repository: HomeSlideBannerRepository())..add(HomeBannerInitEvent(model: widget?.model)), child: HomeSlideBannerContainer(), ); } @@ -36,8 +35,7 @@ class _HomeSlideBannerState extends State { class HomeSlideBannerContainer extends StatefulWidget { @override - _HomeSlideBannerContainerState createState() => - _HomeSlideBannerContainerState(); + _HomeSlideBannerContainerState createState() => _HomeSlideBannerContainerState(); } class _HomeSlideBannerContainerState extends State { @@ -78,20 +76,26 @@ class _HomeSlideBannerContainerState extends State { Widget _getMainWidget(List datas) { return Container( width: double.infinity, - height: 400.h, + height: 140, child: Swiper( itemBuilder: (BuildContext context, int index) { + HomeSlideBannerModelItems items = datas[index]; return Container( - color: Colors.primaries[index % Colors.primaries.length], + // color: Colors.primaries[index % Colors.primaries.length], + width: double.infinity, + child: CachedNetworkImage( + imageUrl: items?.img?? '', + fit: BoxFit.cover, + ), ); }, itemCount: datas?.length ?? 0, + loop: true, onTap: (index) => _itemOnClick(datas[index]), pagination: _SwiperCustomPagination(datas?.length ?? 0), onIndexChanged: (index) { print('切换下一页'); - Provider.of(context, listen: false) - .switchBg(Container( + Provider.of(context, listen: false).switchBg(Container( width: double.infinity, height: 200, color: Colors.primaries[(index + 2) % Colors.primaries.length], @@ -101,15 +105,14 @@ class _HomeSlideBannerContainerState extends State { ); } - // 自定义进度条 + /// 自定义进度条 SwiperPlugin _SwiperCustomPagination(int pageCount) { List list = []; for (int i = 0; i < pageCount; i++) { list.add(i); } - return SwiperCustomPagination( - builder: (BuildContext context, SwiperPluginConfig config) { + return SwiperCustomPagination(builder: (BuildContext context, SwiperPluginConfig config) { return Align( alignment: Alignment(0.0, 0.9), child: Row( @@ -118,13 +121,10 @@ class _HomeSlideBannerContainerState extends State { children: list.map((index) { var borderRadius; if (index == 0) { - borderRadius = BorderRadius.only( - topLeft: Radius.circular(2), bottomLeft: Radius.circular(2)); + borderRadius = BorderRadius.only(topLeft: Radius.circular(2), bottomLeft: Radius.circular(2)); } if (index == list.length - 1) { - borderRadius = BorderRadius.only( - topRight: Radius.circular(2), - bottomRight: Radius.circular(2)); + borderRadius = BorderRadius.only(topRight: Radius.circular(2), bottomRight: Radius.circular(2)); } if (index == config.activeIndex) { @@ -134,11 +134,7 @@ class _HomeSlideBannerContainerState extends State { return Container( height: 4, width: 25, - decoration: BoxDecoration( - borderRadius: borderRadius, - color: index == config.activeIndex - ? HexColor.fromHex('#FF4242') - : HexColor.fromHex('#FFFFFF')), + decoration: BoxDecoration(borderRadius: borderRadius, color: index == config.activeIndex ? HexColor.fromHex('#FF4242') : HexColor.fromHex('#FFFFFF')), ); }).toList(), ), diff --git a/pubspec.yaml b/pubspec.yaml index e342d9d..6c555e6 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -13,11 +13,11 @@ dependencies: shimmer: ^1.1.1 flutter_swiper : ^1.1.6 - provider: ^4.0.0 bloc: ^4.0.0 flutter_bloc: ^4.0.1 event_bus: ^1.1.1 pull_to_refresh: ^1.6.1 + dev_dependencies: flutter_test: @@ -25,7 +25,7 @@ dev_dependencies: zhiying_comm: path: ../zhiying_comm - + json_serializable: ^3.3.0 build_runner: ^1.10.0