feat: implement client-side localization infrastructure

- Add languageProvider (StateProvider<String>, default 'ru') with
  supportedLanguages map matching backend locale.Supported
- Wire Accept-Language header into AuthInterceptor via languageGetter
  callback; all API requests now carry the current language
- Sync language from user profile preferences into languageProvider
  on every ProfileNotifier load/update
- Add language field to UpdateProfileRequest, serialized as
  preferences.language in PUT /profile
- Profile screen: НАСТРОЙКИ section displays current language;
  edit sheet adds DropdownButtonFormField for language selection

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
dbastrikin
2026-02-27 23:34:51 +02:00
parent c0cf1b38ea
commit 0567d90784
7 changed files with 94 additions and 8 deletions

View File

@@ -1,32 +1,48 @@
import 'package:flutter_riverpod/flutter_riverpod.dart';
import '../../core/locale/language_provider.dart';
import '../../shared/models/user.dart';
import 'profile_service.dart';
class ProfileNotifier extends StateNotifier<AsyncValue<User>> {
final ProfileService _service;
final void Function(String) _setLanguage;
ProfileNotifier(this._service) : super(const AsyncValue.loading()) {
ProfileNotifier(this._service, this._setLanguage)
: super(const AsyncValue.loading()) {
load();
}
Future<void> load() async {
state = const AsyncValue.loading();
state = await AsyncValue.guard(() => _service.getProfile());
_syncLanguage();
}
Future<bool> update(UpdateProfileRequest req) async {
try {
final updated = await _service.updateProfile(req);
state = AsyncValue.data(updated);
_syncLanguage();
return true;
} catch (_) {
return false;
}
}
// Propagates the user's preferred language to the global languageProvider.
void _syncLanguage() {
final lang = state.valueOrNull?.preferences['language'] as String?;
if (lang != null && supportedLanguages.containsKey(lang)) {
_setLanguage(lang);
}
}
}
final profileProvider =
StateNotifierProvider<ProfileNotifier, AsyncValue<User>>(
(ref) => ProfileNotifier(ref.read(profileServiceProvider)),
(ref) => ProfileNotifier(
ref.read(profileServiceProvider),
(lang) => ref.read(languageProvider.notifier).state = lang,
),
);