no_context_navigation
3.0.0, released 3 years ago by an unverified publisher
Navigate without BuildContext using a global NavigatorKey
WASM-ready
What it does
Provides a NavigationService that uses a global NavigatorState to push, replace, and pop routes without needing a BuildContext. It wraps Navigator methods in a simple API.
AI-written summary of version 3.0.0, based on the package's README and metadata. Report an inaccuracy
Use it when
- You need context‑free navigation in a small or medium app
- You want a quick, minimal setup without learning a new routing library
- You prefer imperative navigation calls over declarative routing
Skip it when
- You require deep linking, nested routes, or complex route management
- You are already using a declarative router like go_router or auto_route
- You need advanced navigation features such as route guards or transition animations
Strengths
- Simple API, no context required
- Null safety compliant
- Easy to add to existing projects
Weaknesses
- Limited to basic navigation, no deep linking or nested routes
- No declarative routing or route configuration
- Relies on a global key which can be problematic in tests
Setup
- Kind
- Flutter widgets
- Effort
- Low
- Code generation
- No
- Direct dependencies
- 0
Add navigatorKey to MaterialApp and create a NavigationService instance. No build_runner or permissions needed.
final navService = NavigationService();
MaterialApp(
navigatorKey: NavigationService.navigationKey,
onGenerateRoute: (settings) => MaterialPageRoute(
builder: (_) => settings.name == '/detail' ? DetailScreen() : HomeScreen(),
),
);
// Navigate
navService.pushNamed('/detail', args: 'From Home');Alternatives
Packages that do the same job and could replace no_context_navigation.