diff --git a/example/lib/main.dart b/example/lib/main.dart index 170aed8..2904bc0 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -1,7 +1,9 @@ import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:zhiying_base_widget/pages/home_page/home_page.dart'; +import 'package:provider/provider.dart'; import 'package:zhiying_base_widget/register.dart'; +import 'package:zhiying_comm/zhiying_comm.dart'; void main() { FlutterError.onError = (FlutterErrorDetails details) { @@ -40,8 +42,13 @@ class _MyAppState extends State { ErrorWidget.builder = (FlutterErrorDetails errorDetails) { return getErrorWidget(context, errorDetails); }; - return MaterialApp( - home: HomePage(), + return MultiProvider( + providers: [ + ChangeNotifierProvider.value(value: UserInfoNotifier()), + ], + child: MaterialApp( + home: HomePage(), + ), ); } } diff --git a/lib/pages/home_page/home_page.dart b/lib/pages/home_page/home_page.dart index 95c4399..afbea4d 100644 --- a/lib/pages/home_page/home_page.dart +++ b/lib/pages/home_page/home_page.dart @@ -1,9 +1,9 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:cached_network_image/cached_network_image.dart'; -import 'package:provider/provider.dart'; + import 'package:zhiying_base_widget/pages/home_page/home_page_bloc.dart'; -import 'package:zhiying_base_widget/pages/login_page/notifier/user_info_notifier.dart'; + import 'package:zhiying_comm/zhiying_comm.dart'; import 'package:zhiying_comm/util/base_bloc.dart'; @@ -19,14 +19,9 @@ class _HomePageState extends State { @override Widget build(BuildContext context) { print('home_page build'); - return MultiProvider( - providers: [ - ChangeNotifierProvider.value(value: UserInfoNotifier()), - ], - child: BlocProvider( - bloc: HomePageBloc(), - child: _HomePageContainer(), - ), + return BlocProvider( + bloc: HomePageBloc(), + child: _HomePageContainer(), ); } } diff --git a/lib/pages/login_page/account/bloc/login_account_repository.dart b/lib/pages/login_page/account/bloc/login_account_repository.dart index a6ef75c..45cff14 100644 --- a/lib/pages/login_page/account/bloc/login_account_repository.dart +++ b/lib/pages/login_page/account/bloc/login_account_repository.dart @@ -1,10 +1,10 @@ import 'package:zhiying_base_widget/pages/login_page/account/bloc/bloc.dart'; -import 'package:zhiying_base_widget/pages/login_page/model/login_user.dart'; import 'package:zhiying_base_widget/pages/login_page/login_util.dart'; import 'package:zhiying_base_widget/pages/login_page/model/login_model.dart'; import 'package:zhiying_comm/util/empty_util.dart'; import 'package:zhiying_comm/util/global_config.dart'; import 'package:zhiying_comm/util/net_util.dart'; +import 'package:zhiying_comm/models/user/user_info_model.dart'; /// /// 账户登陆 @@ -36,12 +36,15 @@ class LoginAccountRepository{ } /// 验证码登陆 - Future loginTypeVcode(LoginAccountTypeVcodeEvent event) async{ + Future loginTypeVcode(LoginAccountTypeVcodeEvent event) async{ var result = await NetUtil.post('/api/v1/sign/fast/in', params: {'mobile': event.mobile, 'captcha': event.captcha}); if(NetUtil.isSuccess(result) && !EmptyUtil.isEmpty(result[GlobalConfig.HTTP_RESPONSE_KEY_DATA])){ - LoginUser loginUser = LoginUser.fromJson(result[GlobalConfig.HTTP_RESPONSE_KEY_DATA]); - - return loginUser; + UserInfoModel loginUser = UserInfoModel.fromJson(result[GlobalConfig.HTTP_RESPONSE_KEY_DATA]); + if(null != loginUser){ + loginUser.mobile = event.mobile; + return loginUser; + } + return null; } return null; } diff --git a/lib/pages/login_page/account/bloc/login_account_state.dart b/lib/pages/login_page/account/bloc/login_account_state.dart index aec903f..c3751e0 100644 --- a/lib/pages/login_page/account/bloc/login_account_state.dart +++ b/lib/pages/login_page/account/bloc/login_account_state.dart @@ -1,7 +1,7 @@ import 'package:equatable/equatable.dart'; import 'package:flutter/cupertino.dart'; -import 'package:zhiying_base_widget/pages/login_page/model/login_user.dart'; import 'package:zhiying_base_widget/pages/login_page/model/login_model.dart'; +import 'package:zhiying_comm/models/user/user_info_model.dart'; abstract class LoginAccountState extends Equatable { const LoginAccountState(); @@ -29,7 +29,9 @@ class LoginAccountErrorState extends LoginAccountState {} /// 验证码下发成功的状态 class LoginAccountGetVcodeSuccessState extends LoginAccountState { final String msg; + const LoginAccountGetVcodeSuccessState({this.msg}); + @override List get props => [this.msg]; } @@ -37,12 +39,13 @@ class LoginAccountGetVcodeSuccessState extends LoginAccountState { /// 验证码下发失败的状态 class LoginAccountGetVcodeErrorState extends LoginAccountState { final String msg; + const LoginAccountGetVcodeErrorState({this.msg}); } /// 验证码登陆成功 class LoginAccountTypeVcodeLoginSuccessState extends LoginAccountState { - final LoginUser model; + final UserInfoModel model; const LoginAccountTypeVcodeLoginSuccessState({@required this.model}); @@ -53,5 +56,6 @@ class LoginAccountTypeVcodeLoginSuccessState extends LoginAccountState { /// 验证码登陆失败 class LoginAccountTypeVcodeLoginErrorState extends LoginAccountState { final String msg; + const LoginAccountTypeVcodeLoginErrorState({this.msg}); } diff --git a/lib/pages/login_page/account/login_account_page.dart b/lib/pages/login_page/account/login_account_page.dart index 13d3f87..1362102 100644 --- a/lib/pages/login_page/account/login_account_page.dart +++ b/lib/pages/login_page/account/login_account_page.dart @@ -5,7 +5,6 @@ import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:provider/provider.dart'; import 'package:zhiying_base_widget/pages/login_page/account/bloc/bloc.dart'; import 'package:zhiying_base_widget/pages/login_page/model/login_model.dart'; -import 'package:zhiying_base_widget/pages/login_page/notifier/user_info_notifier.dart'; import 'package:zhiying_comm/zhiying_comm.dart'; import 'bloc/login_account_repository.dart'; import 'widget/slide_verify_widget.dart'; @@ -44,7 +43,6 @@ class LoginAccountPageContianer extends StatefulWidget { /// 主体逻辑 /// class _LoginAccountPageContianerState extends State implements OnClickListener { - TextEditingController _phoneEdController; TextEditingController _vcodeEdController; TextEditingController _passEdController; @@ -53,29 +51,37 @@ class _LoginAccountPageContianerState extends State i FocusNode _vcodeFN; /// 跳转到邀请码页面 - void _openInvitePage(){ + void _openInvitePage() { print('跳转到邀请码页面'); + Navigator.push(context, MaterialPageRoute( + builder: (_) => PageFactory.create('login_invite', null) + )); } /// 登陆成功页面 - void _openLoginSuccessPage(){ + void _openLoginSuccessPage() { Navigator.pushAndRemoveUntil( context, MaterialPageRoute(builder: (BuildContext context) => PageFactory.create('homePage', null)), - (Route route) => false, + (Route route) => false, ); } + /// 返回上一页 + void _openPop() { + if (Navigator.canPop(context)) { + Navigator.pop(context); + } + } + /// 登陆 void _submitOnClick() { print('登陆'); - if(_checkParam(true)) { + if (_checkParam(true)) { if (_useVcode) { - BlocProvider.of(context).add( - LoginAccountTypeVcodeEvent(mobile: _phoneEdController?.text?.toString()?.trim() ?? '', captcha: _vcodeEdController?.text?.toString()?.trim() ?? '')); + BlocProvider.of(context).add(LoginAccountTypeVcodeEvent(mobile: _phoneEdController?.text?.toString()?.trim() ?? '', captcha: _vcodeEdController?.text?.toString()?.trim() ?? '')); } else { - BlocProvider.of(context).add(LoginAccountTypePasswordEvent(username: _phoneEdController?.text?.toString()?.trim() ?? '', - password: _passEdController?.text?.toString()?.trim() ?? '')); + BlocProvider.of(context).add(LoginAccountTypePasswordEvent(username: _phoneEdController?.text?.toString()?.trim() ?? '', password: _passEdController?.text?.toString()?.trim() ?? '')); } } } @@ -88,10 +94,10 @@ class _LoginAccountPageContianerState extends State i _useVcode = !_useVcode; }); // 清除缓存 - if(_useVcode){ + if (_useVcode) { _passEdController?.clear(); _passFN?.unfocus(); - }else{ + } else { _vcodeEdController?.clear(); _vcodeFN?.unfocus(); } @@ -107,63 +113,63 @@ class _LoginAccountPageContianerState extends State i } /// 打开协议 - void _openAgreement(String url){ - if(!EmptyUtil.isEmpty(url)){ + void _openAgreement(String url) { + if (!EmptyUtil.isEmpty(url)) { print('打开协议$url'); } } /// 输入框监听 - void _onChange(string){ + void _onChange(string) { print('$string'); _checkParam(false); } /// 校验登陆参数 - bool _checkParam(bool needToast){ + bool _checkParam(bool needToast) { // 验证码 - if(_useVcode){ + if (_useVcode) { String phone = _phoneEdController?.text?.toString()?.trim() ?? null; String vcode = _vcodeEdController?.text?.toString()?.trim() ?? null; - if(EmptyUtil.isEmpty(phone)){ - if(needToast) Fluttertoast.showToast(msg: '手机号不能为空!'); + if (EmptyUtil.isEmpty(phone)) { + if (needToast) Fluttertoast.showToast(msg: '手机号不能为空!'); return false; } - if(phone.length != 11){ - if(needToast) Fluttertoast.showToast(msg: '手机号格式有误!'); + if (phone.length != 11) { + if (needToast) Fluttertoast.showToast(msg: '手机号格式有误!'); return false; } - if(EmptyUtil.isEmpty(vcode)){ - if(needToast) Fluttertoast.showToast(msg: '验证码不能为空!'); + if (EmptyUtil.isEmpty(vcode)) { + if (needToast) Fluttertoast.showToast(msg: '验证码不能为空!'); return false; } - if(vcode.length < 4){ - if(needToast) Fluttertoast.showToast(msg: '验证码号格式有误!'); + if (vcode.length < 4) { + if (needToast) Fluttertoast.showToast(msg: '验证码号格式有误!'); return false; } - }else{ + } else { String phone = _phoneEdController?.text?.toString()?.trim() ?? null; - String pass = _passEdController?.text?.toString()?.trim() ?? null; - if(EmptyUtil.isEmpty(phone)){ - if(needToast) Fluttertoast.showToast(msg: '手机号不能为空!'); + String pass = _passEdController?.text?.toString()?.trim() ?? null; + if (EmptyUtil.isEmpty(phone)) { + if (needToast) Fluttertoast.showToast(msg: '手机号不能为空!'); return false; } - if(phone.length != 11){ - if(needToast) Fluttertoast.showToast(msg: '手机号格式有误!'); + if (phone.length != 11) { + if (needToast) Fluttertoast.showToast(msg: '手机号格式有误!'); return false; } - if(EmptyUtil.isEmpty(pass)){ - if(needToast) Fluttertoast.showToast(msg: '验证码不能为空!'); + if (EmptyUtil.isEmpty(pass)) { + if (needToast) Fluttertoast.showToast(msg: '验证码不能为空!'); return false; } - if(pass.length < 4){ - if(needToast) Fluttertoast.showToast(msg: '验证码号格式有误!'); + if (pass.length < 4) { + if (needToast) Fluttertoast.showToast(msg: '验证码号格式有误!'); return false; } } - if(!_acceptAgreement){ - if(needToast) Fluttertoast.showToast(msg: '请同意用户协议与隐私政策'); + if (!_acceptAgreement) { + if (needToast) Fluttertoast.showToast(msg: '请同意用户协议与隐私政策'); return false; } @@ -174,14 +180,14 @@ class _LoginAccountPageContianerState extends State i } /// 检测手机号是否合法 - bool _checkPhoneNumParam(bool needToast){ + bool _checkPhoneNumParam(bool needToast) { String phone = _phoneEdController?.text?.toString()?.trim() ?? null; - if(EmptyUtil.isEmpty(phone)){ - if(needToast) Fluttertoast.showToast(msg: '手机号不能为空!'); + if (EmptyUtil.isEmpty(phone)) { + if (needToast) Fluttertoast.showToast(msg: '手机号不能为空!'); return false; } - if(phone.length != 11){ - if(needToast) Fluttertoast.showToast(msg: '手机号格式有误!'); + if (phone.length != 11) { + if (needToast) Fluttertoast.showToast(msg: '手机号格式有误!'); return false; } return true; @@ -194,12 +200,11 @@ class _LoginAccountPageContianerState extends State i bool _canSubmit = false; /// 是否同意协议 - bool _acceptAgreement = false; + bool _acceptAgreement = true; /// 是否显示第三方验证码 bool _showOtherVcode = false; - @override void initState() { _phoneEdController = TextEditingController(); @@ -228,7 +233,7 @@ class _LoginAccountPageContianerState extends State i @override bool onVcodeClick() { /// 获取验证码 - if(_checkPhoneNumParam(true)) { + if (_checkPhoneNumParam(true)) { BlocProvider.of(context).add(LoginAccountGetVcodeEvent(mobile: _phoneEdController?.text?.toString()?.trim() ?? '')); return true; } @@ -238,34 +243,36 @@ class _LoginAccountPageContianerState extends State i @override Widget build(BuildContext context) { return BlocConsumer( - listener: (context, state) {}, + listener: (context, state) { + if (state is LoginAccountTypeVcodeLoginSuccessState) {} + }, buildWhen: (prev, current) { // 验证码登陆失败 - if(current is LoginAccountTypeVcodeLoginErrorState){ + if (current is LoginAccountTypeVcodeLoginErrorState) { Fluttertoast.showToast(msg: '登陆失败'); return false; } // 验证码登陆成功 - if(current is LoginAccountTypeVcodeLoginSuccessState){ - if(current?.model?.registerInviteCodeEnable == '0'){ + if (current is LoginAccountTypeVcodeLoginSuccessState) { + /// 缓存登陆数据 + Provider.of(context, listen: false)?.setUserInfo(current.model); + if (current?.model?.registerInviteCodeEnable == '0') { Fluttertoast.showToast(msg: '登陆成功~'); - /// 缓存登陆数据 - Provider.of(context, listen: false).setUserInfo(current.model); - /// 打开也买 + /// 打开也买 _openLoginSuccessPage(); - }else{ + } else { /// 打开邀请页面 _openInvitePage(); } return false; } // 获取验证码成功 - if (current is LoginAccountGetVcodeSuccessState){ + if (current is LoginAccountGetVcodeSuccessState) { Fluttertoast.showToast(msg: '验证码下发成功'); return false; } // 获取验证码失败 - if(current is LoginAccountGetVcodeErrorState){ + if (current is LoginAccountGetVcodeErrorState) { Fluttertoast.showToast(msg: '验证码获取失败~'); return false; } @@ -287,7 +294,6 @@ class _LoginAccountPageContianerState extends State i print(model); return Column( children: [ - /// appBar _getAppBarWidget(model), @@ -331,10 +337,13 @@ class _LoginAccountPageContianerState extends State i style: TextStyle(color: HexColor.fromHex(model?.mobile?.appBarTitleColor ?? '#333333')), ), centerTitle: true, - leading: Icon( - Icons.arrow_back_ios, - size: 22, - color: HexColor.fromHex('#333333'), + leading: IconButton( + icon: Icon( + Icons.arrow_back_ios, + size: 22, + color: HexColor.fromHex('#333333'), + ), + onPressed: () => _openPop(), ), ); } @@ -351,14 +360,15 @@ class _LoginAccountPageContianerState extends State i /// 手机输入框 Widget _getPhoneWidget(LoginModel model) { - return _getCustomInputWidget( hint: model?.mobile?.inputMobileHintText ?? '请输入您的手机号', + return _getCustomInputWidget( + hint: model?.mobile?.inputMobileHintText ?? '请输入您的手机号', controller: _phoneEdController, focusNode: _passFN, onChanged: _onChange, hintColor: model?.mobile?.inputHintColor ?? '#999999', bgColor: model?.mobile?.inputBgColor ?? '#F7F7F7', textColor: model?.mobile?.inputTextColor ?? '#333333', - iconUrl: model?.mobile?.inputMobileIcon?? ''); + iconUrl: model?.mobile?.inputMobileIcon ?? ''); } /// 验证码输入框 @@ -373,7 +383,7 @@ class _LoginAccountPageContianerState extends State i onChanged: _onChange, hintColor: model?.mobile?.inputHintColor ?? '#999999', hint: model?.mobile?.inputVcodeHintText ?? '请输入您的验证码', - bgColor: model?.mobile?.inputBgColor ??'#F7F7F7', + bgColor: model?.mobile?.inputBgColor ?? '#F7F7F7', textColor: model?.mobile?.inputTextColor ?? '#333333', iconUrl: model?.mobile?.inputVcodeIcon ?? ''), Align(alignment: Alignment.centerRight, child: _getVcodeButtonWidget(model)), @@ -384,17 +394,15 @@ class _LoginAccountPageContianerState extends State i /// 验证码按钮 Widget _getVcodeButtonWidget(LoginModel model) { - return VcodeWidget( - onCallBack: this, - awaitTime: int.parse(model?.mobile?.vcodeTime ?? '60'), - btnAwaitText: '秒', - btnText: '获取验证码', - btnTextColor: model?.mobile?.btnVcodeTextColor ?? '#FFFFFF', - color: model?.mobile?.btnVcodeBgColor ?? '#FF4343', - disabledColor: model?.mobile?.btnVcodeBanBgColor ?? '#DDDDDD', - disabledTextColor: model?.mobile?.btnVcodeBanTextColor ?? '#FFFFFF' - ); + onCallBack: this, + awaitTime: int.parse(model?.mobile?.vcodeTime ?? '60'), + btnAwaitText: '秒', + btnText: '获取验证码', + btnTextColor: model?.mobile?.btnVcodeTextColor ?? '#FFFFFF', + color: model?.mobile?.btnVcodeBgColor ?? '#FF4343', + disabledColor: model?.mobile?.btnVcodeBanBgColor ?? '#DDDDDD', + disabledTextColor: model?.mobile?.btnVcodeBanTextColor ?? '#FFFFFF'); } /// 第三方验证码输入框 @@ -450,13 +458,8 @@ class _LoginAccountPageContianerState extends State i behavior: HitTestBehavior.opaque, onTap: () => _changeLoginTypeOnClick(), child: Text( - _useVcode ? model?.mobile?.textUsePassTip ?? '使用密码登录' : model?.mobile?.textUseVcodeTip ?? '使用验证码登陆', - style: TextStyle(fontSize: 12, - color: HexColor.fromHex( - _useVcode ? - model?.mobile?.textUsePassTipColor ?? '#999999' : - model?.mobile?.textUseVcodeTipColor ?? '#999999' - )), + _useVcode ? model?.mobile?.textUsePassTip ?? '使用密码登录' : model?.mobile?.textUseVcodeTip ?? '使用验证码登陆', + style: TextStyle(fontSize: 12, color: HexColor.fromHex(_useVcode ? model?.mobile?.textUsePassTipColor ?? '#999999' : model?.mobile?.textUseVcodeTipColor ?? '#999999')), ), ); } @@ -473,10 +476,10 @@ class _LoginAccountPageContianerState extends State i model?.mobile?.btnLoginText ?? '立即登录', style: TextStyle(fontSize: 15), ), - textColor: HexColor.fromHex( model?.mobile?.btnLoginTextColor ?? '#FFFFFF'), - color: HexColor.fromHex( model?.mobile?.btnLoginBgColor ?? '#FF3939'), - disabledColor: HexColor.fromHex( model?.mobile?.btnLoginBanBgColor ?? '#F5F5F5'), - disabledTextColor: HexColor.fromHex( model?.mobile?.btnLoginBanTextColor ?? '#999999'), + textColor: HexColor.fromHex(model?.mobile?.btnLoginTextColor ?? '#FFFFFF'), + color: HexColor.fromHex(model?.mobile?.btnLoginBgColor ?? '#FF3939'), + disabledColor: HexColor.fromHex(model?.mobile?.btnLoginBanBgColor ?? '#F5F5F5'), + disabledTextColor: HexColor.fromHex(model?.mobile?.btnLoginBanTextColor ?? '#999999'), elevation: 5, shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(52 / 2)), onPressed: _canSubmit ? _submitOnClick : null, @@ -504,11 +507,17 @@ class _LoginAccountPageContianerState extends State i /// 协议文字 RichText( - text: TextSpan(text: '', children: model.mobile.protocol.map((item){ - return TextSpan(text: item?.text, style: TextStyle(color: HexColor.fromHex(item?.textColor), fontSize: 10),recognizer: TapGestureRecognizer()..onTap = (){ - _openAgreement(item.url); - }); - }).toList()), + text: TextSpan( + text: '', + children: model.mobile.protocol.map((item) { + return TextSpan( + text: item?.text, + style: TextStyle(color: HexColor.fromHex(item?.textColor), fontSize: 10), + recognizer: TapGestureRecognizer() + ..onTap = () { + _openAgreement(item.url); + }); + }).toList()), ) ], ); @@ -520,13 +529,14 @@ class _LoginAccountPageContianerState extends State i padding: const EdgeInsets.only(bottom: 25), child: Text( model?.mobile?.textBottomTip ?? '未注册过的手机将自动注册', - style: TextStyle(fontSize: 11, color: HexColor.fromHex( model?.mobile?.textBottomTipColor ?? '#999999')), + style: TextStyle(fontSize: 11, color: HexColor.fromHex(model?.mobile?.textBottomTipColor ?? '#999999')), ), ); } /// 自定义输入框 - Widget _getCustomInputWidget({String hint, String hintColor, String bgColor, String textColor, String iconUrl, TextEditingController controller, ValueChanged onChanged, FocusNode focusNode}) { + Widget _getCustomInputWidget( + {String hint, String hintColor, String bgColor, String textColor, String iconUrl, TextEditingController controller, ValueChanged onChanged, FocusNode focusNode}) { var border = OutlineInputBorder(borderRadius: BorderRadius.circular(8), borderSide: BorderSide(color: HexColor.fromHex(bgColor), width: 0)); return Container( diff --git a/lib/pages/login_page/bloc/login_repository.dart b/lib/pages/login_page/bloc/login_repository.dart index 3f426a9..11205ca 100644 --- a/lib/pages/login_page/bloc/login_repository.dart +++ b/lib/pages/login_page/bloc/login_repository.dart @@ -1,3 +1,4 @@ +import 'package:zhiying_base_widget/pages/login_page/login_util.dart'; import 'package:zhiying_base_widget/pages/login_page/model/login_model.dart'; import 'package:zhiying_comm/util/net_util.dart'; import 'package:zhiying_comm/util/empty_util.dart'; @@ -6,21 +7,23 @@ import 'package:zhiying_comm/util/global_config.dart'; class LoginRepository { /// 获取页面数据 Future fetchNetPageData() async { - var result = await NetUtil.post('/api/v1/sign/in', method: NetMethod.GET); - if (NetUtil.isSuccess(result) && !EmptyUtil.isEmpty(result[GlobalConfig.HTTP_RESPONSE_KEY_DATA])) { - LoginModel model = LoginModel.fromJson(result[GlobalConfig.HTTP_RESPONSE_KEY_DATA]); - return model; - } - return null; + // var result = await NetUtil.post('/api/v1/sign/in', method: NetMethod.GET, cache: true); + // if (NetUtil.isSuccess(result) && !EmptyUtil.isEmpty(result[GlobalConfig.HTTP_RESPONSE_KEY_DATA])) { + // LoginModel model = LoginModel.fromJson(result[GlobalConfig.HTTP_RESPONSE_KEY_DATA]); + // return model; + // } + // return null; + return await LoginUtil.fetchNetPageData(); } /// 获取缓存的页面数据 Future fetchCachePageData() async { - var result = await NetUtil.getRequestCachedData('/api/v1/sign/in'); - if (!EmptyUtil.isEmpty(result)) { - LoginModel model = LoginModel.fromJson(result); - return model; - } - return null; + // var result = await NetUtil.getRequestCachedData('/api/v1/sign/in'); + // if (!EmptyUtil.isEmpty(result)) { + // LoginModel model = LoginModel.fromJson(result); + // return model; + // } + // return null; + return await LoginUtil.fetchCachePageData(); } } diff --git a/lib/pages/login_page/invite/bloc/login_invite_bloc.dart b/lib/pages/login_page/invite/bloc/login_invite_bloc.dart index 97b3c75..6a48db1 100644 --- a/lib/pages/login_page/invite/bloc/login_invite_bloc.dart +++ b/lib/pages/login_page/invite/bloc/login_invite_bloc.dart @@ -6,7 +6,7 @@ import 'package:zhiying_comm/util/empty_util.dart'; import 'login_invite_repository.dart'; class LoginInviteBloc extends Bloc { - LoginInviteRepostitory repostitory; + LoginInviteRepository repostitory; LoginInviteBloc({@required this.repostitory}); @@ -45,9 +45,9 @@ class LoginInviteBloc extends Bloc { Stream _mapQueryEventToState(LoginInviteQueryEvent event) async* { var data = await repostitory.fetchInviteUserInfo(event); if (!EmptyUtil.isEmpty(data)) - yield LoginInviteQuerySuccess(model: data); + yield LoginInviteQuerySuccessState(model: data, pageMdel: repostitory?.pageModel); else - yield LoginInviteQueryError(); + yield LoginInviteQueryErrorState(); } /// 提交 @@ -56,6 +56,6 @@ class LoginInviteBloc extends Bloc { if (!EmptyUtil.isEmpty(data)) yield LoginInviteSubmitSuccess(model: data); else - yield LoginInviteSubmitError(); + yield LoginInviteSubmitErrorState(); } } diff --git a/lib/pages/login_page/invite/bloc/login_invite_repository.dart b/lib/pages/login_page/invite/bloc/login_invite_repository.dart index d65448b..7cef84c 100644 --- a/lib/pages/login_page/invite/bloc/login_invite_repository.dart +++ b/lib/pages/login_page/invite/bloc/login_invite_repository.dart @@ -1,39 +1,47 @@ import 'package:zhiying_base_widget/pages/login_page/invite/bloc/bloc.dart'; import 'package:zhiying_base_widget/pages/login_page/invite/model/login_invite_user.dart'; import 'package:zhiying_base_widget/pages/login_page/model/login_model.dart'; -import 'package:zhiying_base_widget/pages/login_page/model/login_user.dart'; import 'package:zhiying_comm/util/empty_util.dart'; import 'package:zhiying_comm/util/net_util.dart'; import 'package:zhiying_comm/util/global_config.dart'; +import 'package:zhiying_comm/models/user/user_info_model.dart'; import '../../login_util.dart'; -class LoginInviteRepostitory { +class LoginInviteRepository { + LoginModel pageModel; + /// 获取数据,如果缓存有,则获取缓存的数据 Future fetchData() async { - var result = await LoginUtil.getLoginModel(); - if (!EmptyUtil.isEmpty(result)) { - return result; + pageModel = await LoginUtil.getLoginModel(); + if (!EmptyUtil.isEmpty(pageModel)) { + return pageModel; } return null; } /// 获取邀请人信息 Future fetchInviteUserInfo(LoginInviteQueryEvent event) async { - var result = await NetUtil.post('/api/v1/user/invite/${event.num}'); + var result = await NetUtil.post('/api/v1/user/invite/${event.num}', method: NetMethod.GET); if (NetUtil.isSuccess(result) && !EmptyUtil.isEmpty(result[GlobalConfig.HTTP_RESPONSE_KEY_DATA])) { LoginInviteUser model = LoginInviteUser.fromJson(result[GlobalConfig.HTTP_RESPONSE_KEY_DATA]); - return model; + if(null != model) + return model; + else return null; } else { return null; } } /// 提交 - Future submitInvite(LoginInviteSubmitEvent event) async { - var result = await NetUtil.post('/api/v1/user/invite/ack', params: {'mobile': event.mobile, 'superior_user_id': event.num}); + Future submitInvite(LoginInviteSubmitEvent event) async { + var result = await NetUtil.post('/api/v1/user/invite/ack', params: {'mobile': event.mobile, 'parent_uid': event.num}); if (NetUtil.isSuccess(result) && !EmptyUtil.isEmpty(result[GlobalConfig.HTTP_RESPONSE_KEY_DATA])) { - LoginUser model = LoginUser.fromJson(result[GlobalConfig.HTTP_RESPONSE_KEY_DATA]); - return model; + UserInfoModel model = UserInfoModel.fromJson(result[GlobalConfig.HTTP_RESPONSE_KEY_DATA]); + if (null != model) { + model.mobile = event.mobile; + return model; + } + return null; } return null; } diff --git a/lib/pages/login_page/invite/bloc/login_invite_state.dart b/lib/pages/login_page/invite/bloc/login_invite_state.dart index ebb0a79..f94b16c 100644 --- a/lib/pages/login_page/invite/bloc/login_invite_state.dart +++ b/lib/pages/login_page/invite/bloc/login_invite_state.dart @@ -2,7 +2,7 @@ import 'package:equatable/equatable.dart'; import 'package:flutter/cupertino.dart'; import 'package:zhiying_base_widget/pages/login_page/invite/model/login_invite_user.dart'; import 'package:zhiying_base_widget/pages/login_page/model/login_model.dart'; -import 'package:zhiying_base_widget/pages/login_page/model/login_user.dart'; +import 'package:zhiying_comm/models/user/user_info_model.dart'; abstract class LoginInviteState extends Equatable { const LoginInviteState(); @@ -36,7 +36,7 @@ class LoginInviteErrorState extends LoginInviteState { /// 邀请码成功 class LoginInviteSubmitSuccess extends LoginInviteState { - final LoginUser model; + final UserInfoModel model; const LoginInviteSubmitSuccess({@required this.model}); @@ -45,30 +45,31 @@ class LoginInviteSubmitSuccess extends LoginInviteState { } /// 邀请码失败 -class LoginInviteSubmitError extends LoginInviteState { +class LoginInviteSubmitErrorState extends LoginInviteState { final String msg; - const LoginInviteSubmitError({this.msg}); + const LoginInviteSubmitErrorState({this.msg}); @override List get props => [this.msg]; } /// 查询邀请人成功 -class LoginInviteQuerySuccess extends LoginInviteState { +class LoginInviteQuerySuccessState extends LoginInviteState { final LoginInviteUser model; + final LoginModel pageMdel; - const LoginInviteQuerySuccess({@required this.model}); + const LoginInviteQuerySuccessState({@required this.model, @required this.pageMdel}); @override List get props => [this.model]; } /// 查询邀请人失败 -class LoginInviteQueryError extends LoginInviteState { +class LoginInviteQueryErrorState extends LoginInviteState { final String msg; - const LoginInviteQueryError({this.msg}); + const LoginInviteQueryErrorState({this.msg}); @override List get props => [this.msg]; diff --git a/lib/pages/login_page/invite/login_invite_page.dart b/lib/pages/login_page/invite/login_invite_page.dart index 952afb3..2df9f15 100644 --- a/lib/pages/login_page/invite/login_invite_page.dart +++ b/lib/pages/login_page/invite/login_invite_page.dart @@ -1,9 +1,12 @@ import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:provider/provider.dart'; import 'package:zhiying_base_widget/pages/login_page/invite/bloc/bloc.dart'; import 'package:zhiying_base_widget/pages/login_page/invite/bloc/login_invite_repository.dart'; import 'package:zhiying_base_widget/pages/login_page/model/login_model.dart'; import 'package:zhiying_comm/zhiying_comm.dart'; +import 'package:cached_network_image/cached_network_image.dart'; +import 'package:zhiying_comm/util/empty_util.dart'; import 'model/login_invite_user.dart'; @@ -11,14 +14,13 @@ import 'model/login_invite_user.dart'; /// 邀请页面 /// class LoginInvitePage extends StatelessWidget { - @override Widget build(BuildContext context) { return Scaffold( resizeToAvoidBottomInset: false, backgroundColor: HexColor.fromHex('#FFFFFF'), body: BlocProvider( - create: (_) => LoginInviteBloc(repostitory: LoginInviteRepostitory())..add(LoginInviteInitEvent()), + create: (_) => LoginInviteBloc(repostitory: LoginInviteRepository())..add(LoginInviteInitEvent()), child: LoginInvitePageContainer(), ), ); @@ -33,15 +35,121 @@ class LoginInvitePageContainer extends StatefulWidget { } class _LoginInvitePageContainerState extends State { + TextEditingController _editingController; + FocusNode _focusNode; + bool _showInviteInfo = false; + + /// 返回上一页 + void _openPop() { + if (Navigator.canPop(context)) { + Navigator.pop(context); + } + } + + /// 注册成功跳转 + void _successJump(){ + Navigator.pushAndRemoveUntil( + context, + MaterialPageRoute(builder: (BuildContext context) => PageFactory.create('homePage', null)), + (Route route) => false, + ); + } + + /// 输入框输入变化 + void _onChange(String string) { + setState(() { + _showInviteInfo = false; + }); + print('$string'); + if (!EmptyUtil.isEmpty(string) && string.length >= 3) { + _queryInviteInfo(string); + } + } + + /// 查询邀请人 + void _queryInviteInfo(String inviteNum) { + if (!EmptyUtil.isEmpty(inviteNum) && inviteNum.length < 3) { + return; + } + BlocProvider.of(context).add(LoginInviteQueryEvent(num: inviteNum)); + } + + /// 填写邀请啊吗 + void _submitOnClick(LoginInviteUser inviteUser) async { + _focusNode.unfocus(); + + /// 邀请码 + String inviteNum = inviteUser?.userId ?? ''; + + /// 手机号 + String mobile = Provider.of(context, listen: false)?.getUserInfoModel()?.mobile ?? ''; + if (!EmptyUtil.isEmpty(inviteNum) && !EmptyUtil.isEmpty(mobile)) { + BlocProvider.of(context).add(LoginInviteSubmitEvent(mobile: mobile, num: inviteNum)); + } + } + + @override + void initState() { + _editingController = TextEditingController(); + _focusNode = FocusNode(); + super.initState(); + } + + @override + void didChangeDependencies() { + + super.didChangeDependencies(); + } + + @override + void dispose() { + _editingController?.dispose(); + _focusNode?.unfocus(); + _focusNode?.dispose(); + super.dispose(); + } @override Widget build(BuildContext context) { return BlocConsumer( listener: (context, state) {}, buildWhen: (previous, current) { + /// 提交失败 + if (current is LoginInviteSubmitErrorState) { + return false; + } + + /// 数据加载出错 + if (current is LoginInviteErrorState) { + return false; + } + /// 查询邀请人失败 + if(current is LoginInviteQueryErrorState){ + return false; + } + /// 邀请人查询成功 + if(current is LoginInviteQuerySuccessState){ + _showInviteInfo = true; + return true; + } + /// 邀请码成功 跳转 + if (current is LoginInviteSubmitSuccess) { + // 缓存数据 + Provider.of(context, listen: false).setUserInfo(current.model); + _successJump(); + return false; + } return true; }, builder: (context, state) { + print(state); + if (state is LoginInviteLoadedState) { + return _getMainWidget(state.model, null); + } + if (state is LoginInviteQuerySuccessState) { + return _getMainWidget(state.pageMdel, state.model); + } + /// 骨架屏 return Container(); }, @@ -49,24 +157,184 @@ class _LoginInvitePageContainerState extends State { } /// 主视图 - Widget _getMainWidget(LoginModel model) { - return Column(children: [ + Widget _getMainWidget(LoginModel model, LoginInviteUser inviteUser) { + return Column( + children: [ + /// appbar + _getAppBar(model), + + /// 标题 + Padding(padding: const EdgeInsets.only(left: 27.5, right: 27.5, top: 40), child: _getTitleWidget(model)), + + /// 输入框 + Padding(padding: const EdgeInsets.only(left: 27.5, right: 27.5, top: 30), child: _getInviteInputWidget(model)), + + /// 邀请人信息 + Visibility( + visible: inviteUser != null && _showInviteInfo, + child: Padding(padding: const EdgeInsets.only(left: 27.5, right: 27.5, top: 8), child: _getInviteInfoWidget(inviteUser))), - ],); + /// 按钮 + Padding(padding: const EdgeInsets.only(left: 27.5, right: 27.5, top: 30), child: _getSubmiBtnWidget(model, inviteUser)), + ], + ); } /// appBar - Widget _getAppBar(LoginModel model) {} + Widget _getAppBar(LoginModel model) { + return AppBar( + backgroundColor: HexColor.fromHex('#FFFFFF'), + elevation: 0, + title: Text( + model?.invite?.appBarTitle ?? '登录', + style: TextStyle(color: HexColor.fromHex(model?.invite?.appBarTitleColor ?? '#333333')), + ), + centerTitle: true, + leading: IconButton( + icon: Icon( + Icons.arrow_back_ios, + size: 22, + color: HexColor.fromHex('#333333'), + ), + onPressed: () => _openPop(), + ), + ); + } /// title - Widget _getTitleWidget(LoginModel model) {} + Widget _getTitleWidget(LoginModel model) { + return Align( + alignment: Alignment.centerLeft, + child: Text( + model?.invite?.title ?? '输入邀请码', + style: TextStyle(color: HexColor.fromHex(model?.invite?.titleColor ?? '#333333'), fontSize: 25), + )); + } /// 邀请码输入框 - Widget _getInviteInputWidget(LoginModel model) {} + Widget _getInviteInputWidget(LoginModel model) { + return _getCustomInputWidget( + hint: model?.invite?.inputInviteText ?? '请输入邀请码', + controller: _editingController, + focusNode: _focusNode, + onChanged: _onChange, + hintColor: model?.invite?.inputHintColor ?? '#999999', + bgColor: model?.invite?.inputBgColor ?? '#F7F7F7', + textColor: model?.invite?.inputInviteTextColor ?? '#333333', + iconUrl: model?.invite?.inputInviteIcon ?? ''); + } /// 邀请人信息 - Widget _getInviteInfoWidget(LoginInviteUser model) {} + Widget _getInviteInfoWidget(LoginInviteUser model) { + return Container( + // height: 77.5, + decoration: BoxDecoration(borderRadius: BorderRadius.circular(8), border: Border.all(color: HexColor.fromHex('#E8E8E8'), width: 0.5)), + padding: const EdgeInsets.all(15), + child: Row( + children: [ + /// 头像 + CircleAvatar( + radius: 23.5, + backgroundImage: CachedNetworkImageProvider(model?.avatar ?? ''), + ), + const SizedBox(width: 13), + Column( + mainAxisAlignment: MainAxisAlignment.spaceAround, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + /// 名字 + Text( + '${model?.nickname}', + style: TextStyle(color: HexColor.fromHex(model?.nickNameColor), fontSize: 13), + ), + + /// 邀请 + RichText( + text: TextSpan(text: '邀请您进入', style: TextStyle(fontSize: 11, color: HexColor.fromHex(model?.nickNameColor)), children: [ + TextSpan( + text: '${model?.appName}', + style: TextStyle(fontSize: 11, color: HexColor.fromHex(model?.appNameColor)), + ), + ]), + ) + ], + ) + ], + ), + ); + } /// 按钮 - Widget _getSubmitButtomWidget(LoginModel model) {} + Widget _getSubmiBtnWidget(LoginModel model, LoginInviteUser inviteUser) { + return Material( + child: Container( + height: 52, + width: double.infinity, + color: Colors.white, + child: RaisedButton( + child: Text( + model?.invite?.btnSubmitText ?? '进入智莺生活', + style: TextStyle(fontSize: 15), + ), + textColor: HexColor.fromHex(model?.invite?.btnSubmitTextColor ?? '#FFFFFF'), + color: HexColor.fromHex(model?.invite?.btnSubmitBgColor ?? '#FF3939'), + disabledColor: HexColor.fromHex(model?.invite?.btnBanBgColor ?? '#F5F5F5'), + disabledTextColor: HexColor.fromHex(model?.invite?.btnBanTextColor ?? '#999999'), + elevation: 5, + shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(52 / 2)), + onPressed: _showInviteInfo && inviteUser != null ? ()=> _submitOnClick(inviteUser) : null, + ), + ), + ); + } + + /// 自定义输入框 + Widget _getCustomInputWidget( + {String hint, String hintColor, String bgColor, String textColor, String iconUrl, TextEditingController controller, ValueChanged onChanged, FocusNode focusNode}) { + var border = OutlineInputBorder(borderRadius: BorderRadius.circular(8), borderSide: BorderSide(color: HexColor.fromHex(bgColor), width: 0)); + + return Container( + height: 42, + padding: const EdgeInsets.symmetric(horizontal: 15), + decoration: BoxDecoration( + color: HexColor.fromHex(bgColor), + borderRadius: BorderRadius.circular(8), + ), + child: Row( + mainAxisAlignment: MainAxisAlignment.start, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + CachedNetworkImage( + imageUrl: iconUrl ?? '', + width: 10, + ), + Expanded( + child: TextField( + controller: controller, + focusNode: focusNode, + onChanged: onChanged, + expands: false, + style: TextStyle(color: HexColor.fromHex(textColor)), + maxLines: 1, + keyboardType: TextInputType.number, + decoration: InputDecoration( + contentPadding: EdgeInsets.only(top: 30, left: 7.5), + hintText: hint, + hintStyle: TextStyle(fontSize: 13, color: HexColor.fromHex(hintColor)), + hintMaxLines: 1, + filled: true, + fillColor: Colors.transparent, + border: border, + focusedBorder: border, + enabledBorder: border, + disabledBorder: border, + errorBorder: border, + focusedErrorBorder: border, + ), + ), + ), + ], + ), + ); + } } diff --git a/lib/pages/login_page/invite/model/login_invite_user.dart b/lib/pages/login_page/invite/model/login_invite_user.dart index 23a7816..0b0fbd5 100644 --- a/lib/pages/login_page/invite/model/login_invite_user.dart +++ b/lib/pages/login_page/invite/model/login_invite_user.dart @@ -2,13 +2,19 @@ class LoginInviteUser { String userId; String nickname; String appName; + String nickNameColor; + String appNameColor; + String avatar; LoginInviteUser({this.userId, this.nickname, this.appName}); LoginInviteUser.fromJson(Map json) { - userId = json['user_id']; - nickname = json['nickname']; - appName = json['app_name']; + userId = json['user_id']?.toString(); + nickname = json['nickname']?.toString(); + appName = json['app_name']?.toString(); + avatar = json['avatar']?.toString(); + appNameColor = json['app_name_color']?.toString(); + nickNameColor = json['nickname_color']?.toString(); } Map toJson() { @@ -16,6 +22,9 @@ class LoginInviteUser { data['user_id'] = this.userId; data['nickname'] = this.nickname; data['app_name'] = this.appName; + data['nickname_color'] = this.nickNameColor; + data['app_name_color'] = this.appNameColor; + data['avatar'] = this.avatar; return data; } } diff --git a/lib/pages/login_page/login_page.dart b/lib/pages/login_page/login_page.dart index 0692b21..5bfd947 100644 --- a/lib/pages/login_page/login_page.dart +++ b/lib/pages/login_page/login_page.dart @@ -47,6 +47,13 @@ class _LoginPageContainerState extends State { } } + /// 返回上一页 + void _openPop(){ + if(Navigator.canPop(context)){ + Navigator.pop(context); + } + } + /// 第三方登陆 void _otherLoginClick(BottomIcons model) { print('第三方登陆${model.type}'); @@ -134,10 +141,13 @@ class _LoginPageContainerState extends State { AppBar( backgroundColor: Colors.transparent, elevation: 0, - leading: Icon( - Icons.arrow_back_ios, - size: 22, - color: HexColor.fromHex('#333333'), + leading: IconButton( + icon: Icon( + Icons.arrow_back_ios, + size: 22, + color: HexColor.fromHex('#333333'), + ), + onPressed: ()=> _openPop(), ), ), Column( diff --git a/lib/pages/login_page/login_util.dart b/lib/pages/login_page/login_util.dart index 86b562e..33d681f 100644 --- a/lib/pages/login_page/login_util.dart +++ b/lib/pages/login_page/login_util.dart @@ -18,9 +18,9 @@ class LoginUtil{ /// 获取数据 static Future getLoginModel() async{ - var cache = await _fetchCachePageData(); + var cache = await fetchCachePageData(); if (!EmptyUtil.isEmpty(cache)) return cache; - var result = await _fetchNetPageData(); + var result = await fetchNetPageData(); if(!EmptyUtil.isEmpty(result)) return result; return null; @@ -34,7 +34,7 @@ class LoginUtil{ /// 获取缓存的页面数据 - static Future _fetchCachePageData() async { + static Future fetchCachePageData() async { var result = await NetUtil.getRequestCachedData(_URL); if (!EmptyUtil.isEmpty(result)) { LoginModel model = LoginModel.fromJson(result); @@ -44,8 +44,8 @@ class LoginUtil{ } /// 获取页面数据 - static Future _fetchNetPageData() async { - var result = await NetUtil.post(_URL, method: NetMethod.GET); + static Future fetchNetPageData() async { + var result = await NetUtil.post(_URL, method: NetMethod.GET, cache: true); if (NetUtil.isSuccess(result) && !EmptyUtil.isEmpty(result[GlobalConfig.HTTP_RESPONSE_KEY_DATA])) { LoginModel model = LoginModel.fromJson(result[GlobalConfig.HTTP_RESPONSE_KEY_DATA]); return model; diff --git a/lib/pages/login_page/model/login_user.dart b/lib/pages/login_page/model/login_user.dart deleted file mode 100644 index 9dc33a7..0000000 --- a/lib/pages/login_page/model/login_user.dart +++ /dev/null @@ -1,43 +0,0 @@ -/// token : "6209c60befba0f34c3ade079409337713ddab9c5" -/// user_id : "55" -/// username : "1328603811x" -/// perms : ["app_zhiyingshenghuo_access"] -/// register_invite_code_enable : "0" - -class LoginUser { - String token; - String userId; - String username; - List perms; - String registerInviteCodeEnable; - - LoginUser( - {this.token, - this.userId, - this.username, - this.perms, - this.registerInviteCodeEnable}); - - LoginUser.fromJson(Map json) { - token = json['token']; - userId = json['user_id']; - username = json['username']; - perms = json['perms'].cast(); - registerInviteCodeEnable = json['register_invite_code_enable']; - } - - Map toJson() { - final Map data = new Map(); - data['token'] = this.token; - data['user_id'] = this.userId; - data['username'] = this.username; - data['perms'] = this.perms; - data['register_invite_code_enable'] = this.registerInviteCodeEnable; - return data; - } - - @override - String toString() { - return 'LoginUser{token: $token, userId: $userId, username: $username, perms: $perms, registerInviteCodeEnable: $registerInviteCodeEnable}'; - } -} diff --git a/lib/pages/login_page/notifier/user_info_notifier.dart b/lib/pages/login_page/notifier/user_info_notifier.dart deleted file mode 100644 index 75ca6fb..0000000 --- a/lib/pages/login_page/notifier/user_info_notifier.dart +++ /dev/null @@ -1,35 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:zhiying_base_widget/pages/login_page/model/login_user.dart'; -import 'package:zhiying_comm/util/empty_util.dart'; - -/// -/// 用户信息 -/// -class UserInfoNotifier with ChangeNotifier { - LoginUser userInfo; - - /// 更新用户数据 - void setUserInfo(LoginUser loginUser) { - print('${loginUser.toString()}'); - this.userInfo = loginUser; - // 缓存数据 TODO - - } - - /// 退出登陆 - void unLogin(){ - this.userInfo = null; - // 清除缓存数据 TODO - } - - /// 获取登陆数据 - LoginUser getLoginUserInfo(){ - if(null != userInfo){ - return userInfo; - } - // TODO 需要读取缓存的数据? - return null; - } - - -} diff --git a/lib/register.dart b/lib/register.dart index d2a88a7..7c5850a 100644 --- a/lib/register.dart +++ b/lib/register.dart @@ -18,6 +18,7 @@ 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 'pages/login_page/account/login_account_page.dart'; import 'pages/login_page/invite/login_invite_page.dart'; @@ -55,7 +56,7 @@ class BaseWidgetRegister { // /// 可滚动banner WidgetFactory.regist('index_carousel', HomeSlideBannerCreater()); WidgetFactory.regist('index_recommend_list', GoodsListCreater()); - // 首页快速入口 + /// 首页快速入口 WidgetFactory.regist('home_quick_entry', HomeQuickEntryCreater()); // // /// 首页快速入口 @@ -67,26 +68,17 @@ 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())); + 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/home/home_banner/bloc/home_banner_repository.dart b/lib/widgets/home/home_banner/bloc/home_banner_repository.dart index 701488a..296aaa6 100644 --- a/lib/widgets/home/home_banner/bloc/home_banner_repository.dart +++ b/lib/widgets/home/home_banner/bloc/home_banner_repository.dart @@ -17,9 +17,7 @@ class HomeBannerRepository { /// 获取网路数据 Future fetchNetData({@required int modId}) async { - var result = await NetUtil.post('/api/v1/mod', params: { - 'ids': [modId] - }); + var result = await NetUtil.post('/api/v1/mod', params: {'ids': [modId]}, cache: true); if (NetUtil.isSuccess(result)) { return HomeBannerModel(); } diff --git a/lib/widgets/home/home_goods/bloc/home_goods_header_bloc.dart b/lib/widgets/home/home_goods/bloc/home_goods_header_bloc.dart index b2e79d7..7fdd063 100644 --- a/lib/widgets/home/home_goods/bloc/home_goods_header_bloc.dart +++ b/lib/widgets/home/home_goods/bloc/home_goods_header_bloc.dart @@ -14,7 +14,7 @@ class HomeGoodsHeaderBloc extends BlocBase { @override void dispose() { - _tabController.close(); + _tabController?.close(); _tabController = null; } 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 bec6cb3..cccc7e4 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 @@ -5,7 +5,7 @@ class HomeQuickEntryRepository { /// 获取数据 Future fetchData() async { - var result = await NetUtil.post('/api/v1/mod', params: {'ids':[7]}); + var result = await NetUtil.post('/api/v1/mod', params: {'ids':[7]}, cache: true); if(NetUtil.isSuccess(result)){ } 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 868829d..2e4fac5 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 @@ -24,7 +24,7 @@ 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]); diff --git a/lib/widgets/home_slide_banner/bloc/home_slide_banner_repository.dart b/lib/widgets/home_slide_banner/bloc/home_slide_banner_repository.dart deleted file mode 100644 index 2fe180e..0000000 --- a/lib/widgets/home_slide_banner/bloc/home_slide_banner_repository.dart +++ /dev/null @@ -1,37 +0,0 @@ -import 'package:flutter/cupertino.dart'; -import 'package:zhiying_base_widget/widgets/home/home_slide_banner/model/home_slide_banner_model.dart'; -import 'package:zhiying_comm/util/empty_util.dart'; -import 'package:zhiying_comm/util/global_config.dart'; -import 'package:zhiying_comm/util/net_util.dart'; - -class HomeSlideBannerRepository { - /// 获取缓存数据 - Future> fetchCachedDate( - {@required int id}) async { - var cached = await NetUtil.getRequestCachedData('/api/v1/mod', params: { - 'ids': [id] - }); - if (!EmptyUtil.isEmpty(cached)) { - HomeSlideBannerModel model = HomeSlideBannerModel.fromJson(cached); - if (null != model && !EmptyUtil.isEmpty(model.items)) { - return model.items; - } - } - return null; - } - - /// 获取数据 - Future> fetchData({@required int id}) async { - var params = await NetUtil.post('/api/v1/mod', params: { - 'ids': [id] - }); - if (NetUtil.isSuccess(params)) { - HomeSlideBannerModel model = HomeSlideBannerModel.fromJson( - params[GlobalConfig.HTTP_RESPONSE_KEY_DATA]); - if (null != model && !EmptyUtil.isEmpty(model.items)) { - return model.items; - } - } - return null; - } -}