feat: implement Iteration 6 — profile screen
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>
This commit is contained in:
32
client/lib/features/profile/profile_provider.dart
Normal file
32
client/lib/features/profile/profile_provider.dart
Normal file
@@ -0,0 +1,32 @@
|
||||
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)),
|
||||
);
|
||||
Reference in New Issue
Block a user