fix:登录退出页

This commit is contained in:
jingyun
2026-06-07 11:38:08 +08:00
parent 6a7fa5a067
commit 6c943f8394
8 changed files with 356 additions and 38 deletions
+101
View File
@@ -13,6 +13,7 @@ import '../../theme/yanting_tokens.dart';
import '../../widgets/app_card.dart';
import '../../widgets/page_header.dart';
import '../../widgets/sheets.dart';
import '../../widgets/states.dart';
class SettingsPage extends ConsumerWidget {
const SettingsPage({super.key});
@@ -21,6 +22,7 @@ class SettingsPage extends ConsumerWidget {
Widget build(BuildContext context, WidgetRef ref) {
final themeMode = ref.watch(themeModeProvider);
final scheme = ShadTheme.of(context).colorScheme;
final auth = ref.watch(authControllerProvider);
return Scaffold(
appBar: AppBar(
@@ -138,6 +140,21 @@ class SettingsPage extends ConsumerWidget {
],
),
),
if (auth.loggedIn) ...[
const SizedBox(height: YantingSpacing.x3),
Text('账户', style: YantingText.sectionTitle),
const SizedBox(height: 12),
AppCard(
padding: EdgeInsets.zero,
child: _ActionTile(
icon: Icons.logout,
title: '退出登录',
subtitle: '退出后本地登录态会清空',
destructive: true,
onTap: () => _confirmLogout(context, ref),
),
),
],
],
),
);
@@ -157,6 +174,33 @@ class SettingsPage extends ConsumerWidget {
.recordOutbound(OutboundEvent(scene: scene)),
);
}
Future<void> _confirmLogout(BuildContext context, WidgetRef ref) async {
final ok = await showShadDialog<bool>(
context: context,
variant: ShadDialogVariant.alert,
builder: (dialogContext) => ShadDialog.alert(
title: const Text('退出登录'),
description: const Text('退出后,本设备的登录态会清空,再次登录可继续使用。'),
actions: [
ShadButton.outline(
child: const Text('取消'),
onPressed: () => Navigator.of(dialogContext).pop(false),
),
ShadButton(
child: const Text('确定退出'),
onPressed: () => Navigator.of(dialogContext).pop(true),
),
],
),
);
if (ok != true) return;
await ref.read(authControllerProvider.notifier).logout();
await ref.read(profileControllerProvider.notifier).refresh();
if (!context.mounted) return;
showAppToast(context, '已退出登录');
context.go(AppRoutes.profile);
}
}
class _ThemeModeTile extends StatelessWidget {
@@ -267,3 +311,60 @@ class _LinkTile extends StatelessWidget {
);
}
}
class _ActionTile extends StatelessWidget {
const _ActionTile({
required this.icon,
required this.title,
required this.subtitle,
required this.onTap,
this.destructive = false,
});
final IconData icon;
final String title;
final String subtitle;
final VoidCallback onTap;
final bool destructive;
@override
Widget build(BuildContext context) {
final colors = ShadTheme.of(context).colorScheme;
final titleColor = destructive ? colors.destructive : colors.foreground;
return InkWell(
onTap: onTap,
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 15),
child: Row(
children: [
Icon(icon, size: 20, color: titleColor),
const SizedBox(width: 13),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
title,
style: YantingText.body.copyWith(
color: titleColor,
fontWeight: FontWeight.w600,
),
),
const SizedBox(height: 4),
Text(
subtitle,
style: YantingText.meta.copyWith(
color: colors.mutedForeground,
fontSize: 12.5,
),
),
],
),
),
const Icon(AppIcons.arrowRight, size: 18),
],
),
),
);
}
}