refactor(settings): 重构设置页面,支持语言和地区设置
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user