feat: add onboarding flow with visual redesign

Introduce 6-step onboarding screen (Goal → Gender → DOB → Height+Weight
→ Activity → Calories) with per-step accent colors, hero illustration
area (concentric circles + icon), and white card content panel.

Backend user entity and service updated to support onboarding fields
(goal, activity, height, weight, DOB, dailyCalories). Router guards
unauthenticated and onboarding-incomplete users. Profile service and
screen updated to expose language and onboarding preferences.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
dbastrikin
2026-03-16 23:13:00 +02:00
parent 67d8897c95
commit ddbc8e2bc0
8 changed files with 1278 additions and 18 deletions

View File

@@ -6,6 +6,9 @@ import '../auth/auth_provider.dart';
import '../../features/auth/login_screen.dart';
import '../../features/auth/register_screen.dart';
import '../../features/home/home_screen.dart';
import '../../features/onboarding/onboarding_screen.dart';
import '../../features/profile/profile_provider.dart';
import '../../shared/models/user.dart';
import '../../features/products/products_screen.dart';
import '../../features/products/add_product_screen.dart';
import '../../features/scan/scan_screen.dart';
@@ -22,10 +25,20 @@ import '../../features/products/product_provider.dart';
import '../../shared/models/recipe.dart';
import '../../shared/models/saved_recipe.dart';
// Notifies GoRouter when auth state changes without recreating the router.
// Notifies GoRouter when auth state or profile state changes.
class _RouterNotifier extends ChangeNotifier {
_RouterNotifier(Ref ref) {
ref.listen<AuthState>(authProvider, (_, __) => notifyListeners());
ref.listen<AuthState>(authProvider, (previous, next) {
// Reload profile whenever auth transitions to authenticated.
// This handles the case where profileProvider did an initial load before
// tokens were available (401 → AsyncError) and needs a fresh load after login.
if (next.status == AuthStatus.authenticated &&
previous?.status != AuthStatus.authenticated) {
ref.read(profileProvider.notifier).load();
}
notifyListeners();
});
ref.listen<AsyncValue<User>>(profileProvider, (_, __) => notifyListeners());
}
}
@@ -41,11 +54,29 @@ final routerProvider = Provider<GoRouter>((ref) {
final authState = ref.read(authProvider);
final isLoggedIn = authState.status == AuthStatus.authenticated;
final isAuthRoute = state.matchedLocation.startsWith('/auth');
final isOnboarding = state.matchedLocation.startsWith('/onboarding');
// Show splash until the stored-token check completes.
if (authState.status == AuthStatus.unknown) return '/loading';
if (!isLoggedIn && !isAuthRoute) return '/auth/login';
if (isLoggedIn && isAuthRoute) return '/home';
if (isLoggedIn) {
// Reading profileProvider triggers its lazy initialization (load() in constructor).
final profileState = ref.read(profileProvider);
// Keep showing splash while profile loads.
if (profileState.isLoading) {
return state.matchedLocation == '/loading' ? null : '/loading';
}
final profileUser = profileState.valueOrNull;
// If profile failed to load, don't block navigation.
if (profileUser == null) return isAuthRoute ? '/home' : null;
final needsOnboarding = !profileUser.hasCompletedOnboarding;
if (isAuthRoute) return needsOnboarding ? '/onboarding' : '/home';
if (needsOnboarding && !isOnboarding) return '/onboarding';
if (!needsOnboarding && isOnboarding) return '/home';
}
return null;
},
routes: [
@@ -62,6 +93,11 @@ final routerProvider = Provider<GoRouter>((ref) {
path: '/auth/register',
builder: (_, __) => const RegisterScreen(),
),
// Onboarding — full-screen, no bottom nav, shown to new users.
GoRoute(
path: '/onboarding',
builder: (_, __) => const OnboardingScreen(),
),
// Full-screen recipe detail — shown without the bottom navigation bar.
GoRoute(
path: '/recipe-detail',