home / skills / hoangnguyen0403 / agent-skills-standard / getx-navigation
This skill helps you implement decoupled navigation with GetX, using named routes, bindings, and middleware for robust Flutter apps.
npx playbooks add skill hoangnguyen0403/agent-skills-standard --skill getx-navigationReview the files below or copy the command above to add this skill to your agents.
---
name: Flutter GetX Navigation
description: Context-less navigation, named routes, and middleware using GetX.
metadata:
labels: [navigation, getx, routing, middleware]
triggers:
files: ['**/app_pages.dart', '**/app_routes.dart']
keywords: [GetPage, Get.to, Get.off, Get.offAll, Get.toNamed, GetMiddleware]
---
# GetX Navigation
## **Priority: P0 (CRITICAL)**
Decoupled navigation system allowing UI transitions without `BuildContext`.
## Guidelines
- **Named Routes**: Use `Get.toNamed('/path')`. Define routes in `AppPages`.
- **Navigation APIs**:
- `Get.to()`: Push new route.
- `Get.off()`: Replace current route.
- `Get.offAll()`: Clear stack and push.
- `Get.back()`: Pop route/dialog/bottomSheet.
- **Bindings**: Link routes with `Bindings` for automated lifecycle.
- **Middleware**: Implement `GetMiddleware` for Auth/Permission guards.
## Code Example
```dart
static final routes = [
GetPage(
name: _Paths.HOME,
page: () => HomeView(),
binding: HomeBinding(),
middlewares: [AuthMiddleware()],
),
];
// Usage in Controller
void logout() => Get.offAllNamed(Routes.LOGIN);
```
## Anti-Patterns
- **Navigator Context**: Do not use `Navigator.of(context)` with GetX.
- **Hardcoded Routes**: Use a `Routes` constant class.
- **Direct Dialogs**: Use `Get.dialog()` and `Get.snackbar()`.
## References
- [AppPages Config](references/app-pages.md)
- [Middleware Implementation](references/middleware-example.md)
## Related Topics
getx-state-management | feature-based-clean-architecture
This skill documents context-less navigation, named routes, and middleware patterns using GetX for Flutter. It focuses on decoupling navigation from BuildContext, using named routes, bindings for lifecycle management, and middleware for guards like authentication. The guidance emphasizes safe, consistent routing and common anti-patterns to avoid.
The skill explains how to register GetPage routes in a central AppPages/Routes file and navigate via Get.toNamed, Get.off, Get.offAll, and Get.back without passing BuildContext. It shows how to attach Bindings to routes so controllers and services are instantiated and disposed automatically. It also covers GetMiddleware implementations for route guards and permission checks that run before navigation.
How do I perform navigation without BuildContext?
Use Get.toNamed, Get.offNamed, Get.offAllNamed, and Get.back from controllers or services; GetX provides global access without BuildContext.
Where should I register route bindings and middleware?
Register Bindings and middleware on each GetPage within your centralized AppPages/Routes configuration so lifecycle and guards run automatically when navigating.