diff --git a/CODEMAP.md b/CODEMAP.md index 554c000..3e13c8c 100644 --- a/CODEMAP.md +++ b/CODEMAP.md @@ -99,7 +99,7 @@ There is **no `data/` layer yet**. Repository implementations live in `infrastru | `lib/app/page_transitions.dart` | 100 | `Route transition presets for [GoRouter] [pageBuilder] callbacks.` | | `lib/app/router.dart` | 245 | `_RouterRefreshNotifier` | | `lib/app/shell_navigation_scope.dart` | 33 | `ShellNavigationScope, CoachTab` | -| `lib/app/shell_page.dart` | 164 | `ShellPage, _AnimatedShellBody, _AnimatedShellBodyState, …` | +| `lib/app/shell_page.dart` | 170 | `ShellPage, _AnimatedShellBody, _AnimatedShellBodyState, …` | | `lib/core/constants/app_constants.dart` | 54 | `Compile-time constants for KYNOS.` | | `lib/core/constants/gamification_constants.dart` | 46 | `Gameplay tuning for Summit Camp.` | | `lib/core/constants/imported_workout_ids.dart` | 10 | `Prefix and helpers for locally imported workout identifiers.` | @@ -108,7 +108,7 @@ There is **no `data/` layer yet**. Repository implementations live in `infrastru | `lib/core/theme/colors.dart` | 82 | `KYNOS colour palette — iOS system colours, Apple Fitness aesthetic.` | | `lib/core/theme/elevation.dart` | 33 | `Shadow presets for the KYNOS design system.` | | `lib/core/theme/kynos_theme_extension.dart` | 229 | `KynosThemeExtension` | -| `lib/core/theme/layout.dart` | 64 | `Layout constants for consistent page structure.` | +| `lib/core/theme/layout.dart` | 74 | `Layout constants for consistent page structure.` | | `lib/core/theme/liquid_glass_tokens.dart` | 54 | `Design tokens for Apple Liquid Glass materials — blur, vibrancy, specular edges.` | | `lib/core/theme/motion.dart` | 17 | `Design token: motion durations and curves shared across the app.` | | `lib/core/theme/spacing.dart` | 20 | `Design token: spacing scale (4-point grid).` | @@ -230,7 +230,7 @@ There is **no `data/` layer yet**. Repository implementations live in `infrastru | `lib/domain/utils/running_distance.dart` | 12 | `Running-only distance in meters for a daily summary.` | | `lib/domain/utils/seeded_roll.dart` | 17 | `Deterministic 32-bit roll safe for VM and JavaScript (no >53-bit intermediates).` | | `lib/domain/utils/weekly_momentum.dart` | 87 | `WeeklyMomentum` | -| `lib/features/character/presentation/pages/character_page.dart` | 297 | `CharacterPage, EmptyCharacterState` | +| `lib/features/character/presentation/pages/character_page.dart` | 302 | `CharacterPage, EmptyCharacterState` | | `lib/features/character/presentation/widgets/camp_build_sheet.dart` | 133 | `CampBuildSheet` | | `lib/features/character/presentation/widgets/camp_game_panel.dart` | 145 | `CampGamePanel, _CampGamePanelState` | | `lib/features/character/presentation/widgets/camp_grid.dart` | 119 | `CampGrid, _CampTileCell` | @@ -266,7 +266,7 @@ There is **no `data/` layer yet**. Repository implementations live in `infrastru | `lib/features/coach_chat/presentation/widgets/health_visual_artifact_card.dart` | 404 | `HealthVisualArtifactCard, _HealthVisualArtifactCardState, _ValueRow` | | `lib/features/coach_chat/presentation/widgets/inference_mode_bar.dart` | 94 | `InferenceModeBar` | | `lib/features/coach_chat/presentation/widgets/inference_settings_sheet.dart` | 104 | `InferenceSettingsSheet` | -| `lib/features/coach_chat/presentation/widgets/message_list.dart` | 273 | `MessageList, _MessageListState, MessageBubble, …` | +| `lib/features/coach_chat/presentation/widgets/message_list.dart` | 269 | `MessageList, _MessageListState, MessageBubble, …` | | `lib/features/coach_chat/presentation/widgets/model_setup_screen.dart` | 116 | `ModelSetupScreen` | | `lib/features/coach_chat/presentation/widgets/pending_coach_action_card.dart` | 46 | `PendingCoachActionCard` | | `lib/features/coach_chat/presentation/widgets/streaming_text_pulse.dart` | 67 | `StreamingTextPulse, _StreamingTextPulseState` | @@ -288,7 +288,6 @@ There is **no `data/` layer yet**. Repository implementations live in `infrastru | `lib/features/dashboard/presentation/widgets/coach_agent_hero_card.dart` | 128 | `CoachAgentHeroCard, _PromptChip` | | `lib/features/dashboard/presentation/widgets/coach_insight_card.dart` | 214 | `CoachInsightCard, _CoachInsightContent, _AcwrOnlyCard, …` | | `lib/features/dashboard/presentation/widgets/connect_healthkit_card.dart` | 88 | `ConnectHealthkitCard` | -| `lib/features/dashboard/presentation/widgets/daily_quest_teaser.dart` | 129 | `DailyQuestTeaser` | | `lib/features/dashboard/presentation/widgets/dashboard_header_sliver.dart` | 109 | `DashboardHeaderSliver` | | `lib/features/dashboard/presentation/widgets/gait_teaser_card.dart` | 94 | `GaitTeaserCard` | | `lib/features/dashboard/presentation/widgets/health_metrics_grid.dart` | 254 | `HealthMetricsGrid` | @@ -335,7 +334,7 @@ There is **no `data/` layer yet**. Repository implementations live in `infrastru | `lib/features/settings/providers/manual_run_provider.dart` | 104 | `ManualRunState, ManualRun` | | `lib/features/settings/providers/openrouter_models_provider.dart` | 121 | `OpenRouterCatalogState, OpenRouterCatalog` | | `lib/features/settings/providers/settings_provider.dart` | 1 | `Dart module` | -| `lib/features/training/presentation/pages/training_page.dart` | 323 | `TrainingPage, _TrainingPageState, _TrendAnalysis` | +| `lib/features/training/presentation/pages/training_page.dart` | 582 | `TrainingPage, _TrainingPageState, _SectionAnchor, …` | | `lib/features/training/presentation/widgets/past_runs_list.dart` | 73 | `PastRunsList` | | `lib/features/training/presentation/widgets/training_chip.dart` | 33 | `TrainingChip` | | `lib/features/training/presentation/widgets/training_insight_cards.dart` | 133 | `TrainingInsightsCards` | @@ -414,6 +413,7 @@ There is **no `data/` layer yet**. Repository implementations live in `infrastru | `lib/shared/providers/coach_personalization_provider.dart` | 74 | `CoachPersonalizationState, CoachPersonalizationNotifier` | | `lib/shared/providers/coach_usecase_providers.dart` | 29 | `Dart module` | | `lib/shared/providers/daily_quests_provider.dart` | 56 | `Dart module` | +| `lib/shared/providers/dashboard_summary_provider.dart` | 1 | `Dart module` | | `lib/shared/providers/gamification_providers.dart` | 73 | `Dart module` | | `lib/shared/providers/health_coach_providers.dart` | 215 | `HealthCoachData` | | `lib/shared/providers/health_import_providers.dart` | 23 | `Dart module` | @@ -450,19 +450,25 @@ There is **no `data/` layer yet**. Repository implementations live in `infrastru | `lib/shared/widgets/charts/health_trend_chart.dart` | 279 | `HealthTrendPoint, HealthTrendChart, _HealthTrendChartState` | | `lib/shared/widgets/charts/hrv_chart.dart` | 86 | `HrvChart` | | `lib/shared/widgets/charts/load_chart.dart` | 85 | `LoadChart` | +| `lib/shared/widgets/daily_quest_teaser.dart` | 129 | `DailyQuestTeaser` | | `lib/shared/widgets/gait_model_card.dart` | 247 | `GaitModelCard, _CoefficientsRow, GaitModelCardAsync` | | `lib/shared/widgets/glass_card.dart` | 43 | `GlassCard` | | `lib/shared/widgets/insight_expandable_card.dart` | 221 | `InsightExpandableCard, _InsightExpandableCardState, InsightTextExpandableCard, …` | | `lib/shared/widgets/kynos_bottom_nav.dart` | 185 | `KynosBottomNavItem, KynosBottomNav, _NavBarItem` | | `lib/shared/widgets/kynos_card.dart` | 57 | `KynosCard` | | `lib/shared/widgets/kynos_chip.dart` | 128 | `KynosChip, _MetricChip, _AccentChip` | +| `lib/shared/widgets/kynos_collapsible_section.dart` | 105 | `KynosCollapsibleSection, _KynosCollapsibleSectionState` | | `lib/shared/widgets/kynos_hero_banner.dart` | 125 | `KynosHeroBanner` | | `lib/shared/widgets/kynos_inline_error_card.dart` | 53 | `KynosInlineErrorCard` | | `lib/shared/widgets/kynos_loading_line.dart` | 59 | `KynosLoadingLine` | +| `lib/shared/widgets/kynos_nav_rail.dart` | 143 | `KynosNavRailItem, KynosNavRail, _RailItem` | | `lib/shared/widgets/kynos_page_dots.dart` | 45 | `KynosPageDots` | +| `lib/shared/widgets/kynos_page_header.dart` | 114 | `KynosPageHeader` | | `lib/shared/widgets/kynos_privacy_footer.dart` | 25 | `KynosPrivacyFooter` | | `lib/shared/widgets/kynos_section_header.dart` | 21 | `KynosSectionHeader` | +| `lib/shared/widgets/kynos_section_jump_bar.dart` | 87 | `KynosSectionJumpBar, _JumpChip` | | `lib/shared/widgets/kynos_section_row.dart` | 38 | `KynosSectionRow` | +| `lib/shared/widgets/kynos_segmented_control.dart` | 98 | `KynosSegmentedControl, _Segment` | | `lib/shared/widgets/kynos_skeleton.dart` | 41 | `KynosSkeleton` | | `lib/shared/widgets/kynos_user_bubble.dart` | 57 | `KynosUserBubble` | | `lib/shared/widgets/liquid_glass_button.dart` | 142 | `LiquidGlassButton, LiquidGlassIconButton` | @@ -471,7 +477,7 @@ There is **no `data/` layer yet**. Repository implementations live in `infrastru | `lib/shared/widgets/nav_icon.dart` | 238 | `NavIconDefinition, NavIconPainter` | | `lib/shared/widgets/responsive_center.dart` | 30 | `ResponsiveCenter` | | `lib/shared/widgets/run_card.dart` | 113 | `RunCard` | -| `lib/shared/widgets/widgets.dart` | 24 | `KYNOS shared widgets — barrel export.` | +| `lib/shared/widgets/widgets.dart` | 30 | `KYNOS shared widgets — barrel export.` | ## Hot Files (do not grow) @@ -479,6 +485,7 @@ There is **no `data/` layer yet**. Repository implementations live in `infrastru |------|------:|--------| | `lib/features/coach_chat/providers/coach_chat_provider.dart` | 719 | Split if > 250 lines | | `lib/features/settings/presentation/pages/settings_page.dart` | 689 | Split if > 250 lines | +| `lib/features/training/presentation/pages/training_page.dart` | 582 | Split if > 250 lines | | `lib/domain/usecases/coach/coach_tool_health_queries.dart` | 521 | Split if > 250 lines | | `lib/features/coach_chat/presentation/pages/coach_chat_page.dart` | 425 | Split if > 250 lines | | `lib/features/coach_chat/presentation/widgets/health_visual_artifact_card.dart` | 404 | Split if > 250 lines | @@ -486,8 +493,7 @@ There is **no `data/` layer yet**. Repository implementations live in `infrastru | `lib/domain/usecases/coach/coach_tool_wellbeing_queries.dart` | 387 | Split if > 250 lines | | `lib/infrastructure/ai/isolate_ai_coach_repository.dart` | 375 | Split if > 250 lines | | `lib/infrastructure/coach/coach_conversation_codec.dart` | 357 | Split if > 250 lines | -| `lib/features/training/presentation/pages/training_page.dart` | 323 | Split if > 250 lines | -| `lib/features/character/presentation/pages/character_page.dart` | 297 | Split if > 250 lines | +| `lib/features/character/presentation/pages/character_page.dart` | 302 | Split if > 250 lines | | `lib/infrastructure/health/import/apple_health_export_parser.dart` | 296 | Split if > 250 lines | | `lib/domain/usecases/insights/generate_training_insights_usecase.dart` | 287 | Split if > 250 lines | | `lib/features/settings/providers/health_import_provider.dart` | 280 | Split if > 250 lines | @@ -495,9 +501,9 @@ There is **no `data/` layer yet**. Repository implementations live in `infrastru | `lib/features/onboarding/presentation/onboarding_page.dart` | 278 | Split if > 250 lines | | `lib/domain/catalog/on_device_model_catalog.dart` | 275 | Split if > 250 lines | | `lib/domain/utils/run_route_analytics.dart` | 274 | Split if > 250 lines | -| `lib/features/coach_chat/presentation/widgets/message_list.dart` | 273 | Split if > 250 lines | | `lib/features/character/presentation/widgets/quest_card.dart` | 269 | Split if > 250 lines | +| `lib/features/coach_chat/presentation/widgets/message_list.dart` | 269 | Split if > 250 lines | -_Generated by `dart run tool/generate_codemap.dart` — 378 hand-written Dart files._ +_Generated by `dart run tool/generate_codemap.dart` — 384 hand-written Dart files._ diff --git a/lib/app/shell_page.dart b/lib/app/shell_page.dart index 02873dd..2fae8ce 100644 --- a/lib/app/shell_page.dart +++ b/lib/app/shell_page.dart @@ -5,20 +5,20 @@ import 'package:kynos/app/shell_navigation_scope.dart'; import 'package:kynos/core/theme/theme.dart'; import 'package:kynos/features/character/presentation/pages/character_page.dart'; import 'package:kynos/features/training/presentation/pages/training_page.dart'; -import 'package:kynos/shared/widgets/kynos_bottom_nav.dart'; +import 'package:kynos/shared/widgets/kynos_nav_rail.dart'; import 'package:kynos/shared/widgets/nav_icon.dart'; import 'package:kynos/shared/widgets/responsive_center.dart'; -/// Root app shell — floating bottom nav with three focused tabs. +/// Root app shell — left-edge nav rail with three focused tabs. class ShellPage extends ConsumerWidget { const ShellPage({super.key, required this.navigationShell}); final StatefulNavigationShell navigationShell; static const _navItems = [ - KynosBottomNavItem(label: 'Coach', icon: NavIconPaths.coach), - KynosBottomNavItem(label: 'Health', icon: NavIconPaths.training), - KynosBottomNavItem(label: 'Journey', icon: NavIconPaths.character), + KynosNavRailItem(label: 'Coach', icon: NavIconPaths.coach), + KynosNavRailItem(label: 'Health', icon: NavIconPaths.training), + KynosNavRailItem(label: 'Journey', icon: NavIconPaths.character), ]; void _onTabSelected(int index) { @@ -36,41 +36,47 @@ class ShellPage extends ConsumerWidget { goToBranch: _onTabSelected, child: Scaffold( backgroundColor: kynos.background, - extendBody: true, - body: ResponsiveCenter( - child: Padding( - padding: EdgeInsets.only( - bottom: LayoutTokens.shellNavExtent(context), - ), - child: _AnimatedShellBody( - tabIndex: navigationShell.currentIndex, - child: navigationShell, - ), - ), - ), - bottomNavigationBar: Align( - alignment: Alignment.bottomCenter, - child: ConstrainedBox( - constraints: const BoxConstraints( - maxWidth: LayoutTokens.maxContentWidth, + body: Stack( + fit: StackFit.expand, + children: [ + Positioned( + top: -120, + right: -80, + child: IgnorePointer( + child: Container( + width: 280, + height: 280, + decoration: BoxDecoration( + shape: BoxShape.circle, + gradient: RadialGradient( + colors: [ + kynos.purple.withValues(alpha: 0.08), + Colors.transparent, + ], + ), + ), + ), + ), ), - child: AnimatedSlide( - duration: Motion.fast, - curve: Motion.curve, - offset: MediaQuery.viewInsetsOf(context).bottom > 0 - ? const Offset(0, 1.4) - : Offset.zero, - child: AnimatedOpacity( - duration: Motion.fast, - opacity: MediaQuery.viewInsetsOf(context).bottom > 0 ? 0 : 1, - child: KynosBottomNav( + Row( + crossAxisAlignment: CrossAxisAlignment.stretch, + children: [ + KynosNavRail( items: _navItems, selectedIndex: navigationShell.currentIndex, onSelected: _onTabSelected, ), - ), + Expanded( + child: ResponsiveCenter( + child: _AnimatedShellBody( + tabIndex: navigationShell.currentIndex, + child: navigationShell, + ), + ), + ), + ], ), - ), + ], ), ), ); @@ -106,7 +112,7 @@ class _AnimatedShellBodyState extends State<_AnimatedShellBody> } void _buildAnimations() { - final slideOffset = 0.15 * _direction; + final slideOffset = 0.08 * _direction; final curved = CurvedAnimation(parent: _controller, curve: Motion.curve); _slide = Tween( begin: Offset(slideOffset, 0), @@ -143,7 +149,7 @@ class _AnimatedShellBodyState extends State<_AnimatedShellBody> } } -/// Health tab — sleep, recovery, movement, experiments, and activity detail. +/// Health tab — unified health hub (dashboard + training). class HealthTab extends StatelessWidget { const HealthTab({super.key}); @@ -153,7 +159,7 @@ class HealthTab extends StatelessWidget { } } -/// Journey tab — sustainable wellbeing progression and the existing camp. +/// Journey tab — sustainable wellbeing progression and camp. class JourneyTab extends StatelessWidget { const JourneyTab({super.key}); diff --git a/lib/core/theme/layout.dart b/lib/core/theme/layout.dart index 5df1af5..724bed1 100644 --- a/lib/core/theme/layout.dart +++ b/lib/core/theme/layout.dart @@ -3,17 +3,23 @@ import 'package:kynos/core/theme/spacing.dart' as tokens; /// Layout constants for consistent page structure. abstract final class LayoutTokens { - /// Fixed height of the floating shell nav bar (excludes device safe-area). - static const double shellNavBarHeight = - tokens.Spacing.md + tokens.Spacing.xs + tokens.Spacing.xs * 2 + 56; + /// Width of the left-edge shell navigation rail. + static const double shellRailWidth = 56; - /// Total bottom inset required to clear the floating shell nav bar. - static double shellNavExtent(BuildContext context) => - shellNavBarHeight + MediaQuery.viewPaddingOf(context).bottom; + /// @deprecated Use [shellRailWidth]. Kept for legacy bottom-nav references. + static const double shellNavBarHeight = shellRailWidth; - /// Bottom scroll padding to clear the floating shell nav bar. - static const double shellBottomPadding = - tokens.Spacing.xxxl * 2 + tokens.Spacing.xl + tokens.Spacing.lg; + /// Total bottom inset — rail layout no longer reserves bottom chrome. + static double shellNavExtent(BuildContext context) => 0; + + /// Bottom scroll padding for tab content (safe-area aware). + static double shellBottomPadding(BuildContext context) => + tokens.Spacing.xxxl + + MediaQuery.viewPaddingOf(context).bottom; + + /// @deprecated Prefer [shellBottomPadding] with context for safe-area. + static const double shellBottomPaddingLegacy = + tokens.Spacing.xxxl + tokens.Spacing.lg; static const double heroBannerHeight = tokens.Spacing.xxxl * 2 + tokens.Spacing.sm - tokens.Spacing.xs; @@ -36,6 +42,10 @@ abstract final class LayoutTokens { right: tokens.Spacing.md, ); + static const EdgeInsets shellRailPadding = EdgeInsets.only( + left: tokens.Spacing.xs, + ); + static const EdgeInsets settingsSectionPadding = EdgeInsets.fromLTRB( tokens.Spacing.md, tokens.Spacing.lg, diff --git a/lib/features/character/presentation/pages/character_page.dart b/lib/features/character/presentation/pages/character_page.dart index 6630128..389d09d 100644 --- a/lib/features/character/presentation/pages/character_page.dart +++ b/lib/features/character/presentation/pages/character_page.dart @@ -26,6 +26,7 @@ import 'package:kynos/shared/providers/nexus_lab_provider.dart'; import 'package:kynos/shared/utils/health_permission_feedback.dart'; import 'package:kynos/shared/utils/health_platform_labels.dart'; import 'package:kynos/shared/utils/open_coach_chat.dart'; +import 'package:kynos/shared/widgets/daily_quest_teaser.dart'; import 'package:kynos/shared/widgets/kynos_inline_error_card.dart'; import 'package:kynos/shared/widgets/kynos_section_header.dart'; import 'package:kynos/shared/widgets/kynos_skeleton.dart'; @@ -108,11 +109,11 @@ class CharacterPage extends ConsumerWidget { return const SliverFillRemaining(child: EmptyCharacterState()); } return SliverPadding( - padding: const EdgeInsets.fromLTRB( + padding: EdgeInsets.fromLTRB( tokens.Spacing.md, 0, tokens.Spacing.md, - LayoutTokens.shellBottomPadding, + LayoutTokens.shellBottomPadding(context), ), sliver: SliverList.list( children: [ @@ -162,6 +163,10 @@ class CharacterPage extends ConsumerWidget { const Gap(tokens.Spacing.md), XpBar(character: character), const Gap(tokens.Spacing.lg), + const KynosSectionHeader(title: 'DAILY QUEST'), + const Gap(tokens.Spacing.sm), + DailyQuestTeaser(questsAsync: questsAsync), + const Gap(tokens.Spacing.lg), const KynosSectionHeader(title: 'STATS'), const Gap(tokens.Spacing.sm), StatsPanel(character: character), diff --git a/lib/features/coach_chat/presentation/widgets/message_list.dart b/lib/features/coach_chat/presentation/widgets/message_list.dart index 47431dd..8e862b5 100644 --- a/lib/features/coach_chat/presentation/widgets/message_list.dart +++ b/lib/features/coach_chat/presentation/widgets/message_list.dart @@ -5,6 +5,7 @@ import 'package:kynos/core/theme/theme.dart'; import 'package:kynos/domain/entities/ai_inference_backend.dart'; import 'package:kynos/domain/entities/chat_message.dart'; import 'package:kynos/domain/entities/health/health_coach_models.dart'; +import 'package:kynos/domain/utils/readiness_score.dart'; import 'package:kynos/features/coach_chat/presentation/widgets/animated_message_entrance.dart'; import 'package:kynos/features/coach_chat/presentation/widgets/assistant_bubble.dart'; import 'package:kynos/features/coach_chat/presentation/widgets/daily_health_brief_card.dart'; @@ -13,6 +14,8 @@ import 'package:kynos/features/coach_chat/presentation/widgets/health_check_in_s import 'package:kynos/features/coach_chat/providers/coach_chat_provider.dart'; import 'package:kynos/shared/providers/ai_repository_providers.dart'; import 'package:kynos/shared/providers/health_coach_providers.dart'; +import 'package:kynos/shared/providers/health_providers.dart'; +import 'package:kynos/shared/widgets/kynos_chip.dart'; import 'package:kynos/shared/widgets/kynos_loading_line.dart'; import 'package:kynos/shared/widgets/kynos_user_bubble.dart'; @@ -168,7 +171,9 @@ class CoachChatEmptyState extends ConsumerWidget { @override Widget build(BuildContext context, WidgetRef ref) { final brief = ref.watch(dailyHealthBriefProvider); + final summary = ref.watch(healthSummaryProvider); final coachData = ref.watch(healthCoachDataProvider).value; + final kynos = context.kynosTheme; final now = DateTime.now(); final todayCheckIn = coachData?.checkIns .where( @@ -178,6 +183,11 @@ class CoachChatEmptyState extends ConsumerWidget { item.date.day == now.day, ) .firstOrNull; + final readiness = readinessScore(summary.value); + final readinessLine = readiness > 0 + ? readinessSummaryBrief(readiness).split('.').first + : null; + return ListView( padding: const EdgeInsets.fromLTRB( Spacing.md, @@ -186,6 +196,13 @@ class CoachChatEmptyState extends ConsumerWidget { LayoutTokens.chatInputClearance, ), children: [ + if (readinessLine != null) ...[ + KynosChip.accent( + label: readinessLine, + color: kynos.purple, + ), + const Gap(Spacing.sm), + ], brief.when( loading: () => const KynosLoadingLine(label: 'Building your health brief…'), @@ -217,55 +234,34 @@ class CoachChatEmptyState extends ConsumerWidget { ), ), const Gap(Spacing.xl), - Padding( - padding: const EdgeInsets.symmetric(horizontal: Spacing.sm), - child: Column( - children: [ - Container( - width: 52, - height: 52, - decoration: BoxDecoration( - color: context.kynosTheme.purple.withValues(alpha: 0.12), - borderRadius: BorderRadius.circular(Radius.lg), - ), - child: Icon( - Icons.auto_awesome_rounded, - color: context.kynosTheme.purple, - ), - ), - const Gap(Spacing.md), - Text( - 'What would you like to understand?', - style: Theme.of(context).textTheme.displaySmall, - ), - const Gap(Spacing.sm), - Text( - 'KYNOS can investigate patterns, build local visualisations, and explain uncertainty.', - textAlign: TextAlign.center, - style: Theme.of(context).textTheme.bodyMedium, - ), - const Gap(Spacing.lg), - Wrap( - alignment: WrapAlignment.center, - spacing: Spacing.sm, - runSpacing: Spacing.sm, - children: - [ - 'Why has my energy changed?', - 'Show my sleep trend', - 'Compare this week with last week', - 'What seems to help my wellbeing?', - ] - .map( - (suggestion) => GlassSuggestionChip( - label: suggestion, - onTap: () => onSuggestionTap(suggestion), - ), - ) - .toList(), + Text( + 'What would you like to understand?', + style: Theme.of(context).textTheme.titleLarge, + ), + const Gap(Spacing.xs), + Text( + 'Ask about patterns, trends, or what to do next.', + style: Theme.of(context).textTheme.bodyMedium?.copyWith( + color: kynos.secondaryLabel, ), - ], - ), + ), + const Gap(Spacing.lg), + Wrap( + spacing: Spacing.sm, + runSpacing: Spacing.sm, + children: [ + 'Why has my energy changed?', + 'Show my sleep trend', + 'Compare this week with last week', + 'What should I do today?', + ] + .map( + (suggestion) => GlassSuggestionChip( + label: suggestion, + onTap: () => onSuggestionTap(suggestion), + ), + ) + .toList(), ), ], ); diff --git a/lib/features/dashboard/presentation/pages/dashboard_page.dart b/lib/features/dashboard/presentation/pages/dashboard_page.dart index 3e70e3b..a48c29e 100644 --- a/lib/features/dashboard/presentation/pages/dashboard_page.dart +++ b/lib/features/dashboard/presentation/pages/dashboard_page.dart @@ -15,7 +15,6 @@ import 'package:kynos/features/dashboard/presentation/widgets/character_glance_c import 'package:kynos/features/dashboard/presentation/widgets/coach_agent_hero_card.dart'; import 'package:kynos/features/dashboard/presentation/widgets/coach_insight_card.dart'; import 'package:kynos/features/dashboard/presentation/widgets/connect_healthkit_card.dart'; -import 'package:kynos/features/dashboard/presentation/widgets/daily_quest_teaser.dart'; import 'package:kynos/features/dashboard/presentation/widgets/dashboard_header_sliver.dart'; import 'package:kynos/features/dashboard/presentation/widgets/gait_teaser_card.dart'; import 'package:kynos/features/dashboard/presentation/widgets/health_metrics_grid.dart'; @@ -33,6 +32,7 @@ import 'package:kynos/shared/providers/nexus_lab_provider.dart'; import 'package:kynos/shared/providers/training_insights_provider.dart'; import 'package:kynos/shared/utils/open_coach_chat.dart'; import 'package:kynos/shared/widgets/charts/health_trend_chart.dart'; +import 'package:kynos/shared/widgets/daily_quest_teaser.dart'; import 'package:kynos/shared/widgets/kynos_card.dart'; import 'package:kynos/shared/widgets/kynos_chip.dart'; import 'package:kynos/shared/widgets/kynos_privacy_footer.dart'; @@ -234,11 +234,11 @@ class _DashboardPageState extends ConsumerState { onAskCoach: () => _openCoachChat(), ), SliverPadding( - padding: const EdgeInsets.fromLTRB( + padding: EdgeInsets.fromLTRB( tokens.Spacing.md, tokens.Spacing.lg, tokens.Spacing.md, - LayoutTokens.shellBottomPadding, + LayoutTokens.shellBottomPadding(context), ), sliver: SliverList.list( children: [ diff --git a/lib/features/training/presentation/pages/training_page.dart b/lib/features/training/presentation/pages/training_page.dart index 335c18e..248ae59 100644 --- a/lib/features/training/presentation/pages/training_page.dart +++ b/lib/features/training/presentation/pages/training_page.dart @@ -7,26 +7,38 @@ import 'package:kynos/app/router.dart'; import 'package:kynos/core/theme/spacing.dart' as tokens; import 'package:kynos/core/theme/theme.dart'; import 'package:kynos/domain/entities/coach/coach_seed_topic.dart'; +import 'package:kynos/domain/entities/dashboard/dashboard_summary.dart'; import 'package:kynos/domain/entities/health_summary.dart'; +import 'package:kynos/domain/utils/readiness_score.dart'; +import 'package:kynos/domain/utils/weekly_momentum.dart'; +import 'package:kynos/features/dashboard/presentation/widgets/coach_insight_card.dart'; +import 'package:kynos/features/dashboard/presentation/widgets/connect_healthkit_card.dart'; +import 'package:kynos/features/dashboard/presentation/widgets/last_run_preview.dart'; +import 'package:kynos/features/dashboard/presentation/widgets/readiness_card.dart'; +import 'package:kynos/features/dashboard/presentation/widgets/week_momentum_card.dart'; import 'package:kynos/features/training/presentation/widgets/past_runs_list.dart'; -import 'package:kynos/features/training/presentation/widgets/training_insight_cards.dart'; import 'package:kynos/features/training/presentation/widgets/weekly_stats_grid.dart'; import 'package:kynos/features/training/presentation/widgets/wellbeing_panels.dart'; -import 'package:kynos/features/training/providers/training_insights_provider.dart'; +import 'package:kynos/shared/providers/dashboard_summary_provider.dart'; import 'package:kynos/shared/providers/health_coach_providers.dart'; import 'package:kynos/shared/providers/health_providers.dart'; import 'package:kynos/shared/providers/nexus_lab_provider.dart'; -import 'package:kynos/shared/utils/date_label.dart'; +import 'package:kynos/shared/providers/today_insights_provider.dart'; import 'package:kynos/shared/utils/open_coach_chat.dart'; import 'package:kynos/shared/widgets/charts/health_trend_chart.dart'; import 'package:kynos/shared/widgets/gait_model_card.dart'; import 'package:kynos/shared/widgets/kynos_card.dart'; +import 'package:kynos/shared/widgets/kynos_chip.dart'; +import 'package:kynos/shared/widgets/kynos_collapsible_section.dart'; import 'package:kynos/shared/widgets/kynos_inline_error_card.dart'; import 'package:kynos/shared/widgets/kynos_loading_line.dart'; +import 'package:kynos/shared/widgets/kynos_page_header.dart'; import 'package:kynos/shared/widgets/kynos_privacy_footer.dart'; import 'package:kynos/shared/widgets/kynos_section_header.dart'; +import 'package:kynos/shared/widgets/kynos_section_jump_bar.dart'; +import 'package:kynos/shared/widgets/kynos_segmented_control.dart'; -/// Training tab — weekly stats, trends, runs, and gait model. +/// Unified Health hub — merges dashboard "today" surfaces with training detail. class TrainingPage extends ConsumerStatefulWidget { const TrainingPage({super.key}); @@ -35,202 +47,417 @@ class TrainingPage extends ConsumerStatefulWidget { } class _TrainingPageState extends ConsumerState { + final _scrollController = ScrollController(); + final _sectionKeys = List.generate(5, (_) => GlobalKey()); + int _jumpIndex = 0; HealthChartRange _range = HealthChartRange.month; - HealthChartMetric _metric = HealthChartMetric.distance; + HealthChartMetric _metric = HealthChartMetric.recovery; - Future _refreshTraining() async { + static const _jumpSections = [ + 'Today', + 'Week', + 'Trends', + 'Runs', + 'More', + ]; + + @override + void dispose() { + _scrollController.dispose(); + super.dispose(); + } + + Future _refreshHealthHub() async { final days = _range.days * 2; + ref.invalidate(healthSummaryProvider); + ref.invalidate(todayInsightsStateProvider); + ref.invalidate(healthHistoryProvider(days: 28)); ref.invalidate(healthHistoryProvider(days: days)); ref.invalidate(recentRunsProvider(days: 365, limit: 60)); - ref.invalidate(trainingInsightsStateProvider); + ref.invalidate(recentRunsProvider(days: 30, limit: 3)); + ref.invalidate(dashboardSummaryProvider); ref.invalidate(nexusLabProvider); ref.invalidate(dailyHealthBriefProvider); ref.invalidate(healthCoachDataProvider); await Future.wait([ + ref.read(healthSummaryProvider.future), + ref.read(todayInsightsStateProvider.future), ref.read(healthHistoryProvider(days: days).future), + ref.read(healthHistoryProvider(days: 28).future), ref.read(recentRunsProvider(days: 365, limit: 60).future), - ref.read(trainingInsightsStateProvider.future), - ref.read(nexusLabProvider.future), + ref.read(recentRunsProvider(days: 30, limit: 3).future), + ref.read(dashboardSummaryProvider.future), ref.read(dailyHealthBriefProvider.future), ref.read(healthCoachDataProvider.future), ]); } + void _scrollToSection(int index) { + setState(() => _jumpIndex = index); + final context = _sectionKeys[index].currentContext; + if (context != null) { + Scrollable.ensureVisible( + context, + duration: Motion.medium, + curve: Motion.curve, + alignment: 0.05, + ); + } + } + + void _openCoachChat({ + String? seedMessage, + CoachSeedTopic topic = CoachSeedTopic.general, + }) { + openCoachChat(context, ref, seed: seedMessage, topic: topic); + } + + String _greeting() { + final h = DateTime.now().hour; + if (h < 5) return 'Good night'; + if (h < 12) return 'Good morning'; + if (h < 17) return 'Good afternoon'; + if (h < 21) return 'Good evening'; + return 'Good night'; + } + + String _statusSubtitle({ + required HealthSummary? summary, + required DashboardSummary? dash, + }) { + final parts = []; + final score = readinessScore(summary); + if (score > 0) { + parts.add(readinessSummaryBrief(score).split('.').first); + } + if (dash != null && dash.runStreak > 0) { + parts.add('${dash.runStreak}-day streak'); + } + if (parts.isEmpty) { + return 'Sleep, recovery, movement, and how you feel'; + } + return parts.join(' · '); + } + + bool _shouldShowWeeklyGoalCoachNudge(WeeklyMomentum? momentum) { + if (momentum == null) return false; + return DateTime.now().weekday >= DateTime.wednesday && + momentum.distanceGoalProgress < 0.5; + } + + List _currentPeriod(List items) { + final cutoff = DateTime.now().subtract(Duration(days: _range.days)); + return items.where((item) => item.date.isAfter(cutoff)).toList(); + } + @override Widget build(BuildContext context) { + final summary = ref.watch(healthSummaryProvider); + final todayInsights = ref.watch(todayInsightsStateProvider); final history = ref.watch(healthHistoryProvider(days: _range.days * 2)); + final weekHistory = ref.watch(healthHistoryProvider(days: 28)); + final recentRunsPreview = ref.watch(recentRunsProvider(days: 30, limit: 3)); final recentRuns = ref.watch(recentRunsProvider(days: 365, limit: 60)); - final labState = kIsWeb ? null : ref.watch(nexusLabProvider); - final insightsState = ref.watch(trainingInsightsStateProvider); + final dashboardSummaryAsync = ref.watch(dashboardSummaryProvider); + final dash = dashboardSummaryAsync.value; final healthBrief = ref.watch(dailyHealthBriefProvider); final coachData = ref.watch(healthCoachDataProvider); - - final kynos = context.kynosTheme; + final labState = kIsWeb ? null : ref.watch(nexusLabProvider); + final showConnectCard = + !kIsWeb && summary.hasValue && summary.requireValue == null; return RefreshIndicator( - onRefresh: _refreshTraining, + onRefresh: _refreshHealthHub, child: CustomScrollView( + controller: _scrollController, physics: const AlwaysScrollableScrollPhysics( parent: BouncingScrollPhysics(), ), slivers: [ - SliverAppBar( - backgroundColor: kynos.background, - surfaceTintColor: Colors.transparent, - elevation: 0, + KynosPageHeader( + greeting: _greeting(), + title: 'Health', + subtitle: _statusSubtitle(summary: summary.value, dash: dash), + onAskCoach: () => _openCoachChat(), + ), + SliverPersistentHeader( pinned: true, - toolbarHeight: 56, - titleSpacing: 20, - title: Text( - formatDateLabel(), - style: Theme.of(context).textTheme.labelLarge?.copyWith( - color: kynos.tertiaryLabel, - letterSpacing: 0.2, + delegate: _JumpBarDelegate( + child: KynosSectionJumpBar( + sections: _jumpSections, + selectedIndex: _jumpIndex, + onSelected: _scrollToSection, ), ), ), SliverPadding( - padding: const EdgeInsets.fromLTRB( + padding: EdgeInsets.fromLTRB( tokens.Spacing.md, - 0, + tokens.Spacing.sm, tokens.Spacing.md, - LayoutTokens.shellBottomPadding, + LayoutTokens.shellBottomPadding(context), ), sliver: SliverList.list( children: [ - Text('HEALTH', style: Theme.of(context).textTheme.labelSmall), - const Gap(tokens.Spacing.xs), - Text( - 'Health', - style: Theme.of(context).textTheme.headlineLarge, - ), - const Gap(tokens.Spacing.xs), - Text( - 'Understand your sleep, recovery, movement, and lived experience', - style: Theme.of(context).textTheme.bodyMedium, - ), - const Gap(tokens.Spacing.lg), - const KynosSectionHeader(title: 'Today'), - const Gap(tokens.Spacing.sm), - DailyHealthOverview(brief: healthBrief), - const Gap(tokens.Spacing.lg), - const KynosSectionHeader(title: 'Body signals'), - const Gap(tokens.Spacing.sm), - history.when( - loading: () => const KynosCard( - child: KynosLoadingLine(label: 'Loading weekly stats...'), + _SectionAnchor( + key: _sectionKeys[0], + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + const KynosSectionHeader(title: 'Today'), + const Gap(tokens.Spacing.sm), + ReadinessCard( + summaryAsync: summary, + todayInsightsState: todayInsights, + onRetry: _refreshHealthHub, + ), + const Gap(tokens.Spacing.md), + DailyHealthOverview(brief: healthBrief), + ], ), - error: (_, _) => KynosInlineErrorCard( - message: 'Could not load weekly stats.', - onRetry: () => ref.invalidate( - healthHistoryProvider(days: _range.days * 2), - ), - ), - data: (items) => - WeeklyStatsGrid(history: _currentPeriod(items)), - ), - const Gap(tokens.Spacing.lg), - const KynosSectionHeader(title: 'Progress'), - const Gap(tokens.Spacing.sm), - _TrendAnalysis( - history: history, - range: _range, - metric: _metric, - onRangeChanged: (value) => setState(() => _range = value), - onMetricChanged: (value) => setState(() => _metric = value), ), - const Gap(tokens.Spacing.lg), - TrainingInsightsCards(insightsState: insightsState), - const Gap(tokens.Spacing.lg), - const KynosSectionHeader(title: 'How you felt'), - const Gap(tokens.Spacing.sm), - coachData.when( - loading: () => const KynosCard( - child: KynosLoadingLine(label: 'Loading check-ins...'), - ), - error: (_, _) => KynosInlineErrorCard( - message: 'Could not load check-ins.', - onRetry: () => ref.invalidate(healthCoachDataProvider), + const Gap(tokens.Spacing.xl), + _SectionAnchor( + key: _sectionKeys[1], + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + const KynosSectionHeader(title: 'This week'), + const Gap(tokens.Spacing.sm), + WeekMomentumCard( + momentum: dash?.weeklyMomentum, + isLoading: weekHistory.isLoading || + dashboardSummaryAsync.isLoading, + onImportRun: () => context.push(Routes.healthImport), + onAskCoach: _shouldShowWeeklyGoalCoachNudge( + dash?.weeklyMomentum, + ) + ? () => _openCoachChat( + seedMessage: + 'I am behind on my weekly distance goal. ' + 'Help me plan the rest of the week.', + topic: CoachSeedTopic.weeklyGoal, + ) + : null, + ), + ], ), - data: (data) => CheckInHistoryPanel(checkIns: data.checkIns), ), - const Gap(tokens.Spacing.lg), - const KynosSectionHeader(title: 'Wellbeing experiments'), - const Gap(tokens.Spacing.sm), - coachData.when( - loading: () => const KynosCard( - child: KynosLoadingLine(label: 'Loading experiments...'), - ), - error: (_, _) => KynosInlineErrorCard( - message: 'Could not load wellbeing experiments.', - onRetry: () => ref.invalidate(healthCoachDataProvider), + const Gap(tokens.Spacing.xl), + _SectionAnchor( + key: _sectionKeys[2], + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + const KynosSectionHeader(title: 'Body signals'), + const Gap(tokens.Spacing.sm), + history.when( + loading: () => const KynosCard( + child: KynosLoadingLine( + label: 'Loading weekly stats...', + ), + ), + error: (_, _) => KynosInlineErrorCard( + message: 'Could not load weekly stats.', + onRetry: () => ref.invalidate( + healthHistoryProvider(days: _range.days * 2), + ), + ), + data: (items) => WeeklyStatsGrid( + history: _currentPeriod(items), + ), + ), + const Gap(tokens.Spacing.lg), + const KynosSectionHeader(title: 'Trends'), + const Gap(tokens.Spacing.sm), + _TrendAnalysis( + history: history, + range: _range, + metric: _metric, + onRangeChanged: (value) => + setState(() => _range = value), + onMetricChanged: (value) => + setState(() => _metric = value), + ), + const Gap(tokens.Spacing.lg), + CoachInsightCard( + todayInsightsState: todayInsights, + history: history.value ?? const [], + onAskCoach: () => _openCoachChat( + seedMessage: + 'Based on my readiness today, what should I ' + 'prioritise in training?', + topic: CoachSeedTopic.general, + ), + ), + ], ), - data: (data) => - WellbeingExperimentsPanel(experiments: data.experiments), ), - const Gap(tokens.Spacing.lg), - Row( - children: [ - const Expanded( - child: KynosSectionHeader(title: 'Movement & exercise'), - ), - TextButton( - onPressed: () => context.push(Routes.runHistory), - child: const Text('View all'), - ), - ], - ), - const Gap(tokens.Spacing.sm), - recentRuns.when( - loading: () => const KynosCard( - child: KynosLoadingLine(label: 'Loading recent runs...'), - ), - error: (_, _) => KynosInlineErrorCard( - message: 'Could not load recent runs.', - onRetry: () => ref.invalidate( - recentRunsProvider(days: 365, limit: 60), - ), - ), - data: (runs) => PastRunsList( - runs: runs, - onAskCoach: (run, seed) => openCoachChat( - context, - ref, - seed: seed, - topic: CoachSeedTopic.run, - runId: run.id, - ), + const Gap(tokens.Spacing.xl), + _SectionAnchor( + key: _sectionKeys[3], + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Row( + children: [ + const Expanded( + child: KynosSectionHeader(title: 'Recent runs'), + ), + TextButton( + onPressed: () => context.push(Routes.runHistory), + child: const Text('View all'), + ), + ], + ), + const Gap(tokens.Spacing.sm), + LastRunPreview(runsAsync: recentRunsPreview), + const Gap(tokens.Spacing.md), + recentRuns.when( + loading: () => const KynosCard( + child: KynosLoadingLine( + label: 'Loading run history...', + ), + ), + error: (_, _) => KynosInlineErrorCard( + message: 'Could not load recent runs.', + onRetry: () => ref.invalidate( + recentRunsProvider(days: 365, limit: 60), + ), + ), + data: (runs) => PastRunsList( + runs: runs.take(5).toList(), + onAskCoach: (run, seed) => openCoachChat( + context, + ref, + seed: seed, + topic: CoachSeedTopic.run, + runId: run.id, + ), + ), + ), + ], ), ), - const Gap(tokens.Spacing.lg), - const KynosSectionHeader(title: 'Advanced movement analysis'), - const Gap(tokens.Spacing.sm), - GaitModelCardAsync( - labState: labState?.when( - loading: () => const AsyncLoading(), - error: AsyncError.new, - data: (state) => AsyncData(( - coefficients: state.coefficients, - calibratedAt: state.calibratedAt, - )), - ), - onCalibrate: kIsWeb - ? null - : () => ref.read(nexusLabProvider.notifier).calibrate(), - onAskCoach: () => openCoachChat( - context, - ref, - seed: - 'Explain my gait model and what the beta coefficients mean ' - 'for my running form.', - topic: CoachSeedTopic.gait, + const Gap(tokens.Spacing.xl), + _SectionAnchor( + key: _sectionKeys[4], + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + KynosCollapsibleSection( + title: 'How you felt', + subtitle: 'Daily check-ins and lived experience', + child: coachData.when( + loading: () => const KynosLoadingLine( + label: 'Loading check-ins...', + ), + error: (_, _) => KynosInlineErrorCard( + message: 'Could not load check-ins.', + onRetry: () => + ref.invalidate(healthCoachDataProvider), + ), + data: (data) => + CheckInHistoryPanel(checkIns: data.checkIns), + ), + ), + const Gap(tokens.Spacing.md), + coachData.when( + data: (data) { + if (data.experiments.isEmpty) { + return const SizedBox.shrink(); + } + return KynosCollapsibleSection( + title: 'Wellbeing experiments', + initiallyExpanded: true, + child: WellbeingExperimentsPanel( + experiments: data.experiments, + ), + ); + }, + loading: () => const SizedBox.shrink(), + error: (_, _) => const SizedBox.shrink(), + ), + const Gap(tokens.Spacing.md), + KynosCollapsibleSection( + title: 'Advanced analysis', + subtitle: 'Gait model and Nexus Lab', + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + GaitModelCardAsync( + labState: labState?.when( + loading: () => const AsyncLoading(), + error: AsyncError.new, + data: (state) => AsyncData(( + coefficients: state.coefficients, + calibratedAt: state.calibratedAt, + )), + ), + onCalibrate: kIsWeb + ? null + : () => ref + .read(nexusLabProvider.notifier) + .calibrate(), + onAskCoach: () => _openCoachChat( + seedMessage: + 'Explain my gait model and what the beta ' + 'coefficients mean for my running form.', + topic: CoachSeedTopic.gait, + ), + ), + const Gap(tokens.Spacing.sm), + KynosCard( + onTap: () => context.push(Routes.nexusLab), + child: Row( + children: [ + Icon( + Icons.science_outlined, + color: context.kynosTheme.purple, + ), + const Gap(tokens.Spacing.sm), + Expanded( + child: Column( + crossAxisAlignment: + CrossAxisAlignment.start, + children: [ + Text( + 'Nexus Lab', + style: Theme.of(context) + .textTheme + .titleSmall, + ), + Text( + 'Calibrate biomechanics coefficients', + style: Theme.of(context) + .textTheme + .bodySmall + ?.copyWith( + color: context + .kynosTheme + .secondaryLabel, + ), + ), + ], + ), + ), + KynosChip.accent( + label: 'Beta', + color: context.kynosTheme.purple, + ), + ], + ), + ), + ], + ), + ), + ], ), ), - const Gap(tokens.Spacing.lg), - TextButton( - onPressed: () => context.push(Routes.nexusLab), - child: const Text('Open Nexus Lab'), - ), + if (showConnectCard) ...[ + const Gap(tokens.Spacing.lg), + const ConnectHealthkitCard(), + ], const Gap(tokens.Spacing.lg), const KynosPrivacyFooter(), ], @@ -240,11 +467,52 @@ class _TrainingPageState extends ConsumerState { ), ); } +} - List _currentPeriod(List items) { - final cutoff = DateTime.now().subtract(Duration(days: _range.days)); - return items.where((item) => item.date.isAfter(cutoff)).toList(); +class _SectionAnchor extends StatelessWidget { + const _SectionAnchor({super.key, required this.child}); + + final Widget child; + + @override + Widget build(BuildContext context) => child; +} + +class _JumpBarDelegate extends SliverPersistentHeaderDelegate { + _JumpBarDelegate({required this.child}); + + final Widget child; + + @override + double get minExtent => 52; + + @override + double get maxExtent => 52; + + @override + Widget build( + BuildContext context, + double shrinkOffset, + bool overlapsContent, + ) { + final kynos = context.kynosTheme; + return ColoredBox( + color: kynos.background.withValues( + alpha: overlapsContent ? 0.96 : 1, + ), + child: Align( + alignment: Alignment.centerLeft, + child: Padding( + padding: const EdgeInsets.symmetric(vertical: tokens.Spacing.xs), + child: child, + ), + ), + ); } + + @override + bool shouldRebuild(covariant _JumpBarDelegate oldDelegate) => + oldDelegate.child != child; } class _TrendAnalysis extends StatelessWidget { @@ -269,32 +537,23 @@ class _TrendAnalysis extends StatelessWidget { child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ - Wrap( - spacing: tokens.Spacing.xs, - children: HealthChartRange.values - .map( - (item) => ChoiceChip( - label: Text(item.label), - selected: item == range, - onSelected: (_) => onRangeChanged(item), - ), - ) - .toList(), + KynosSegmentedControl( + segments: HealthChartRange.values, + selected: range, + onChanged: onRangeChanged, + labelBuilder: (value) => value.label, ), const Gap(tokens.Spacing.sm), - DropdownButton( - value: metric, - isExpanded: true, - underline: const SizedBox.shrink(), - onChanged: (value) { - if (value != null) onMetricChanged(value); - }, - items: HealthChartMetric.values - .map( - (item) => - DropdownMenuItem(value: item, child: Text(item.label)), - ) - .toList(), + KynosSegmentedControl( + segments: const [ + HealthChartMetric.recovery, + HealthChartMetric.distance, + HealthChartMetric.sleep, + HealthChartMetric.restingPulse, + ], + selected: metric, + onChanged: onMetricChanged, + labelBuilder: (value) => value.label, ), const Gap(tokens.Spacing.sm), SizedBox( diff --git a/lib/shared/providers/dashboard_summary_provider.dart b/lib/shared/providers/dashboard_summary_provider.dart new file mode 100644 index 0000000..99484cf --- /dev/null +++ b/lib/shared/providers/dashboard_summary_provider.dart @@ -0,0 +1 @@ +export 'package:kynos/features/dashboard/providers/dashboard_summary_provider.dart'; diff --git a/lib/features/dashboard/presentation/widgets/daily_quest_teaser.dart b/lib/shared/widgets/daily_quest_teaser.dart similarity index 100% rename from lib/features/dashboard/presentation/widgets/daily_quest_teaser.dart rename to lib/shared/widgets/daily_quest_teaser.dart diff --git a/lib/shared/widgets/kynos_collapsible_section.dart b/lib/shared/widgets/kynos_collapsible_section.dart new file mode 100644 index 0000000..8be2dd3 --- /dev/null +++ b/lib/shared/widgets/kynos_collapsible_section.dart @@ -0,0 +1,105 @@ +import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; +import 'package:gap/gap.dart'; +import 'package:kynos/core/theme/theme.dart'; +import 'package:kynos/shared/widgets/kynos_card.dart'; + +/// Expandable section for progressive disclosure on long scroll surfaces. +class KynosCollapsibleSection extends StatefulWidget { + const KynosCollapsibleSection({ + super.key, + required this.title, + required this.child, + this.initiallyExpanded = false, + this.subtitle, + }); + + final String title; + final String? subtitle; + final Widget child; + final bool initiallyExpanded; + + @override + State createState() => + _KynosCollapsibleSectionState(); +} + +class _KynosCollapsibleSectionState extends State { + late bool _expanded = widget.initiallyExpanded; + + @override + Widget build(BuildContext context) { + final kynos = context.kynosTheme; + + return KynosCard( + padding: EdgeInsets.zero, + child: Column( + crossAxisAlignment: CrossAxisAlignment.stretch, + children: [ + InkWell( + onTap: () { + HapticFeedback.selectionClick(); + setState(() => _expanded = !_expanded); + }, + borderRadius: BorderRadius.circular(Radius.lg), + child: Padding( + padding: const EdgeInsets.all(Spacing.md), + child: Row( + children: [ + Expanded( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + widget.title.toUpperCase(), + style: Theme.of(context).textTheme.labelSmall?.copyWith( + color: kynos.tertiaryLabel, + letterSpacing: 0.6, + ), + ), + if (widget.subtitle != null) ...[ + const Gap(Spacing.xs), + Text( + widget.subtitle!, + style: Theme.of(context).textTheme.bodySmall?.copyWith( + color: kynos.secondaryLabel, + ), + ), + ], + ], + ), + ), + AnimatedRotation( + turns: _expanded ? 0.5 : 0, + duration: Motion.fast, + curve: Motion.curve, + child: Icon( + Icons.keyboard_arrow_down_rounded, + color: kynos.secondaryLabel, + ), + ), + ], + ), + ), + ), + AnimatedCrossFade( + firstChild: const SizedBox.shrink(), + secondChild: Padding( + padding: const EdgeInsets.fromLTRB( + Spacing.md, + 0, + Spacing.md, + Spacing.md, + ), + child: widget.child, + ), + crossFadeState: _expanded + ? CrossFadeState.showSecond + : CrossFadeState.showFirst, + duration: Motion.fast, + ), + ], + ), + ); + } +} diff --git a/lib/shared/widgets/kynos_nav_rail.dart b/lib/shared/widgets/kynos_nav_rail.dart new file mode 100644 index 0000000..dd902f3 --- /dev/null +++ b/lib/shared/widgets/kynos_nav_rail.dart @@ -0,0 +1,143 @@ +import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; +import 'package:gap/gap.dart'; +import 'package:kynos/core/theme/kynos_theme_extension.dart'; +import 'package:kynos/core/theme/layout.dart'; +import 'package:kynos/core/theme/liquid_glass_tokens.dart'; +import 'package:kynos/core/theme/motion.dart'; +import 'package:kynos/core/theme/spacing.dart' as tokens; +import 'package:kynos/shared/widgets/liquid_glass_surface.dart'; +import 'package:kynos/shared/widgets/nav_icon.dart'; + +/// Configuration for a single destination in [KynosNavRail]. +@immutable +class KynosNavRailItem { + const KynosNavRailItem({required this.label, required this.icon}); + + final String label; + final NavIconDefinition icon; +} + +/// Left-edge Liquid Glass navigation rail — icon-forward, coach-first layout. +class KynosNavRail extends StatelessWidget { + const KynosNavRail({ + super.key, + required this.items, + required this.selectedIndex, + required this.onSelected, + }); + + final List items; + final int selectedIndex; + final ValueChanged onSelected; + + void _handleTap(int index) { + if (index == selectedIndex) return; + HapticFeedback.selectionClick(); + onSelected(index); + } + + @override + Widget build(BuildContext context) { + final kynos = context.kynosTheme; + + return RepaintBoundary( + child: SafeArea( + right: false, + child: SizedBox( + width: LayoutTokens.shellRailWidth, + child: Padding( + padding: const EdgeInsets.symmetric( + vertical: tokens.Spacing.md, + horizontal: tokens.Spacing.xs, + ), + child: LiquidGlassSurface( + borderRadius: tokens.Radius.xl, + blurSigma: LiquidGlassTokens.navBlurSigma, + padding: const EdgeInsets.symmetric(vertical: tokens.Spacing.sm), + child: Column( + mainAxisSize: MainAxisSize.min, + children: [ + for (var i = 0; i < items.length; i++) ...[ + if (i > 0) const Gap(tokens.Spacing.xs), + _RailItem( + icon: items[i].icon, + label: items[i].label, + selected: selectedIndex == i, + onTap: () => _handleTap(i), + accent: kynos.purple, + unselected: kynos.navUnselected, + ), + ], + ], + ), + ), + ), + ), + ), + ); + } +} + +class _RailItem extends StatelessWidget { + const _RailItem({ + required this.icon, + required this.label, + required this.selected, + required this.onTap, + required this.accent, + required this.unselected, + }); + + final NavIconDefinition icon; + final String label; + final bool selected; + final VoidCallback onTap; + final Color accent; + final Color unselected; + + @override + Widget build(BuildContext context) { + final color = selected ? accent : unselected; + + return Semantics( + button: true, + selected: selected, + label: label, + child: Tooltip( + message: label, + waitDuration: const Duration(milliseconds: 400), + child: GestureDetector( + onTap: onTap, + behavior: HitTestBehavior.opaque, + child: AnimatedContainer( + duration: Motion.navItem, + curve: Motion.curve, + width: 44, + height: 44, + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(tokens.Radius.lg), + color: selected ? accent.withValues(alpha: 0.14) : Colors.transparent, + ), + child: Center( + child: AnimatedScale( + scale: selected ? 1.06 : 1.0, + duration: Motion.navItem, + curve: Motion.curve, + child: CustomPaint( + size: const Size(24, 24), + painter: NavIconPainter( + pathData: selected ? icon.filled : icon.outline, + color: color, + strokeWidth: 2.0, + filled: selected, + ), + ), + ), + ), + ), + ), + ), + ); + } +} diff --git a/lib/shared/widgets/kynos_page_header.dart b/lib/shared/widgets/kynos_page_header.dart new file mode 100644 index 0000000..01ee16f --- /dev/null +++ b/lib/shared/widgets/kynos_page_header.dart @@ -0,0 +1,114 @@ +import 'package:flutter/material.dart'; +import 'package:gap/gap.dart'; +import 'package:go_router/go_router.dart'; +import 'package:kynos/app/router.dart'; +import 'package:kynos/core/theme/theme.dart'; +import 'package:kynos/shared/utils/date_label.dart'; +import 'package:kynos/shared/widgets/liquid_glass_button.dart'; + +/// Apple Health–style large-title page header sliver group. +class KynosPageHeader extends StatelessWidget { + const KynosPageHeader({ + super.key, + required this.title, + this.greeting, + this.subtitle, + this.onAskCoach, + this.showSettings = true, + }); + + final String title; + final String? greeting; + final String? subtitle; + final VoidCallback? onAskCoach; + final bool showSettings; + + @override + Widget build(BuildContext context) { + final kynos = context.kynosTheme; + final theme = Theme.of(context); + + return SliverMainAxisGroup( + slivers: [ + SliverAppBar( + backgroundColor: kynos.background, + surfaceTintColor: Colors.transparent, + elevation: 0, + pinned: true, + toolbarHeight: LayoutTokens.appBarToolbarHeight, + titleSpacing: LayoutTokens.titleSpacing, + title: Text( + formatDateLabel(), + style: theme.textTheme.labelLarge?.copyWith( + color: kynos.tertiaryLabel, + letterSpacing: 0.2, + ), + ), + actions: [ + if (onAskCoach != null) + Padding( + padding: const EdgeInsets.only(right: Spacing.xs), + child: LiquidGlassButton( + label: 'Ask Coach', + icon: Icons.auto_awesome_rounded, + onPressed: onAskCoach, + ), + ), + if (showSettings) + Padding( + padding: const EdgeInsets.only(right: Spacing.sm), + child: LiquidGlassIconButton( + icon: Icons.settings_outlined, + onPressed: () => context.push(Routes.settings), + tooltip: 'Settings', + ), + ), + ], + ), + SliverToBoxAdapter( + child: Padding( + padding: const EdgeInsets.fromLTRB( + LayoutTokens.titleSpacing, + Spacing.sm, + LayoutTokens.titleSpacing, + Spacing.md, + ), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + if (greeting != null) ...[ + Text( + greeting!, + style: theme.textTheme.labelLarge?.copyWith( + color: kynos.secondaryLabel, + ), + ), + const Gap(Spacing.xs), + ], + Text( + title, + style: theme.textTheme.headlineLarge?.copyWith( + fontWeight: FontWeight.w700, + letterSpacing: -0.5, + height: 1.1, + ), + ), + if (subtitle != null && subtitle!.isNotEmpty) ...[ + const Gap(Spacing.sm), + Text( + subtitle!, + style: theme.textTheme.bodyMedium?.copyWith( + color: kynos.secondaryLabel, + ), + maxLines: 2, + overflow: TextOverflow.ellipsis, + ), + ], + ], + ), + ), + ), + ], + ); + } +} diff --git a/lib/shared/widgets/kynos_section_jump_bar.dart b/lib/shared/widgets/kynos_section_jump_bar.dart new file mode 100644 index 0000000..6a95cbd --- /dev/null +++ b/lib/shared/widgets/kynos_section_jump_bar.dart @@ -0,0 +1,87 @@ +import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; +import 'package:kynos/core/theme/theme.dart'; + +/// Sticky horizontal chips for jumping between sections on long scroll pages. +class KynosSectionJumpBar extends StatelessWidget { + const KynosSectionJumpBar({ + super.key, + required this.sections, + required this.selectedIndex, + required this.onSelected, + }); + + final List sections; + final int selectedIndex; + final ValueChanged onSelected; + + @override + Widget build(BuildContext context) { + final kynos = context.kynosTheme; + + return SingleChildScrollView( + scrollDirection: Axis.horizontal, + padding: const EdgeInsets.symmetric(horizontal: Spacing.md), + child: Row( + children: [ + for (var i = 0; i < sections.length; i++) ...[ + if (i > 0) const SizedBox(width: Spacing.xs), + _JumpChip( + label: sections[i], + selected: selectedIndex == i, + accent: kynos.purple, + onTap: () { + HapticFeedback.selectionClick(); + onSelected(i); + }, + ), + ], + ], + ), + ); + } +} + +class _JumpChip extends StatelessWidget { + const _JumpChip({ + required this.label, + required this.selected, + required this.accent, + required this.onTap, + }); + + final String label; + final bool selected; + final Color accent; + final VoidCallback onTap; + + @override + Widget build(BuildContext context) { + final kynos = context.kynosTheme; + + return GestureDetector( + onTap: onTap, + child: AnimatedContainer( + duration: Motion.fast, + curve: Motion.curve, + padding: const EdgeInsets.symmetric( + horizontal: Spacing.md, + vertical: Spacing.sm, + ), + decoration: BoxDecoration( + color: selected + ? accent.withValues(alpha: 0.14) + : kynos.separator.withValues(alpha: 0.4), + borderRadius: BorderRadius.circular(Radius.full), + ), + child: Text( + label, + style: Theme.of(context).textTheme.labelMedium?.copyWith( + color: selected ? accent : kynos.secondaryLabel, + fontWeight: selected ? FontWeight.w600 : FontWeight.w500, + ), + ), + ), + ); + } +} diff --git a/lib/shared/widgets/kynos_segmented_control.dart b/lib/shared/widgets/kynos_segmented_control.dart new file mode 100644 index 0000000..0f1d724 --- /dev/null +++ b/lib/shared/widgets/kynos_segmented_control.dart @@ -0,0 +1,98 @@ +import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; +import 'package:gap/gap.dart'; +import 'package:kynos/core/theme/theme.dart'; + +/// Token-aligned segmented control for chart range and metric pickers. +class KynosSegmentedControl extends StatelessWidget { + const KynosSegmentedControl({ + super.key, + required this.segments, + required this.selected, + required this.onChanged, + this.labelBuilder, + }); + + final List segments; + final T selected; + final ValueChanged onChanged; + final String Function(T value)? labelBuilder; + + @override + Widget build(BuildContext context) { + final kynos = context.kynosTheme; + + return DecoratedBox( + decoration: BoxDecoration( + color: kynos.separator.withValues(alpha: 0.35), + borderRadius: BorderRadius.circular(Radius.md), + ), + child: Padding( + padding: const EdgeInsets.all(Spacing.xs), + child: Row( + children: [ + for (var i = 0; i < segments.length; i++) ...[ + if (i > 0) const Gap(Spacing.xs), + Expanded( + child: _Segment( + label: labelBuilder?.call(segments[i]) ?? segments[i].toString(), + selected: segments[i] == selected, + onTap: () { + if (segments[i] == selected) return; + HapticFeedback.selectionClick(); + onChanged(segments[i]); + }, + ), + ), + ], + ], + ), + ), + ); + } +} + +class _Segment extends StatelessWidget { + const _Segment({ + required this.label, + required this.selected, + required this.onTap, + }); + + final String label; + final bool selected; + final VoidCallback onTap; + + @override + Widget build(BuildContext context) { + final kynos = context.kynosTheme; + + return Semantics( + button: true, + selected: selected, + label: label, + child: GestureDetector( + onTap: onTap, + behavior: HitTestBehavior.opaque, + child: AnimatedContainer( + duration: Motion.fast, + curve: Motion.curve, + padding: const EdgeInsets.symmetric(vertical: Spacing.sm), + decoration: BoxDecoration( + color: selected ? kynos.card : Colors.transparent, + borderRadius: BorderRadius.circular(Radius.sm), + boxShadow: selected ? kynos.cardShadow : null, + ), + alignment: Alignment.center, + child: Text( + label, + style: Theme.of(context).textTheme.labelMedium?.copyWith( + color: selected ? kynos.label : kynos.secondaryLabel, + fontWeight: selected ? FontWeight.w600 : FontWeight.w500, + ), + ), + ), + ), + ); + } +} diff --git a/lib/shared/widgets/widgets.dart b/lib/shared/widgets/widgets.dart index 03433a2..312142c 100644 --- a/lib/shared/widgets/widgets.dart +++ b/lib/shared/widgets/widgets.dart @@ -4,17 +4,23 @@ library; export 'animated_async_content.dart'; export 'animated_progress_bar.dart'; export 'charts/health_trend_chart.dart'; +export 'daily_quest_teaser.dart'; export 'glass_card.dart'; export 'kynos_bottom_nav.dart'; export 'kynos_card.dart'; export 'kynos_chip.dart'; +export 'kynos_collapsible_section.dart'; export 'kynos_hero_banner.dart'; export 'kynos_inline_error_card.dart'; export 'kynos_loading_line.dart'; +export 'kynos_nav_rail.dart'; export 'kynos_page_dots.dart'; +export 'kynos_page_header.dart'; export 'kynos_privacy_footer.dart'; export 'kynos_section_header.dart'; +export 'kynos_section_jump_bar.dart'; export 'kynos_section_row.dart'; +export 'kynos_segmented_control.dart'; export 'kynos_skeleton.dart'; export 'kynos_user_bubble.dart'; export 'liquid_glass_button.dart'; diff --git a/test/features/training/training_page_test.dart b/test/features/training/training_page_test.dart index 631dc09..396f5d9 100644 --- a/test/features/training/training_page_test.dart +++ b/test/features/training/training_page_test.dart @@ -4,13 +4,14 @@ import 'package:flutter_test/flutter_test.dart'; import 'package:kynos/features/training/presentation/pages/training_page.dart'; void main() { - testWidgets('TrainingPage renders hero banner', (tester) async { + testWidgets('TrainingPage renders health hub header', (tester) async { await tester.pumpWidget( const ProviderScope(child: MaterialApp(home: TrainingPage())), ); await tester.pump(); - expect(find.text('HEALTH'), findsOneWidget); + expect(find.text('Health'), findsOneWidget); + expect(find.text('Today'), findsOneWidget); }); } diff --git a/test/shared/widgets/kynos_nav_rail_test.dart b/test/shared/widgets/kynos_nav_rail_test.dart new file mode 100644 index 0000000..9ee1005 --- /dev/null +++ b/test/shared/widgets/kynos_nav_rail_test.dart @@ -0,0 +1,53 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:kynos/shared/widgets/kynos_nav_rail.dart'; +import 'package:kynos/shared/widgets/nav_icon.dart'; + +void main() { + const items = [ + KynosNavRailItem(label: 'Coach', icon: NavIconPaths.coach), + KynosNavRailItem(label: 'Health', icon: NavIconPaths.training), + KynosNavRailItem(label: 'Journey', icon: NavIconPaths.character), + ]; + + group('KynosNavRail', () { + testWidgets('renders all rail items', (tester) async { + await tester.pumpWidget( + MaterialApp( + home: Scaffold( + body: KynosNavRail( + items: items, + selectedIndex: 0, + onSelected: (_) {}, + ), + ), + ), + ); + + expect(find.byType(KynosNavRail), findsOneWidget); + expect(find.byTooltip('Coach'), findsOneWidget); + expect(find.byTooltip('Health'), findsOneWidget); + expect(find.byTooltip('Journey'), findsOneWidget); + }); + + testWidgets('calls onSelected when tapping a different item', (tester) async { + var selected = 0; + await tester.pumpWidget( + MaterialApp( + home: Scaffold( + body: KynosNavRail( + items: items, + selectedIndex: selected, + onSelected: (index) => selected = index, + ), + ), + ), + ); + + await tester.tap(find.byTooltip('Health')); + await tester.pump(); + + expect(selected, 1); + }); + }); +} diff --git a/test/widget_test.dart b/test/widget_test.dart index 99ac11a..357a330 100644 --- a/test/widget_test.dart +++ b/test/widget_test.dart @@ -73,8 +73,8 @@ void main() { expect(tester.getSize(find.byType(EditableText)).height, greaterThan(20)); expect(find.byType(EditableText).hitTestable(), findsOneWidget); expect(tester.takeException(), isNull); - expect(find.text('Coach'), findsOneWidget); - expect(find.text('Health'), findsOneWidget); - expect(find.text('Journey'), findsOneWidget); + expect(find.byTooltip('Coach'), findsOneWidget); + expect(find.byTooltip('Health'), findsOneWidget); + expect(find.byTooltip('Journey'), findsOneWidget); }); }