Skip to content

GP-Moon/context_holder

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Context Holder for Flutter Pub version

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

1. Add dependency

dependencies:
  context_holder: ^0.0.5

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

About

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

Resources

License

Stars

Watchers

Forks

Packages

No packages published