merge: integrate sccsbc release preparation safely

This commit is contained in:
MingNian
2026-07-16 00:41:52 +08:00
38 changed files with 2974 additions and 45 deletions

View File

@@ -1,7 +1,10 @@
import 'package:flutter/material.dart';
import 'dart:io' show Platform;
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:shadcn_ui/shadcn_ui.dart';
import 'package:sign_in_with_apple/sign_in_with_apple.dart';
import '../../core/app_colors.dart';
import '../../core/app_design_tokens.dart';
import '../../core/navigation_provider.dart';
@@ -73,6 +76,66 @@ class _LoginPageState extends ConsumerState<LoginPage> {
}
}
// Apple 登录
Future<void> _appleSignIn() async {
if (_loading) return;
if (!_agreed) {
final accepted = await _showAgreementDialog();
if (!mounted || accepted != true) return;
setState(() => _agreed = true);
}
setState(() {
_loading = true;
_error = null;
_successMsg = null;
});
try {
final credential = await SignInWithApple.getAppleIDCredential(
scopes: [AppleIDAuthorizationScopes.fullName],
);
final identityToken = credential.identityToken;
if (identityToken == null) {
if (mounted) {
setState(() {
_loading = false;
_error = 'Apple 登录未返回身份信息,请重试';
});
}
return;
}
final name = '${credential.familyName ?? ''}${credential.givenName ?? ''}'
.trim();
final err = await ref
.read(authProvider.notifier)
.appleLogin(
identityToken,
credential.authorizationCode,
name.isEmpty ? null : name,
);
if (mounted) {
setState(() => _loading = false);
if (err != null) {
setState(() => _error = err);
}
}
} catch (e) {
if (mounted) {
setState(() {
_loading = false;
if (e is SignInWithAppleAuthorizationException) {
_error = 'Apple 登录已取消';
} else {
_error = 'Apple 登录失败,请稍后重试';
}
});
}
}
}
Future<void> _submit() async {
if (_phoneCtrl.text.trim().isEmpty || _codeCtrl.text.trim().isEmpty) {
setState(() => _error = '请输入手机号和验证码');
@@ -500,6 +563,20 @@ class _LoginPageState extends ConsumerState<LoginPage> {
label: _isLogin ? '登录' : '注册',
onTap: _loading ? null : _submit,
),
if (_isLogin &&
(Platform.isIOS ||
Platform.isMacOS)) ...[
const SizedBox(height: 20),
SignInWithAppleButton(
onPressed: _loading
? () {}
: _appleSignIn,
style: SignInWithAppleButtonStyle
.whiteOutlined,
height: 48,
text: '通过 Apple 登录',
),
],
const SizedBox(height: 16),
GestureDetector(
onTap: () => setState(() {