diff --git a/lib/pages/login_page/invite/login_invite_page.dart b/lib/pages/login_page/invite/login_invite_page.dart index 0e8c2ab..412a5df 100644 --- a/lib/pages/login_page/invite/login_invite_page.dart +++ b/lib/pages/login_page/invite/login_invite_page.dart @@ -1,10 +1,11 @@ +import 'package:cached_network_image/cached_network_image.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:provider/provider.dart'; import 'package:zhiying_comm/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 'package:zhiying_comm/util/mob_util/mob_util.dart'; +import 'package:zhiying_comm/zhiying_comm.dart'; import 'bloc/bloc.dart'; import 'bloc/login_invite_repository.dart'; @@ -20,7 +21,8 @@ class LoginInvitePage extends StatelessWidget { resizeToAvoidBottomInset: false, backgroundColor: HexColor.fromHex('#FFFFFF'), body: BlocProvider( - create: (_) => LoginInviteBloc(repostitory: LoginInviteRepository())..add(LoginInviteInitEvent()), + create: (_) => LoginInviteBloc(repostitory: LoginInviteRepository()) + ..add(LoginInviteInitEvent()), child: LoginInvitePageContainer(), ), ); @@ -31,7 +33,8 @@ class LoginInvitePage extends StatelessWidget { /// 邀请 class LoginInvitePageContainer extends StatefulWidget { @override - _LoginInvitePageContainerState createState() => _LoginInvitePageContainerState(); + _LoginInvitePageContainerState createState() => + _LoginInvitePageContainerState(); } class _LoginInvitePageContainerState extends State { @@ -50,11 +53,13 @@ class _LoginInvitePageContainerState extends State { } /// 注册成功跳转 - void _successJump(){ + void _successJump() { RouterUtil.hideKeyboard(context); Navigator.pushAndRemoveUntil( context, - MaterialPageRoute(builder: (BuildContext context) => PageFactory.create('homePage', null)), + MaterialPageRoute( + builder: (BuildContext context) => + PageFactory.create('homePage', null)), (Route route) => false, ); } @@ -75,7 +80,8 @@ class _LoginInvitePageContainerState extends State { if (!EmptyUtil.isEmpty(inviteNum) && inviteNum.length < 3) { return; } - BlocProvider.of(context).add(LoginInviteQueryEvent(num: inviteNum)); + BlocProvider.of(context) + .add(LoginInviteQueryEvent(num: inviteNum)); } /// 填写邀请啊吗 @@ -86,23 +92,32 @@ class _LoginInvitePageContainerState extends State { String inviteNum = inviteUser?.userId ?? ''; /// 手机号 - UserInfoModel model = await Provider.of(context, listen: false)?.getUserInfoModel(); + UserInfoModel model = + await Provider.of(context, listen: false) + ?.getUserInfoModel(); String mobile = model?.mobile ?? ''; if (!EmptyUtil.isEmpty(inviteNum) && !EmptyUtil.isEmpty(mobile)) { - BlocProvider.of(context).add(LoginInviteSubmitEvent(mobile: mobile, num: inviteNum)); + BlocProvider.of(context) + .add(LoginInviteSubmitEvent(mobile: mobile, num: inviteNum)); } } @override void initState() { _editingController = TextEditingController(); + // SharedPreferencesUtil.setNetCacheResult(Constants.mobInvitedCode, tgid); + + MobUtil.getInvitedCode().then((value) { + _editingController.text = value; + _onChange(value); + }); + _focusNode = FocusNode(); super.initState(); } @override void didChangeDependencies() { - super.didChangeDependencies(); } @@ -128,19 +143,23 @@ class _LoginInvitePageContainerState extends State { if (current is LoginInviteErrorState) { return false; } + /// 查询邀请人失败 - if(current is LoginInviteQueryErrorState){ + if (current is LoginInviteQueryErrorState) { return false; } + /// 邀请人查询成功 - if(current is LoginInviteQuerySuccessState){ + if (current is LoginInviteQuerySuccessState) { _showInviteInfo = true; return true; } + /// 邀请码成功 跳转 if (current is LoginInviteSubmitSuccess) { // 缓存数据 - Provider.of(context, listen: false).setUserInfo(current.model); + Provider.of(context, listen: false) + .setUserInfo(current.model); _successJump(); return false; } @@ -165,22 +184,31 @@ class _LoginInvitePageContainerState extends State { 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: 40), + child: _getTitleWidget(model)), /// 输入框 - Padding(padding: const EdgeInsets.only(left: 27.5, right: 27.5, top: 30), child: _getInviteInputWidget(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))), + 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)), + Padding( + padding: const EdgeInsets.only(left: 27.5, right: 27.5, top: 30), + child: _getSubmiBtnWidget(model, inviteUser)), ], ); } @@ -193,7 +221,9 @@ class _LoginInvitePageContainerState extends State { elevation: 0, title: Text( model?.invite?.appBarTitle ?? '登录', - style: TextStyle(color: HexColor.fromHex(model?.invite?.appBarTitleColor ?? '#333333')), + style: TextStyle( + color: + HexColor.fromHex(model?.invite?.appBarTitleColor ?? '#333333')), ), centerTitle: true, leading: IconButton( @@ -213,7 +243,9 @@ class _LoginInvitePageContainerState extends State { alignment: Alignment.centerLeft, child: Text( model?.invite?.title ?? '输入邀请码', - style: TextStyle(color: HexColor.fromHex(model?.invite?.titleColor ?? '#333333'), fontSize: 25), + style: TextStyle( + color: HexColor.fromHex(model?.invite?.titleColor ?? '#333333'), + fontSize: 25), )); } @@ -234,10 +266,13 @@ class _LoginInvitePageContainerState extends State { 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)), + 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, @@ -248,20 +283,30 @@ class _LoginInvitePageContainerState extends State { mainAxisAlignment: MainAxisAlignment.spaceAround, crossAxisAlignment: CrossAxisAlignment.start, children: [ + /// 名字 Text( '${model?.nickname}', - style: TextStyle(color: HexColor.fromHex(model?.nickNameColor), fontSize: 13), + 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)), - ), - ]), + 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)), + ), + ]), ) ], ) @@ -282,22 +327,36 @@ class _LoginInvitePageContainerState extends State { model?.invite?.btnSubmitText ?? '进入智莺生活', style: TextStyle(fontSize: 15), ), - textColor: HexColor.fromHex(model?.invite?.btnSubmitTextColor ?? '#FFFFFF'), + 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'), + 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, + 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)); + 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, @@ -326,7 +385,8 @@ class _LoginInvitePageContainerState extends State { decoration: InputDecoration( contentPadding: EdgeInsets.only(top: 30, left: 7.5), hintText: hint, - hintStyle: TextStyle(fontSize: 13, color: HexColor.fromHex(hintColor)), + hintStyle: + TextStyle(fontSize: 13, color: HexColor.fromHex(hintColor)), hintMaxLines: 1, filled: true, fillColor: Colors.transparent, diff --git a/lib/util/mob_util/mob_util.dart b/lib/util/mob_util/mob_util.dart index 4ab8000..114146c 100644 --- a/lib/util/mob_util/mob_util.dart +++ b/lib/util/mob_util/mob_util.dart @@ -7,6 +7,7 @@ import 'package:zhiying_comm/util/global_config.dart'; import 'package:zhiying_comm/util/log/let_log.dart'; import 'package:zhiying_comm/util/mob_util/secverify/quick_login_util.dart'; import 'package:zhiying_comm/util/net_util.dart'; +import 'package:zhiying_comm/util/shared_prefe_util.dart'; /// /// MOB SDK 工具类 @@ -92,9 +93,12 @@ class MobUtil { if (EmptyUtil.isEmpty(vCodeType)) { vCodeType = enumToString(SMSCodeType.NORMAL).toLowerCase(); } - String url = type == SMSCodeType.AUTO ? '/api/v1/mob/sms/tmp/${vCodeType}?phone=${phone}' : '/api/v1/mob/sms/tmp/$vCodeType'; + String url = type == SMSCodeType.AUTO + ? '/api/v1/mob/sms/tmp/${vCodeType}?phone=${phone}' + : '/api/v1/mob/sms/tmp/$vCodeType'; var result = await NetUtil.post(url, method: NetMethod.GET); - if (NetUtil.isSuccess(result) && !EmptyUtil.isEmpty(result[GlobalConfig.HTTP_RESPONSE_KEY_DATA])) { + if (NetUtil.isSuccess(result) && + !EmptyUtil.isEmpty(result[GlobalConfig.HTTP_RESPONSE_KEY_DATA])) { return result[GlobalConfig.HTTP_RESPONSE_KEY_DATA]; } } catch (e, s) { @@ -103,6 +107,15 @@ class MobUtil { return null; } + static Future storeInvitedCode(String code) { + return SharedPreferencesUtil.setStringValue('mobInvitedCode', code); + } + + // 获取一件锁粉邀请码 + static Future getInvitedCode() async { + return SharedPreferencesUtil.getStringValue('mobInvitedCode'); + } + /// 统计MOB验证码提交 // static void _countMobSMS(final String phone, final String code, {String zoneCode = '86'}) async { // try {