Commit e477d911 by tanghuan

调整通过Apple登录的流程

1 parent a293b024
......@@ -18,6 +18,7 @@ class LoginMainState extends Equatable {
final int loginType; // 1=Wechat,2=Apple
final String appleUserIdentifier;
final bool loading;
final bool wechatInstalled;
const LoginMainState({
this.agreed = false,
......@@ -26,6 +27,7 @@ class LoginMainState extends Equatable {
this.loginType = 0,
this.appleUserIdentifier = '',
this.loading = false,
this.wechatInstalled = false,
});
LoginMainState copyWith({
......@@ -33,16 +35,18 @@ class LoginMainState extends Equatable {
bool? showAgreed,
bool? showNeedWechatForApple,
int? loginType,
bool? loading,
String? appleUserIdentifier,
bool? loading,
bool? wechatInstalled,
}) {
return LoginMainState(
agreed: agreed ?? this.agreed,
showAgreed: showAgreed ?? this.showAgreed,
showNeedWechatForApple: showNeedWechatForApple ?? this.showNeedWechatForApple,
loginType: loginType ?? this.loginType,
loading: loading ?? this.loading,
appleUserIdentifier: appleUserIdentifier ?? this.appleUserIdentifier,
loading: loading ?? this.loading,
wechatInstalled: wechatInstalled ?? this.wechatInstalled,
);
}
......@@ -50,10 +54,11 @@ class LoginMainState extends Equatable {
List<Object?> get props => [
agreed,
showAgreed,
loading,
showNeedWechatForApple,
loginType,
appleUserIdentifier,
loading,
wechatInstalled,
];
}
......@@ -65,6 +70,12 @@ class LoginMainCubit extends Cubit<LoginMainState> {
LoginMainCubit(super.initialState) {
_fluwx = getIt.get<Fluwx>();
// 处理微信安装检测
_fluwx.isWeChatInstalled.then((value) {
emit(state.copyWith(wechatInstalled: value));
});
_fluwxCancelable = _fluwx.addSubscriber(_responseListener);
_wechatAuthRepository = getIt.get<WechatAuthRepository>();
_userAuthRepository = getIt.get<UserAuthRepository>();
......@@ -136,8 +147,15 @@ class LoginMainCubit extends Cubit<LoginMainState> {
if (binding == 1) {
_handleLoginSuccess(data);
} else {
// 设置 appleUserIdentifier 状态,通知用户需要授权微信认证
emit(state.copyWith(appleUserIdentifier: data['appleUid']!, showNeedWechatForApple: true));
// 未绑定时,也会返回 sessionCode 和 userCode
if (state.wechatInstalled) {
// 已安装微信APP,直接拉起微信授权,不使用 sessionCode 和 userCode
// 设置 appleUserIdentifier 状态,通知用户需要授权微信认证
emit(state.copyWith(appleUserIdentifier: data['appleUid']!, showNeedWechatForApple: true));
} else {
// 未安装微信APP,使用 sessionCode 和 userCode
_handleLoginSuccess(data);
}
}
}
......@@ -215,7 +233,11 @@ class LoginMainCubit extends Cubit<LoginMainState> {
void _handleLoginSuccess(Map<String, dynamic> data) {
var roles = data['roles'];
// 过滤出家长角色的数据
roles.removeWhere((element) => element['userType'] != 2);
if (roles?.isNotEmpty ?? false) {
roles.removeWhere((element) => element['userType'] != 2);
} else {
roles = [];
}
var sessionCode = data['sessionCode'];
var userCode = data['userCode'];
......
......@@ -146,7 +146,11 @@ class LoginPhoneCubit extends Cubit<LoginPhoneState> {
void _handleLoginSuccess(Map<String, dynamic> data) {
var roles = data['roles'];
// 过滤出家长角色的数据
roles.removeWhere((element) => element['userType'] != 2);
if (roles?.isNotEmpty ?? false) {
roles.removeWhere((element) => element['userType'] != 2);
} else {
roles = [];
}
var sessionCode = data['sessionCode'];
var userCode = data['userCode'];
......
import 'dart:io';
import 'package:appframe/bloc/login_main_cubit.dart';
import 'package:appframe/config/locator.dart';
import 'package:appframe/config/routes.dart';
import 'package:appframe/ui/widgets/login/login_page_agreed_widget.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:fluwx/fluwx.dart';
import 'package:sign_in_with_apple/sign_in_with_apple.dart';
class LoginMainPage extends StatelessWidget {
......@@ -39,6 +37,44 @@ class LoginMainPage extends StatelessWidget {
SizedBox(height: 15),
]
: [];
var wechatLoginBtn = (!Platform.isIOS || state.wechatInstalled)
? [
Padding(
padding: EdgeInsets.symmetric(horizontal: 42.5),
child: SizedBox(
width: double.infinity,
height: 50,
child: ElevatedButton(
onPressed: () async {
if (state.wechatInstalled) {
loginMainCubit.wechatAuth();
} else {
if (!context.mounted) return;
_showWechatNotInstallDialog(context);
}
},
style: ElevatedButton.styleFrom(
backgroundColor: Color(0xFF26C445),
foregroundColor: Colors.white,
textStyle: TextStyle(fontSize: 19),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(27),
),
),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Image.asset('assets/images/login_v2/wechat_white_icon.png'),
SizedBox(width: 4.5),
Text('微信登录'),
],
),
),
),
),
SizedBox(height: 15),
]
: [];
var scaffold = Scaffold(
backgroundColor: Colors.white,
body: SafeArea(
......@@ -60,40 +96,7 @@ class LoginMainPage extends StatelessWidget {
),
SizedBox(height: 40),
...appleLoginBtn,
Padding(
padding: EdgeInsets.symmetric(horizontal: 42.5),
child: SizedBox(
width: double.infinity,
height: 50,
child: ElevatedButton(
onPressed: () async {
if (await getIt.get<Fluwx>().isWeChatInstalled) {
loginMainCubit.wechatAuth();
} else {
if (!context.mounted) return;
_showWechatNotInstallDialog(context);
}
},
style: ElevatedButton.styleFrom(
backgroundColor: Color(0xFF26C445),
foregroundColor: Colors.white,
textStyle: TextStyle(fontSize: 19),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(27),
),
),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Image.asset('assets/images/login_v2/wechat_white_icon.png'),
SizedBox(width: 4.5),
Text('微信登录'),
],
),
),
),
),
SizedBox(height: 15),
...wechatLoginBtn,
_buildAgreement(context, loginMainCubit, state.agreed),
SizedBox(height: 82.5),
Text(
......
import 'dart:io';
import 'package:appframe/bloc/login_phone_cubit.dart';
import 'package:appframe/config/routes.dart';
import 'package:appframe/ui/widgets/login/login_page_agreed_widget.dart';
......@@ -16,6 +18,75 @@ class LoginPhonePage extends StatelessWidget {
child: BlocConsumer<LoginPhoneCubit, LoginPhoneState>(
builder: (ctx, state) {
var loginPhoneCubit = ctx.read<LoginPhoneCubit>();
var iosBackHome = Platform.isIOS
? [
InkWell(
onTap: () {
loginPhoneCubit.goLoginMain();
},
borderRadius: BorderRadius.circular(4),
child: Padding(
padding: EdgeInsets.symmetric(horizontal: 8, vertical: 4),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Icon(
Icons.arrow_back_ios,
size: 16,
color: Color(0xFF7691FA),
),
SizedBox(width: 4),
Text(
'其他方式登录',
style: TextStyle(
fontSize: 14,
color: Color(0xFF7691FA),
decoration: TextDecoration.underline,
decorationColor: Color(0xFF7691FA),
),
strutStyle: StrutStyle(height: 16 / 14),
),
],
),
),
),
]
: [];
var androidBackHome = Platform.isAndroid
? [
Text(
'其他方式登录',
style: TextStyle(
fontSize: 14,
color: Color(0xFF999999),
),
strutStyle: StrutStyle(height: 16 / 14),
),
SizedBox(height: 15),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
InkWell(
onTap: () {
loginPhoneCubit.goLoginMain();
},
child: Image.asset(
'assets/images/login_v2/wechat_green_icon.png',
),
),
SizedBox(width: 25),
InkWell(
onTap: () {
loginPhoneCubit.goLoginQr();
},
child: Image.asset(
'assets/images/login_v2/qr_green_icon.png',
),
),
],
),
]
: [];
return Scaffold(
backgroundColor: Colors.white,
body: SafeArea(
......@@ -40,37 +111,8 @@ class LoginPhonePage extends StatelessWidget {
SizedBox(height: 15),
_buildAgreement(ctx, loginPhoneCubit, state.agreed),
SizedBox(height: 140),
Text(
'其他方式登录',
style: TextStyle(
fontSize: 14,
color: Color(0xFF999999),
),
strutStyle: StrutStyle(height: 16 / 14),
),
SizedBox(height: 15),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
InkWell(
onTap: () {
loginPhoneCubit.goLoginMain();
},
child: Image.asset(
'assets/images/login_v2/wechat_green_icon.png',
),
),
SizedBox(width: 25),
InkWell(
onTap: () {
loginPhoneCubit.goLoginQr();
},
child: Image.asset(
'assets/images/login_v2/qr_green_icon.png',
),
),
],
),
...iosBackHome,
...androidBackHome,
],
),
),
......
import 'dart:io';
import 'package:appframe/bloc/login_qr_cubit.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
......@@ -12,6 +14,70 @@ class LoginQrPage extends StatelessWidget {
child: BlocConsumer<LoginQrCubit, LoginQrState>(
builder: (context, state) {
var loginQrCubit = context.read<LoginQrCubit>();
var iosBackHome = Platform.isIOS
? [
Center(
child: InkWell(
onTap: () {
loginQrCubit.goLoginMain();
},
borderRadius: BorderRadius.circular(4),
child: Padding(
padding: EdgeInsets.symmetric(horizontal: 8, vertical: 4),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Icon(
Icons.arrow_back_ios,
size: 16,
color: Color(0xFF7691FA),
),
SizedBox(width: 4),
Text(
'其他方式登录',
style: TextStyle(
fontSize: 14,
color: Color(0xFF7691FA),
decoration: TextDecoration.underline,
decorationColor: Color(0xFF7691FA),
),
strutStyle: StrutStyle(height: 16 / 14),
),
],
),
),
),
),
]
: [];
var androidBackHome = Platform.isAndroid
? [
Center(
child: Text(
'其他方式登录',
style: TextStyle(
fontSize: 14,
color: Color(0xFF999999),
),
strutStyle: StrutStyle(height: 16 / 14),
),
),
SizedBox(height: 15),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
InkWell(
onTap: () {
loginQrCubit.goLoginMain();
},
child: Image.asset(
'assets/images/login_v2/wechat_green_icon.png',
),
),
],
),
]
: [];
return Scaffold(
backgroundColor: Colors.white,
body: SafeArea(
......@@ -30,30 +96,8 @@ class LoginQrPage extends StatelessWidget {
child: _buildQrCode(loginQrCubit, state),
),
SizedBox(height: 20),
Center(
child: Text(
'其他方式登录',
style: TextStyle(
fontSize: 14,
color: Color(0xFF999999),
),
strutStyle: StrutStyle(height: 16 / 14),
),
),
SizedBox(height: 15),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
InkWell(
onTap: () {
loginQrCubit.goLoginMain();
},
child: Image.asset(
'assets/images/login_v2/wechat_green_icon.png',
),
),
],
),
...iosBackHome,
...androidBackHome,
],
),
),
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!