flutter-getx-navigation
Context-less navigation, named routes, and middleware using GetX.
Installation
Follow the repository instructions for this skill and your agent. Review the files and dependencies before adding it to your workflow.
View source ↗GuidesSkill instructions
GetX Navigation
Priority: P0 (CRITICAL)
Decoupled navigation system allowing UI transitions without BuildContext.
Implementation Guidelines
-
Prefer Named Routes: Use
Get.toNamed('/path')for better maintainability. Define routes in a centralizedAppPagesclass. -
No Context Navigation: Leverage
Get.to(),Get.back(), etc., directly from controllers. -
Navigation Methods:
-
Get.to(): Navigate to next screen. -
Get.off(): Navigate and replace current screen (e.g., Splash -> Home). -
Get.offAll(): Clear stack and navigate (e.g., Logout -> Login). -
Get.back(): Close current screen, dialog, or bottom sheet.
-
-
Bindings Everywhere: Always link routes with
Bindingsto manage controller lifecycles. -
Middleware: Use
GetMiddlewarefor route guards (Auth, Permissions) instead of logic inside views.
Code Example
// Route Definition
static final routes = [
GetPage(
name: _Paths.HOME,
page: () => HomeView(),
binding: HomeBinding(),
middlewares: [AuthMiddleware()],
),
];
// Usage in Controller
void logout() {
_authService.clear();
Get.offAllNamed(Routes.LOGIN);
}
// Route Guard
class AuthMiddleware extends GetMiddleware {
@override
RouteSettings? redirect(String? route) {
return isAuthenticated ? null : RouteSettings(name: Routes.LOGIN);
}
}
Anti-Patterns
-
Mixing Context and GetX: Do not use
Navigator.of(context)when GetX is the primary router. -
Hardcoded Strings: Always use a
Routesconstant class for names. -
Dialogs without GetX: Use
Get.dialog()andGet.snackbar()for consistency.
Reference & Examples
For centralized route configuration and middleware guards: See references/app-pages.md and references/middleware-example.md.
Related Topics
getx-state-management | feature-based-clean-architecture
Examples
Read the usage examples in the source repository.
View source ↗Source history
- Indexed on
- 2026-01-20
- Index updated
- 2026-01-26
- Branch
- main
Index and sync dates describe this directory. View the source repository for code history.
GitHub ↗chat Comments (0)
Sign in to join the discussion and leave a comment.
No comments yet. Be the first to share your thoughts!