🌱
CultivaFit
Flutter — Enrutamiento Declarativo con go_router · Deep Linking iOS & Android
Flutter ^3.22 · go_router ^14.0.0 CULTIVA IA · flutter-enrutamiento-declarativo
Árbol de Rutas — GoRouter Configuration
GoRouter
initialLocation: /home  ·  domain: cultivafit.app  ·  redirect: → /onboarding si no auth
Rutas independientes (fuera del Shell)
/onboarding OnboardingScreen · Acceso sin auth
* (error) ErrorScreen · Ruta no encontrada
↓ StatefulShellRoute.indexedStack ↓
0
🏠
Inicio
/home
HomeScreen
Dashboard · resumen diario IA
1
💪
Entrena
/workouts
WorkoutsScreen
/workouts/:id
WorkoutDetailScreen
?week=N (query param)
2
🥗
Nutrición
/nutrition
NutritionScreen
/nutrition/:id
NutritionDetailScreen
3
👤
Perfil
/profile
ProfileScreen
Stats · Ajustes · Logout
Implementación — GoRouter Core
main.dart
router.dart
shell_widget.dart
// cultivafit/lib/main.dart import 'package:flutter/material.dart'; import 'package:go_router/go_router.dart'; import 'package:flutter_web_plugins/url_strategy.dart'; void main() { usePathUrlStrategy(); // Elimina '#' en URLs web → cultivafit.app/workouts/123 runApp(const CultivaFitApp()); } final GoRouter _router = GoRouter( initialLocation: '/home', debugLogDiagnostics: true, redirect: (context, state) { final isAuth = authState.isAuthenticated; if (!isAuth && state.matchedLocation != '/onboarding') return '/onboarding'; if (isAuth && state.matchedLocation == '/onboarding') return '/home'; return null; }, refreshListenable: authState, // Refresca rutas al cambiar auth routes: [ GoRoute(path: '/onboarding', builder: OnboardingScreen), StatefulShellRoute.indexedStack( builder: (ctx, state, shell) => CultivaFitShell(shell: shell), branches: [ StatefulShellBranch(routes: [GoRoute(path: '/home', ...),]), StatefulShellBranch(routes: [GoRoute(path: '/workouts', routes: [GoRoute(path: ':id', ...)], )]), StatefulShellBranch(routes: [GoRoute(path: '/nutrition', routes: [GoRoute(path: ':id', ...)], )]), StatefulShellBranch(routes: [GoRoute(path: '/profile', ...),]), ], ), ], errorBuilder: (ctx, state) => ErrorScreen(error: state.error), );
Checklist de Implementación — CultivaFit
Configuración base
Flutter create + flutter pub add go_router
usePathUrlStrategy() en main()
GoRouter con initialLocation: '/home'
MaterialApp.router con routerConfig: _router
AuthState como refreshListenable
Navegación anidada
StatefulShellRoute.indexedStack configurado
4 StatefulShellBranch (Home/Workouts/Nutrición/Perfil)
ScaffoldWithNavBar con NavigationBar Material 3
Sub-rutas :id en workouts y nutrition
Deep Linking iOS
FlutterDeepLinkingEnabled: true en Info.plist
applinks:cultivafit.app en entitlements
AASA publicado con CULTV5.com.cultivaia.cultivafit
Validado con xcrun simctl openurl
Deep Linking Android
Intent filter con autoVerify="true" en Manifest
assetlinks.json con SHA-256 del keystore
Validado con adb shell am start
Package com.cultivaia.cultivafit verificado