refactor(settings): 重构设置页面,支持语言和地区设置

This commit is contained in:
qzl
2026-04-07 18:44:14 +08:00
parent 6e82053ea7
commit 6217844865
4 changed files with 101 additions and 52 deletions
@@ -14,11 +14,13 @@ class ProfileEditScreen extends StatefulWidget {
required this.account,
required this.settings,
required this.onUploadAvatar,
required this.onSave,
});
final String account;
final ProfileSettingsV1 settings;
final Future<ProfileSettingsV1> Function(String filePath) onUploadAvatar;
final Future<ProfileSettingsV1> Function(ProfileSettingsV1 updated) onSave;
@override
State<ProfileEditScreen> createState() => _ProfileEditScreenState();
@@ -191,7 +193,7 @@ class _ProfileEditScreenState extends State<ProfileEditScreen> {
);
}
void _save() {
Future<void> _save() async {
final l10n = AppLocalizations.of(context)!;
final name = _nameController.text.trim();
if (name.isEmpty) {
@@ -202,14 +204,33 @@ class _ProfileEditScreenState extends State<ProfileEditScreen> {
);
return;
}
Navigator.of(context).pop(
widget.settings.copyWith(
displayName: name,
bio: _bioController.text.trim(),
avatarPath: _avatarPath,
avatarUrl: _avatarPreviewUrl,
),
final updated = widget.settings.copyWith(
displayName: name,
bio: _bioController.text.trim(),
avatarPath: _avatarPath,
avatarUrl: _avatarPreviewUrl,
);
try {
final saved = await widget.onSave(updated);
if (!mounted) {
return;
}
Navigator.of(context).pop(saved);
} catch (error, stackTrace) {
_logger.error(
message: 'Failed to save profile',
error: error,
stackTrace: stackTrace,
);
if (!mounted) {
return;
}
Toast.show(
context,
AppLocalizations.of(context)!.errorRequestGeneric,
type: ToastType.error,
);
}
}
Future<void> _pickAndUploadAvatar() async {