fix:苹果一键登录页面,深浅色

This commit is contained in:
jingyun committed 2026-09-04 11:41:22 +08:00
1 parent afee4b5aec
commit b503cb7e6e
35 files changed
+687 -228

No files matched your search

@@ -8,10 +8,8 @@ import '../../../common/router/app_router.dart';
import 'auth_controller.dart';
import 'one_key_login_service.dart';
/// Shared login entry: launch the carrier-owned authorization page first and
/// use the Flutter SMS page only as a deliberate fallback.
abstract final class LoginLauncher {
static final _service = OneKeyLoginService();
static final OneKeyLoginService _service = OneKeyLoginService();
static bool _starting = false;
static Future<void> start(
@@ -21,71 +19,95 @@ abstract final class LoginLauncher {
}) async {
if (_starting) return;
_starting = true;
final dismissLoading = _showLoading(context);
var loadingVisible = false;
void showLoading() {
if (loadingVisible || !context.mounted) return;
loadingVisible = true;
unawaited(
showDialog<void>(
context: context,
useRootNavigator: true,
barrierDismissible: false,
builder: (_) => const PopScope(
canPop: false,
child: Center(child: CircularProgressIndicator()),
),
),
);
}
void dismissLoading() {
if (!loadingVisible || !context.mounted) return;
loadingVisible = false;
Navigator.of(context, rootNavigator: true).pop();
}
try {
final observer = _OneKeyLoginLifecycleObserver(_service);
WidgetsBinding.instance.addObserver(observer);
var observerAdded = false;
late final OneKeyLoginOutcome outcome;
try {
WidgetsBinding.instance.addObserver(observer);
observerAdded = true;
// Carrier-auth initialization only begins after this explicit login
// action. Keep the loading indicator visible while the native SDK
// determines whether one-key login can be launched.
showLoading();
outcome = await _service.start(
context: context,
verifyToken: ref.read(authProvider.notifier).verifyOneKeyLogin,
// The native carrier page follows the device, while linked H5 pages
// retain the appearance selected inside the app.
appIsDark: Theme.of(context).brightness == Brightness.dark,
nativeIsDark:
MediaQuery.platformBrightnessOf(context) == Brightness.dark,
onNativeRequestDispatched: dismissLoading,
onAuthPageOpened: dismissLoading,
);
} catch (_) {
outcome = OneKeyLoginOutcome.fallback;
} finally {
WidgetsBinding.instance.removeObserver(observer);
dismissLoading();
if (observerAdded) WidgetsBinding.instance.removeObserver(observer);
}
if (!context.mounted) return;
if (outcome == OneKeyLoginOutcome.success) {
context.go(next?.isNotEmpty == true ? next! : AppRoutes.profile);
return;
}
if (outcome == OneKeyLoginOutcome.fallback ||
outcome == OneKeyLoginOutcome.unsupported) {
final target = next == null || next.isEmpty
? AppRoutes.login
: '${AppRoutes.login}?next=${Uri.encodeComponent(next)}';
if (GoRouterState.of(context).matchedLocation != AppRoutes.login) {
await context.push(target);
}
switch (outcome) {
case OneKeyLoginOutcome.success:
if (next != null && next.isNotEmpty) GoRouter.of(context).go(next);
return;
case OneKeyLoginOutcome.cancelled:
case OneKeyLoginOutcome.busy:
return;
case OneKeyLoginOutcome.fallback:
case OneKeyLoginOutcome.unsupported:
await openSmsLogin(context, next: next);
}
} finally {
dismissLoading();
_starting = false;
}
}
}
static VoidCallback _showLoading(BuildContext context) {
var visible = true;
unawaited(
showDialog<void>(
context: context,
useRootNavigator: true,
barrierDismissible: false,
builder: (_) => const PopScope(
canPop: false,
child: Center(child: CircularProgressIndicator()),
),
),
);
return () {
if (visible && context.mounted) {
Navigator.of(context, rootNavigator: true).pop();
}
visible = false;
};
}
Future<void> openSmsLogin(
BuildContext context, {
String? next,
Future<void> Function()? onReturn,
}) async {
if (!context.mounted) return;
if (GoRouterState.of(context).matchedLocation == AppRoutes.login) return;
final location = next == null || next.isEmpty
? AppRoutes.login
: '${AppRoutes.login}?next=${Uri.encodeComponent(next)}';
await GoRouter.of(context).push(location);
if (context.mounted) await onReturn?.call();
}
class _OneKeyLoginLifecycleObserver with WidgetsBindingObserver {
_OneKeyLoginLifecycleObserver(this._service);
final OneKeyLoginService _service;
_OneKeyLoginLifecycleObserver(this.service);
final OneKeyLoginService service;
@override
void didChangeAppLifecycleState(AppLifecycleState state) {
if (state == AppLifecycleState.resumed) _service.onAppResumed();
if (state == AppLifecycleState.resumed) service.onAppResumed();
}
}