context_holder
0.0.5, released 5 years ago by an unverified publisher
Hold BuildContext globally to access it anywhere in the app without passing it.
WASM-ready
What it does
It stores the app's BuildContext globally by attaching to the root navigatorKey. Developers can then retrieve the current context, state, widget, or overlay from anywhere without explicit parameter passing.
AI-written summary of version 0.0.5, based on the package's README and metadata. Report an inaccuracy
Use it when
- You need access to the current BuildContext in non-widget utility or service classes.
- You want to show dialogs or snackbars without passing context through multiple layers.
Skip it when
- You prefer structured dependency injection or clean state management practices.
- You are building apps where global context tracking can lead to anti-patterns or hard-to-debug lifecycle issues.
Strengths
- Extremely simple setup with a single navigatorKey assignment.
- Allows accessing context from anywhere in the codebase.
Weaknesses
- Relies on a global state approach which is generally considered an anti-pattern in Flutter.
- Can lead to using context when it might be stale or invalid.
Setup
- Kind
- Flutter widgets
- Effort
- Low
- Code generation
- No
- Direct dependencies
- 0
Assign ContextHolder.key to the navigatorKey of your MaterialApp or CupertinoApp.
MaterialApp(
navigatorKey: ContextHolder.key,
home: Scaffold(),
);Alternatives
Packages that do the same job and could replace context_holder.
- flutter_olm
Builds the native Olm library for Android and iOS to be used via dart:ffi.
40Compare