0

I ended up non this but I do not think it is the way to go:

void doSomething(BuildContext context, MyDatadata) {
    late StreamSubscription<SomeState> subscription;
    subscription = BlocProvider.of<SomeBloc>(context, listen:false).stream.where((event) => event is SomethingLoaded).listen((event) {
      BuildContext? ctx = MyGoRoutes.router.routerDelegate.navigatorKey.currentContext;
      BlocProvider.of<OtherBloc>(ctx!).add(SomethingOtherLoaded());
      GoRouter.of(ctx!).push("/" + MyGoRoutes.SOME_PATH_CONSTANT, extra: (event as SomeEvent).data);
      subscription.cancel();
    });
    BlocProvider.of<OtherBloc>(context).add(LoadSomethingOther());
    BlocProvider.of<SomeBloc>(context).add(LoadSomething(data));
  }

Is there a better way to access the context in the StreamSubscription-Handler?

derChris
  • 726
  • 8
  • 19

0 Answers0