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>
33 lines
840 B
Dart
33 lines
840 B
Dart
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
|
|
import '../../shared/models/user.dart';
|
|
import 'profile_service.dart';
|
|
|
|
class ProfileNotifier extends StateNotifier<AsyncValue<User>> {
|
|
final ProfileService _service;
|
|
|
|
ProfileNotifier(this._service) : super(const AsyncValue.loading()) {
|
|
load();
|
|
}
|
|
|
|
Future<void> load() async {
|
|
state = const AsyncValue.loading();
|
|
state = await AsyncValue.guard(() => _service.getProfile());
|
|
}
|
|
|
|
Future<bool> update(UpdateProfileRequest req) async {
|
|
try {
|
|
final updated = await _service.updateProfile(req);
|
|
state = AsyncValue.data(updated);
|
|
return true;
|
|
} catch (_) {
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
|
|
final profileProvider =
|
|
StateNotifierProvider<ProfileNotifier, AsyncValue<User>>(
|
|
(ref) => ProfileNotifier(ref.read(profileServiceProvider)),
|
|
);
|