Fix app routing to show WelcomeScreen for returning users

Previously the app jumped directly to ResultsScreen when user had
existing data, bypassing the WelcomeScreen entirely. Now returning
users see WelcomeScreen where they can Start and choose to continue
from their last saved run or start fresh.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
John Mizerek 2026-02-21 21:52:23 -08:00
parent 498a1534ed
commit e4b8c9eb8e

View file

@ -42,18 +42,19 @@ class AppRouter extends StatefulWidget {
class _AppRouterState extends State<AppRouter> { class _AppRouterState extends State<AppRouter> {
bool _loading = true; bool _loading = true;
bool _hasData = false; bool _hasCompletedOnboarding = false;
@override @override
void initState() { void initState() {
super.initState(); super.initState();
_checkExistingData(); _checkState();
} }
Future<void> _checkExistingData() async { Future<void> _checkState() async {
// Check if user has ever completed a run (has saved data)
final hasData = await LocalStorage.hasCompletedSetup(); final hasData = await LocalStorage.hasCompletedSetup();
setState(() { setState(() {
_hasData = hasData; _hasCompletedOnboarding = hasData;
_loading = false; _loading = false;
}); });
} }
@ -68,40 +69,12 @@ class _AppRouterState extends State<AppRouter> {
); );
} }
// If user has existing data, go straight to results // First launch: show onboarding
if (_hasData) { // Returning users: show welcome screen (where they can start fresh or continue)
return FutureBuilder( if (_hasCompletedOnboarding) {
future: _loadExistingData(), return const WelcomeScreen();
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) {
return const Scaffold(
body: Center(child: CircularProgressIndicator()),
);
}
if (snapshot.hasData) {
final data = snapshot.data!;
return ResultsScreen(
profile: data.$1,
behaviors: data.$2,
);
}
return const OnboardingScreen();
},
);
} }
return const OnboardingScreen(); return const OnboardingScreen();
} }
Future<(dynamic, dynamic)?> _loadExistingData() async {
final profile = await LocalStorage.getProfile();
final behaviors = await LocalStorage.getBehaviors();
if (profile != null && behaviors != null) {
return (profile, behaviors);
}
return null;
}
} }