From e4b8c9eb8e6e126fde61d9339fc9eedf9e6f9618 Mon Sep 17 00:00:00 2001 From: John Mizerek Date: Sat, 21 Feb 2026 21:52:23 -0800 Subject: [PATCH] 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 --- lib/main.dart | 45 +++++++++------------------------------------ 1 file changed, 9 insertions(+), 36 deletions(-) diff --git a/lib/main.dart b/lib/main.dart index a2ab4ec..4f800b2 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -42,18 +42,19 @@ class AppRouter extends StatefulWidget { class _AppRouterState extends State { bool _loading = true; - bool _hasData = false; + bool _hasCompletedOnboarding = false; @override void initState() { super.initState(); - _checkExistingData(); + _checkState(); } - Future _checkExistingData() async { + Future _checkState() async { + // Check if user has ever completed a run (has saved data) final hasData = await LocalStorage.hasCompletedSetup(); setState(() { - _hasData = hasData; + _hasCompletedOnboarding = hasData; _loading = false; }); } @@ -68,40 +69,12 @@ class _AppRouterState extends State { ); } - // If user has existing data, go straight to results - if (_hasData) { - return FutureBuilder( - future: _loadExistingData(), - 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(); - }, - ); + // First launch: show onboarding + // Returning users: show welcome screen (where they can start fresh or continue) + if (_hasCompletedOnboarding) { + return const WelcomeScreen(); } 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; - } }