---
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`.

## Implementation Guidelines

- **Prefer Named Routes**: Use `Get.toNamed('/path')` for better maintainability. Define routes in a centralized `AppPages` class.
- **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 `Bindings` to manage controller lifecycles.
- **Middleware**: Use `GetMiddleware` for route guards (Auth, Permissions) instead of logic inside views.

## Code Example

```dart
// 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 `Routes` constant class for names.
- **Dialogs without GetX**: Use `Get.dialog()` and `Get.snackbar()` for consistency.

## Reference & Examples

For centralized route configuration and middleware guards:
See [references/app-pages.md](references/app-pages.md) and [references/middleware-example.md](references/middleware-example.md).

## Related Topics

getx-state-management | feature-based-clean-architecture


---
Source attribution: ngxtm
Original project: https://github.com/ngxtm/devkit/blob/9439f27ce3fa7fe53ff9278a1ee9a44bffa70eba/rules/flutter/getx-navigation/SKILL.md
License: MIT
License information: https://opensource.org/license/mit
Original upstream instructions; downloaded from Mega AI Hub.

## Upstream license notice

MIT License

Copyright (c) 2024

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.



# Mega AI Hub resource metadata

Creator / publisher: ngxtm
Original project: https://github.com/ngxtm/devkit/blob/9439f27ce3fa7fe53ff9278a1ee9a44bffa70eba/rules/flutter/getx-navigation/SKILL.md
Attribution basis: Source repository record

Fields of work: Development & Engineering
Roles: Frontend Developer, Mobile Developer
Specialties: Backend, Mobile
Tools: Getx
Country applicability: Country not specified
Classification basis: Source catalog labels
Instruction SHA-256: c9fe3dff04029ac38a3c2bf7aa9e513975381e7996f8f1103b32d214c7de50c2
