0 purchases
context holder
Build Context Holder for Flutter #
A flutter build context holder, init once, use everywhere.
1. Add dependency #
dependencies:
context_holder: ^0.0.5
copied to clipboard
2. Import context holder #
import 'package:context_holder/context_holder.dart';
copied to clipboard
3. Init context holder #
Set your root app's navigatorKey with ContextHolder.key
For MaterialApp
void main() {
runApp(
MaterialApp(
/// must set the navigatorKey!!!!!!
navigatorKey: ContextHolder.key,
home: Scaffold(),
),
);
}
copied to clipboard
For CupertinoApp
void main() {
runApp(
CupertinoApp(
/// must set the navigatorKey!!!!!!
navigatorKey: ContextHolder.key,
home: Scaffold(),
),
);
}
copied to clipboard
4. Now you can use it everywhere! #
Get the current build context.
ContextHolder.currentContext
copied to clipboard
Get the current state.
ContextHolder.currentState
copied to clipboard
Get the current widget.
ContextHolder.currentWidget
copied to clipboard
Get the current overlay.
ContextHolder.currentOverlay
copied to clipboard
For personal and professional use. You cannot resell or redistribute these repositories in their original state.
There are no reviews.