feat: 实现用户画像、占卜历史与后端用户管理模块

This commit is contained in:
ZL-Q
2026-04-06 01:28:10 +08:00
parent d87b2e1e3a
commit 8a18b3528b
77 changed files with 5850 additions and 2604 deletions
@@ -1,12 +1,17 @@
import 'package:flutter/material.dart';
import '../../../../l10n/app_localizations.dart';
import '../../../../core/logging/logger.dart';
import '../../../../shared/theme/design_tokens.dart';
import '../../../../shared/widgets/app_modal_dialog.dart';
import '../../../../shared/widgets/toast/toast.dart';
import '../../../../shared/widgets/toast/toast_type.dart';
import '../../data/models/profile_settings.dart';
import '../widgets/settings_section_widgets.dart';
import 'coin_center_screen.dart';
import 'general_settings_screen.dart';
import 'legal_center_screen.dart';
import 'profile_edit_screen.dart';
class SettingsScreen extends StatefulWidget {
const SettingsScreen({
@@ -15,6 +20,8 @@ class SettingsScreen extends StatefulWidget {
required this.settings,
required this.coinBalance,
required this.onInterfaceLanguageChanged,
required this.onSettingsChanged,
required this.onUploadAvatar,
required this.onLogout,
});
@@ -22,6 +29,8 @@ class SettingsScreen extends StatefulWidget {
final ProfileSettingsV1 settings;
final int coinBalance;
final Future<void> Function(String languageTag) onInterfaceLanguageChanged;
final Future<void> Function(ProfileSettingsV1 settings) onSettingsChanged;
final Future<ProfileSettingsV1> Function(String filePath) onUploadAvatar;
final Future<void> Function() onLogout;
@override
@@ -29,6 +38,7 @@ class SettingsScreen extends StatefulWidget {
}
class _SettingsScreenState extends State<SettingsScreen> {
final Logger _logger = getLogger('features.settings.settings_screen');
late ProfileSettingsV1 _settings;
bool _isLoggingOut = false;
@@ -38,6 +48,14 @@ class _SettingsScreenState extends State<SettingsScreen> {
_settings = widget.settings;
}
@override
void didUpdateWidget(covariant SettingsScreen oldWidget) {
super.didUpdateWidget(oldWidget);
if (oldWidget.settings != widget.settings) {
_settings = widget.settings;
}
}
@override
Widget build(BuildContext context) {
final l10n = AppLocalizations.of(context)!;
@@ -59,7 +77,15 @@ class _SettingsScreenState extends State<SettingsScreen> {
AppSpacing.xl,
),
children: [
ProfileHeaderCard(account: widget.account),
ProfileHeaderCard(
account: widget.account,
displayName: _settings.displayName.isEmpty
? widget.account
: _settings.displayName,
bio: _settings.bio,
avatarUrl: _settings.avatarUrl,
onEditTap: _openProfileEdit,
),
const SizedBox(height: AppSpacing.lg),
WalletHeroCard(
balance: widget.coinBalance,
@@ -67,7 +93,6 @@ class _SettingsScreenState extends State<SettingsScreen> {
onTap: _openCoinCenter,
),
const SizedBox(height: AppSpacing.xl),
SectionLabel(text: l10n.settingsSectionQuickAccess),
SettingsGroupCard(
children: [
SettingsMenuTile(
@@ -131,6 +156,44 @@ class _SettingsScreenState extends State<SettingsScreen> {
});
}
Future<void> _openProfileEdit() async {
final result = await Navigator.of(context).push<ProfileSettingsV1>(
MaterialPageRoute<ProfileSettingsV1>(
builder: (_) => ProfileEditScreen(
account: widget.account,
settings: _settings,
onUploadAvatar: widget.onUploadAvatar,
),
),
);
if (result == null || !mounted) {
return;
}
try {
await widget.onSettingsChanged(result);
if (!mounted) {
return;
}
setState(() {
_settings = result;
});
} catch (error, stackTrace) {
_logger.error(
message: 'Failed to save profile settings',
error: error,
stackTrace: stackTrace,
);
if (!mounted) {
return;
}
Toast.show(
context,
AppLocalizations.of(context)!.errorRequestGeneric,
type: ToastType.error,
);
}
}
Future<void> _openLegalCenter() async {
await Navigator.of(context).push<void>(
MaterialPageRoute<void>(builder: (_) => const LegalCenterScreen()),
@@ -142,21 +205,20 @@ class _SettingsScreenState extends State<SettingsScreen> {
final confirmed = await showDialog<bool>(
context: context,
builder: (dialogContext) {
return AlertDialog(
title: Text(l10n.settingsLogoutDialogTitle),
content: Text(l10n.settingsLogoutDialogBody),
return AppModalDialog(
title: l10n.settingsLogoutDialogTitle,
message: l10n.settingsLogoutDialogBody,
icon: Icons.logout_rounded,
actions: [
TextButton(
AppModalDialogAction(
label: l10n.settingsCancel,
onPressed: () => Navigator.of(dialogContext).pop(false),
child: Text(l10n.settingsCancel),
),
FilledButton(
AppModalDialogAction(
label: l10n.logout,
primary: true,
destructive: true,
onPressed: () => Navigator.of(dialogContext).pop(true),
style: FilledButton.styleFrom(
backgroundColor: Theme.of(dialogContext).colorScheme.error,
foregroundColor: Theme.of(dialogContext).colorScheme.onError,
),
child: Text(l10n.logout),
),
],
);
@@ -171,6 +233,10 @@ class _SettingsScreenState extends State<SettingsScreen> {
});
try {
await widget.onLogout();
if (!mounted) {
return;
}
Navigator.of(context).popUntil((route) => route.isFirst);
} finally {
if (mounted) {
setState(() {