google和apple登录ok
This commit is contained in:
@@ -57,7 +57,7 @@ class _HomePageState extends State<HomePage> with AutomaticKeepAliveClientMixin
|
||||
return Scaffold(
|
||||
resizeToAvoidBottomInset: false,
|
||||
body: AppBackend(
|
||||
child: Column(
|
||||
child: ListView(
|
||||
children: [
|
||||
AppHeader(),
|
||||
UploadBox(
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import 'package:derma_flutter/api/dto/skin_check_dto.dart';
|
||||
import 'package:derma_flutter/config/theme/custom_colors.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:remixicon/remixicon.dart';
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
import 'package:derma_flutter/api/dto/skin_check_dto.dart';
|
||||
import 'package:derma_flutter/api/endpoints/skin_api.dart';
|
||||
import 'package:derma_flutter/config/theme/custom_colors.dart';
|
||||
import 'package:derma_flutter/providers/app_store.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_easyloading/flutter_easyloading.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:remixicon/remixicon.dart';
|
||||
|
||||
import 'common_box.dart';
|
||||
@@ -20,6 +22,17 @@ class WarningBox extends StatefulWidget {
|
||||
class _WarningBoxState extends State<WarningBox> {
|
||||
final _emailController = TextEditingController();
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_init();
|
||||
}
|
||||
|
||||
void _init() {
|
||||
var appStore = context.read<AppStore>();
|
||||
_emailController.text = appStore.userInfo?.email ?? "";
|
||||
}
|
||||
|
||||
///提交
|
||||
void _handSubmit() async {
|
||||
if (_emailController.text.isEmpty) {
|
||||
|
||||
@@ -90,7 +90,7 @@ class _ItemWidgetState extends State<ItemWidget> {
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
"health",
|
||||
"healthy",
|
||||
style: TextStyle(fontSize: 14, fontWeight: FontWeight.w500, color: color),
|
||||
),
|
||||
Container(
|
||||
|
||||
@@ -9,7 +9,9 @@ import 'package:go_router/go_router.dart';
|
||||
import 'package:google_sign_in/google_sign_in.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:remixicon/remixicon.dart';
|
||||
import 'package:sign_in_with_apple/sign_in_with_apple.dart';
|
||||
import '../../../providers/app_store.dart';
|
||||
import '../../../utils/common.dart';
|
||||
import '../../../widgets/common/app_backend.dart';
|
||||
import '../../../widgets/ui_kit/button/custom_button.dart';
|
||||
import 'widget/agreement_box.dart';
|
||||
@@ -24,6 +26,7 @@ class LoginPage extends StatefulWidget {
|
||||
|
||||
class _LoginPageState extends State<LoginPage> {
|
||||
var _subLoading = false;
|
||||
|
||||
///协议
|
||||
bool _agree = false;
|
||||
|
||||
@@ -31,8 +34,8 @@ class _LoginPageState extends State<LoginPage> {
|
||||
final GoogleSignIn _googleSignIn = GoogleSignIn.instance;
|
||||
|
||||
///邮箱输入框
|
||||
final TextEditingController _emailController = TextEditingController(text: "18207394@qq.com");
|
||||
final TextEditingController _passwordController = TextEditingController(text: "111");
|
||||
final TextEditingController _emailController = TextEditingController(text: "");
|
||||
final TextEditingController _passwordController = TextEditingController(text: "");
|
||||
|
||||
//显示密码
|
||||
var _hidePassword = true;
|
||||
@@ -40,14 +43,40 @@ class _LoginPageState extends State<LoginPage> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_ensureNetworkPermission();
|
||||
_initGoogleSign();
|
||||
}
|
||||
|
||||
/// 预触发 iOS 网络权限弹窗
|
||||
Future<bool> _ensureNetworkPermission() async {
|
||||
try {
|
||||
await Dio().get(
|
||||
'https://captive.apple.com/hotspot-detect.html',
|
||||
options: Options(
|
||||
sendTimeout: const Duration(seconds: 3),
|
||||
receiveTimeout: const Duration(seconds: 3),
|
||||
headers: {'Cache-Control': 'no-cache'},
|
||||
),
|
||||
);
|
||||
return true;
|
||||
} catch (_) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void _initGoogleSign() {
|
||||
_googleSignIn.initialize(
|
||||
clientId: null,
|
||||
serverClientId: "497244455669-sl271gkb1polqd8kqtnb6co82n95aerq.apps.googleusercontent.com",
|
||||
);
|
||||
if (isAndroid()) {
|
||||
_googleSignIn.initialize(
|
||||
clientId: null,
|
||||
serverClientId: "497244455669-sl271gkb1polqd8kqtnb6co82n95aerq.apps.googleusercontent.com",
|
||||
);
|
||||
} else {
|
||||
_googleSignIn.initialize(
|
||||
clientId: "497244455669-4c8jmohrsj81e7rpjfamv3kvr07haa6r.apps.googleusercontent.com",
|
||||
serverClientId: "497244455669-sl271gkb1polqd8kqtnb6co82n95aerq.apps.googleusercontent.com",
|
||||
);
|
||||
}
|
||||
|
||||
_googleSignIn.authenticationEvents
|
||||
.listen((_) {
|
||||
print("登陆成功");
|
||||
@@ -57,7 +86,8 @@ class _LoginPageState extends State<LoginPage> {
|
||||
});
|
||||
}
|
||||
|
||||
void _handleSignIn() async {
|
||||
///谷歌登录
|
||||
void _handleGoogleSignIn() async {
|
||||
if (!_agree) {
|
||||
EasyLoading.showToast('Please read and agree to the terms first.');
|
||||
return;
|
||||
@@ -69,7 +99,7 @@ class _LoginPageState extends State<LoginPage> {
|
||||
// 使用 authenticate() 进行认证
|
||||
GoogleSignInAccount? user = await _googleSignIn.authenticate();
|
||||
var auth = user.authentication;
|
||||
|
||||
|
||||
// var res = await Dio().get("https://oauth2.googleapis.com/tokeninfo?id_token=${auth.idToken}");
|
||||
//登陆
|
||||
EasyLoading.show(status: "Logging in...");
|
||||
@@ -77,25 +107,50 @@ class _LoginPageState extends State<LoginPage> {
|
||||
EasyLoading.dismiss();
|
||||
_onLogin(res);
|
||||
}
|
||||
// } catch (e) {
|
||||
// if (e is GoogleSignInException) {
|
||||
// if (e.code == GoogleSignInExceptionCode.canceled) {
|
||||
// // 用户取消登录
|
||||
// print("User canceled login.");
|
||||
// } else {
|
||||
// // 其他错误
|
||||
// print("Google Sign-In error: $e");
|
||||
// }
|
||||
// } else {
|
||||
// print("Unknown error: $e");
|
||||
// }
|
||||
// }
|
||||
// } catch (e) {
|
||||
// if (e is GoogleSignInException) {
|
||||
// if (e.code == GoogleSignInExceptionCode.canceled) {
|
||||
// // 用户取消登录
|
||||
// print("User canceled login.");
|
||||
// } else {
|
||||
// // 其他错误
|
||||
// print("Google Sign-In error: $e");
|
||||
// }
|
||||
// } else {
|
||||
// print("Unknown error: $e");
|
||||
// }
|
||||
// }
|
||||
} catch (e) {
|
||||
EasyLoading.showError("Login failed");
|
||||
print("登录错误: $e");
|
||||
}
|
||||
}
|
||||
|
||||
///apple登录
|
||||
void _handAppleSignIn() async {
|
||||
if (!_agree) {
|
||||
EasyLoading.showToast('Please read and agree to the terms first.');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
final credential = await SignInWithApple.getAppleIDCredential(
|
||||
scopes: [
|
||||
AppleIDAuthorizationScopes.email,
|
||||
AppleIDAuthorizationScopes.fullName,
|
||||
],
|
||||
);
|
||||
EasyLoading.show(status: "Logging in...");
|
||||
var res = await thirdLoginApi(credential.identityToken!, OtherLoginType.apple);
|
||||
EasyLoading.dismiss();
|
||||
_onLogin(res);
|
||||
print('Apple Credential: ${credential.identityToken}');
|
||||
print('Apple Email: ${credential.email}');
|
||||
} catch (e) {
|
||||
print('Error during Apple sign-in: $e');
|
||||
}
|
||||
}
|
||||
|
||||
void _handSubmit() async {
|
||||
if (!_agree) {
|
||||
EasyLoading.showToast('Please read and agree to the terms first.');
|
||||
@@ -158,7 +213,7 @@ class _LoginPageState extends State<LoginPage> {
|
||||
Container(
|
||||
width: double.infinity,
|
||||
padding: EdgeInsets.only(
|
||||
top: 0.1.sh,
|
||||
top: 0.07.sh,
|
||||
left: 20,
|
||||
right: 20,
|
||||
),
|
||||
@@ -203,15 +258,17 @@ class _LoginPageState extends State<LoginPage> {
|
||||
title: "Continue with Google",
|
||||
icon: "assets/image/google.png",
|
||||
onTap: () {
|
||||
_handleSignIn();
|
||||
_handleGoogleSignIn();
|
||||
},
|
||||
),
|
||||
SizedBox(height: 15),
|
||||
// OtherButton(
|
||||
// title: "Continue with Apple",
|
||||
// icon: "assets/image/apple.png",
|
||||
// onTap: () {},
|
||||
// ),
|
||||
OtherButton(
|
||||
title: "Continue with Apple",
|
||||
icon: "assets/image/apple.png",
|
||||
onTap: () {
|
||||
_handAppleSignIn();
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
@@ -36,37 +36,26 @@ class AgreementBox extends StatelessWidget {
|
||||
style: Theme.of(context).textTheme.labelSmall,
|
||||
children: [
|
||||
TextSpan(
|
||||
text: "我已阅读并同意",
|
||||
recognizer: TapGestureRecognizer()
|
||||
..onTap = () {
|
||||
onChanged(!checked);
|
||||
},
|
||||
text: "I agree to the ",
|
||||
),
|
||||
TextSpan(
|
||||
text: "《用户协议》",
|
||||
style: TextStyle(
|
||||
color: Theme.of(context).primaryColor,
|
||||
),
|
||||
text: "Terms",
|
||||
style: TextStyle(color: Theme.of(context).primaryColor),
|
||||
recognizer: TapGestureRecognizer()
|
||||
..onTap = () {
|
||||
context.push(
|
||||
RoutePaths.agreement,
|
||||
extra: {"title": "用户协议", "url": "https://keyang2.tuzuu.com/ak-health/agreement/user_agreement.html"},
|
||||
);
|
||||
},
|
||||
..onTap = () => context.push(
|
||||
RoutePaths.agreement,
|
||||
extra: {"title": "Terms of Service", "url": "https://support.curain.ai/privacy/derma/terms_service.html"},
|
||||
),
|
||||
),
|
||||
TextSpan(text: " & "),
|
||||
TextSpan(
|
||||
text: "《隐私协议》",
|
||||
style: TextStyle(
|
||||
color: Theme.of(context).primaryColor,
|
||||
),
|
||||
text: "Privacy Policy",
|
||||
style: TextStyle(color: Theme.of(context).primaryColor),
|
||||
recognizer: TapGestureRecognizer()
|
||||
..onTap = () {
|
||||
context.push(
|
||||
RoutePaths.agreement,
|
||||
extra: {"title": "隐私政策", "url": "https://keyang2.tuzuu.com/ak-health/agreement/privacy_policy.html"},
|
||||
);
|
||||
},
|
||||
..onTap = () => context.push(
|
||||
RoutePaths.agreement,
|
||||
extra: {"title": "Privacy", "url": "https://support.curain.ai/privacy/derma/privacy_policy.html"},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
@@ -7,7 +7,7 @@ class LogoBox extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
margin: EdgeInsets.only(bottom: 60),
|
||||
margin: EdgeInsets.only(bottom: 40),
|
||||
child: Column(
|
||||
children: [
|
||||
Image.asset(
|
||||
|
||||
6
lib/utils/common.dart
Normal file
6
lib/utils/common.dart
Normal file
@@ -0,0 +1,6 @@
|
||||
import 'dart:io';
|
||||
|
||||
///判断是否是安卓
|
||||
bool isAndroid(){
|
||||
return Platform.isAndroid;
|
||||
}
|
||||
Reference in New Issue
Block a user