| @@ -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<MyApp> { | |||
| ErrorWidget.builder = (FlutterErrorDetails errorDetails) { | |||
| return getErrorWidget(context, errorDetails); | |||
| }; | |||
| return MaterialApp( | |||
| home: HomePage(), | |||
| return MultiProvider( | |||
| providers: [ | |||
| ChangeNotifierProvider.value(value: UserInfoNotifier()), | |||
| ], | |||
| child: MaterialApp( | |||
| home: HomePage(), | |||
| ), | |||
| ); | |||
| } | |||
| } | |||
| @@ -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<HomePage> { | |||
| @override | |||
| Widget build(BuildContext context) { | |||
| print('home_page build'); | |||
| return MultiProvider( | |||
| providers: [ | |||
| ChangeNotifierProvider.value(value: UserInfoNotifier()), | |||
| ], | |||
| child: BlocProvider<HomePageBloc>( | |||
| bloc: HomePageBloc(), | |||
| child: _HomePageContainer(), | |||
| ), | |||
| return BlocProvider<HomePageBloc>( | |||
| bloc: HomePageBloc(), | |||
| child: _HomePageContainer(), | |||
| ); | |||
| } | |||
| } | |||
| @@ -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<LoginUser> loginTypeVcode(LoginAccountTypeVcodeEvent event) async{ | |||
| Future<UserInfoModel> 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; | |||
| } | |||
| @@ -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<Object> 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}); | |||
| } | |||
| @@ -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<LoginAccountPageContianer> implements OnClickListener { | |||
| TextEditingController _phoneEdController; | |||
| TextEditingController _vcodeEdController; | |||
| TextEditingController _passEdController; | |||
| @@ -53,29 +51,37 @@ class _LoginAccountPageContianerState extends State<LoginAccountPageContianer> 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<dynamic> route) => false, | |||
| (Route<dynamic> route) => false, | |||
| ); | |||
| } | |||
| /// 返回上一页 | |||
| void _openPop() { | |||
| if (Navigator.canPop(context)) { | |||
| Navigator.pop(context); | |||
| } | |||
| } | |||
| /// 登陆 | |||
| void _submitOnClick() { | |||
| print('登陆'); | |||
| if(_checkParam(true)) { | |||
| if (_checkParam(true)) { | |||
| if (_useVcode) { | |||
| BlocProvider.of<LoginAccountBloc>(context).add( | |||
| LoginAccountTypeVcodeEvent(mobile: _phoneEdController?.text?.toString()?.trim() ?? '', captcha: _vcodeEdController?.text?.toString()?.trim() ?? '')); | |||
| BlocProvider.of<LoginAccountBloc>(context).add(LoginAccountTypeVcodeEvent(mobile: _phoneEdController?.text?.toString()?.trim() ?? '', captcha: _vcodeEdController?.text?.toString()?.trim() ?? '')); | |||
| } else { | |||
| BlocProvider.of<LoginAccountBloc>(context).add(LoginAccountTypePasswordEvent(username: _phoneEdController?.text?.toString()?.trim() ?? '', | |||
| password: _passEdController?.text?.toString()?.trim() ?? '')); | |||
| BlocProvider.of<LoginAccountBloc>(context).add(LoginAccountTypePasswordEvent(username: _phoneEdController?.text?.toString()?.trim() ?? '', password: _passEdController?.text?.toString()?.trim() ?? '')); | |||
| } | |||
| } | |||
| } | |||
| @@ -88,10 +94,10 @@ class _LoginAccountPageContianerState extends State<LoginAccountPageContianer> 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<LoginAccountPageContianer> 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<LoginAccountPageContianer> 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<LoginAccountPageContianer> 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<LoginAccountPageContianer> i | |||
| @override | |||
| bool onVcodeClick() { | |||
| /// 获取验证码 | |||
| if(_checkPhoneNumParam(true)) { | |||
| if (_checkPhoneNumParam(true)) { | |||
| BlocProvider.of<LoginAccountBloc>(context).add(LoginAccountGetVcodeEvent(mobile: _phoneEdController?.text?.toString()?.trim() ?? '')); | |||
| return true; | |||
| } | |||
| @@ -238,34 +243,36 @@ class _LoginAccountPageContianerState extends State<LoginAccountPageContianer> i | |||
| @override | |||
| Widget build(BuildContext context) { | |||
| return BlocConsumer<LoginAccountBloc, LoginAccountState>( | |||
| 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<UserInfoNotifier>(context, listen: false)?.setUserInfo(current.model); | |||
| if (current?.model?.registerInviteCodeEnable == '0') { | |||
| Fluttertoast.showToast(msg: '登陆成功~'); | |||
| /// 缓存登陆数据 | |||
| Provider.of<UserInfoNotifier>(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<LoginAccountPageContianer> i | |||
| print(model); | |||
| return Column( | |||
| children: <Widget>[ | |||
| /// appBar | |||
| _getAppBarWidget(model), | |||
| @@ -331,10 +337,13 @@ class _LoginAccountPageContianerState extends State<LoginAccountPageContianer> 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<LoginAccountPageContianer> 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<LoginAccountPageContianer> 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<LoginAccountPageContianer> 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<LoginAccountPageContianer> 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<LoginAccountPageContianer> 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<LoginAccountPageContianer> 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<LoginAccountPageContianer> 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<String> onChanged, FocusNode focusNode}) { | |||
| Widget _getCustomInputWidget( | |||
| {String hint, String hintColor, String bgColor, String textColor, String iconUrl, TextEditingController controller, ValueChanged<String> onChanged, FocusNode focusNode}) { | |||
| var border = OutlineInputBorder(borderRadius: BorderRadius.circular(8), borderSide: BorderSide(color: HexColor.fromHex(bgColor), width: 0)); | |||
| return Container( | |||
| @@ -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<LoginModel> 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<LoginModel> 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(); | |||
| } | |||
| } | |||
| @@ -6,7 +6,7 @@ import 'package:zhiying_comm/util/empty_util.dart'; | |||
| import 'login_invite_repository.dart'; | |||
| class LoginInviteBloc extends Bloc<LoginInviteEvent, LoginInviteState> { | |||
| LoginInviteRepostitory repostitory; | |||
| LoginInviteRepository repostitory; | |||
| LoginInviteBloc({@required this.repostitory}); | |||
| @@ -45,9 +45,9 @@ class LoginInviteBloc extends Bloc<LoginInviteEvent, LoginInviteState> { | |||
| Stream<LoginInviteState> _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<LoginInviteEvent, LoginInviteState> { | |||
| if (!EmptyUtil.isEmpty(data)) | |||
| yield LoginInviteSubmitSuccess(model: data); | |||
| else | |||
| yield LoginInviteSubmitError(); | |||
| yield LoginInviteSubmitErrorState(); | |||
| } | |||
| } | |||
| @@ -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<LoginModel> 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<LoginInviteUser> 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<LoginUser> submitInvite(LoginInviteSubmitEvent event) async { | |||
| var result = await NetUtil.post('/api/v1/user/invite/ack', params: {'mobile': event.mobile, 'superior_user_id': event.num}); | |||
| Future<UserInfoModel> 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; | |||
| } | |||
| @@ -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<Object> 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<Object> 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<Object> get props => [this.msg]; | |||
| @@ -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<LoginInvitePageContainer> { | |||
| 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<dynamic> 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<LoginInviteBloc>(context).add(LoginInviteQueryEvent(num: inviteNum)); | |||
| } | |||
| /// 填写邀请啊吗 | |||
| void _submitOnClick(LoginInviteUser inviteUser) async { | |||
| _focusNode.unfocus(); | |||
| /// 邀请码 | |||
| String inviteNum = inviteUser?.userId ?? ''; | |||
| /// 手机号 | |||
| String mobile = Provider.of<UserInfoNotifier>(context, listen: false)?.getUserInfoModel()?.mobile ?? ''; | |||
| if (!EmptyUtil.isEmpty(inviteNum) && !EmptyUtil.isEmpty(mobile)) { | |||
| BlocProvider.of<LoginInviteBloc>(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<LoginInviteBloc, LoginInviteState>( | |||
| 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<UserInfoNotifier>(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<LoginInvitePageContainer> { | |||
| } | |||
| /// 主视图 | |||
| Widget _getMainWidget(LoginModel model) { | |||
| return Column(children: <Widget>[ | |||
| Widget _getMainWidget(LoginModel model, LoginInviteUser inviteUser) { | |||
| return Column( | |||
| children: <Widget>[ | |||
| /// 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: <Widget>[ | |||
| /// 头像 | |||
| CircleAvatar( | |||
| radius: 23.5, | |||
| backgroundImage: CachedNetworkImageProvider(model?.avatar ?? ''), | |||
| ), | |||
| const SizedBox(width: 13), | |||
| Column( | |||
| mainAxisAlignment: MainAxisAlignment.spaceAround, | |||
| crossAxisAlignment: CrossAxisAlignment.start, | |||
| children: <Widget>[ | |||
| /// 名字 | |||
| 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<String> 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: <Widget>[ | |||
| 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, | |||
| ), | |||
| ), | |||
| ), | |||
| ], | |||
| ), | |||
| ); | |||
| } | |||
| } | |||
| @@ -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<String, dynamic> 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<String, dynamic> 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; | |||
| } | |||
| } | |||
| @@ -47,6 +47,13 @@ class _LoginPageContainerState extends State<LoginPageContainer> { | |||
| } | |||
| } | |||
| /// 返回上一页 | |||
| void _openPop(){ | |||
| if(Navigator.canPop(context)){ | |||
| Navigator.pop(context); | |||
| } | |||
| } | |||
| /// 第三方登陆 | |||
| void _otherLoginClick(BottomIcons model) { | |||
| print('第三方登陆${model.type}'); | |||
| @@ -134,10 +141,13 @@ class _LoginPageContainerState extends State<LoginPageContainer> { | |||
| 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( | |||
| @@ -18,9 +18,9 @@ class LoginUtil{ | |||
| /// 获取数据 | |||
| static Future<LoginModel> 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<LoginModel> _fetchCachePageData() async { | |||
| static Future<LoginModel> 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<LoginModel> _fetchNetPageData() async { | |||
| var result = await NetUtil.post(_URL, method: NetMethod.GET); | |||
| static Future<LoginModel> 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; | |||
| @@ -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<String> perms; | |||
| String registerInviteCodeEnable; | |||
| LoginUser( | |||
| {this.token, | |||
| this.userId, | |||
| this.username, | |||
| this.perms, | |||
| this.registerInviteCodeEnable}); | |||
| LoginUser.fromJson(Map<String, dynamic> json) { | |||
| token = json['token']; | |||
| userId = json['user_id']; | |||
| username = json['username']; | |||
| perms = json['perms'].cast<String>(); | |||
| registerInviteCodeEnable = json['register_invite_code_enable']; | |||
| } | |||
| Map<String, dynamic> toJson() { | |||
| final Map<String, dynamic> data = new Map<String, dynamic>(); | |||
| 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}'; | |||
| } | |||
| } | |||
| @@ -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; | |||
| } | |||
| } | |||
| @@ -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())); | |||
| } | |||
| } | |||
| @@ -17,9 +17,7 @@ class HomeBannerRepository { | |||
| /// 获取网路数据 | |||
| Future<HomeBannerModel> 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(); | |||
| } | |||
| @@ -14,7 +14,7 @@ class HomeGoodsHeaderBloc extends BlocBase { | |||
| @override | |||
| void dispose() { | |||
| _tabController.close(); | |||
| _tabController?.close(); | |||
| _tabController = null; | |||
| } | |||
| @@ -5,7 +5,7 @@ class HomeQuickEntryRepository { | |||
| /// 获取数据 | |||
| Future<dynamic> 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)){ | |||
| } | |||
| @@ -24,7 +24,7 @@ class HomeSlideBannerRepository { | |||
| Future<List<HomeSlideBannerModelItems>> 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]); | |||
| @@ -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<List<HomeSlideBannerModelItems>> 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<List<HomeSlideBannerModelItems>> 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; | |||
| } | |||
| } | |||