init method

void init(
  1. BuildContext context, {
  2. Widget? loaderWidget,
  3. Color? loaderBarrierColor,
})

Set the root BuildContext to this LoaderHelper singleton to be used in the app.

Optionally, a loaderWidget and a loaderBarrierColor can be passed to override the default ones.

NOTES

  • If this method is not called, than the other methods of this LoaderHelper will do nothing (without throwing errors).
  • If this method is called with a BuildContext different from the root one, calling the other methods could throw errors in debug.

To avoid errors, call init in the root widget, right after the MaterialApp or the CupertinoApp (or whatever is the App widget), in the "home" attribtue.

If you use router such as MaterialApp.router, use the BuildContext of the root Navigator widget in the RouterDelegate.

Tip

If you use the RouteManager package, you can get the root context wherever you want by calling

BuildContext? context = RouteManager.of(context).navigatorContext;

Note that it's an optional value to be null-checked before use.

Implementation

void init(BuildContext context,
    {Widget? loaderWidget, Color? loaderBarrierColor}) {
  _context = context;
  _loaderWidget = loaderWidget;
  _loaderBarrierColor = loaderBarrierColor;
}