Add ProfileService (GET/PUT /profile), ProfileNotifier provider, and full ProfileScreen with body-params, goal/activity, daily-calories sections and logout confirmation. EditProfileSheet lets user update name, height, weight, age, gender, goal and activity; backend auto-recalculates daily_calories via Mifflin-St Jeor. HomeScreen greeting now shows the user's real name from profileProvider. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
57 lines
1.4 KiB
Dart
57 lines
1.4 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;
|
|
|
|
const UpdateProfileRequest({
|
|
this.name,
|
|
this.heightCm,
|
|
this.weightKg,
|
|
this.age,
|
|
this.gender,
|
|
this.activity,
|
|
this.goal,
|
|
});
|
|
|
|
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;
|
|
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);
|
|
}
|
|
}
|