- 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>
60 lines
1.5 KiB
Dart
60 lines
1.5 KiB
Dart
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
|
|
import '../../core/api/api_client.dart';
|
|
import '../../core/auth/auth_provider.dart';
|
|
import '../../shared/models/user.dart';
|
|
|
|
final profileServiceProvider = Provider<ProfileService>((ref) {
|
|
return ProfileService(ref.read(apiClientProvider));
|
|
});
|
|
|
|
class UpdateProfileRequest {
|
|
final String? name;
|
|
final int? heightCm;
|
|
final double? weightKg;
|
|
final int? age;
|
|
final String? gender;
|
|
final String? activity;
|
|
final String? goal;
|
|
final String? language;
|
|
|
|
const UpdateProfileRequest({
|
|
this.name,
|
|
this.heightCm,
|
|
this.weightKg,
|
|
this.age,
|
|
this.gender,
|
|
this.activity,
|
|
this.goal,
|
|
this.language,
|
|
});
|
|
|
|
Map<String, dynamic> toJson() {
|
|
final map = <String, dynamic>{};
|
|
if (name != null) map['name'] = name;
|
|
if (heightCm != null) map['height_cm'] = heightCm;
|
|
if (weightKg != null) map['weight_kg'] = weightKg;
|
|
if (age != null) map['age'] = age;
|
|
if (gender != null) map['gender'] = gender;
|
|
if (activity != null) map['activity'] = activity;
|
|
if (goal != null) map['goal'] = goal;
|
|
if (language != null) map['preferences'] = {'language': language};
|
|
return map;
|
|
}
|
|
}
|
|
|
|
class ProfileService {
|
|
final ApiClient _client;
|
|
ProfileService(this._client);
|
|
|
|
Future<User> getProfile() async {
|
|
final json = await _client.get('/profile');
|
|
return User.fromJson(json);
|
|
}
|
|
|
|
Future<User> updateProfile(UpdateProfileRequest req) async {
|
|
final json = await _client.put('/profile', data: req.toJson());
|
|
return User.fromJson(json);
|
|
}
|
|
}
|