I need a reference to the current OverlayState from a service where I don't have access to the current context. I've tried to use the "trick" of getting my BuildContext from a navigator key, but while this works for dialogs and navigation, does not seem to be valid for this use case. I've tried following approaches:
Overlay.of(navigatorKey.currentContext, rootOverlay: false);
Overlay.of(navigatorKey.currentState!.context, rootOverlay: false);
Overlay.of(navigatorKey.currentState!.overlay!.context, rootOverlay: false);
And all of them return null. Same piece of code, called from a widget (Overlay.of(context)) returns a valid OverlayState. Is there any way of achieving this?