Build Context Holder for Flutter Pub version

A flutter build context holder, init once, use everywhere.

1. Add dependency

dependencies:
  context_holder: ^0.0.4

2. Import context holder

import 'package:context_holder/context_holder.dart';

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(),
    ),
  );
}

For CupertinoApp

void main() {
  runApp(
    CupertinoApp(
      /// must set the navigatorKey!!!!!!
      navigatorKey: ContextHolder.key,
      home: Scaffold(),
    ),
  );
}

4. Now you can use it everywhere!

Get the current build context.

ContextHolder.currentContext

Get the current state.

ContextHolder.currentState

Get the current widget.

ContextHolder.currentWidget

Get the current overlay.

ContextHolder.currentOverlay

Libraries

context_holder