I am migrating to GetX to Bloc, in GetController
we don t need BuildContext
to call controller, so is there any way to Provide the Context to the bloc class from BlocProvider
and we get bloc without providing buildContext like for example:
BlocProvider(
create: (context) => TestBloc(context),
),
class TestBloc extends Bloc<TestEvent, TestState> {
final BuildContext context;
TestBloc(this.context) : super(const TestInitial(false)) {
on<TestEvent1>((event, emit) {});
}
static TestBloc bloc() => BlocProvider.of<TestBloc>(context); //<--- Instance members can t be accessed from a static method.
// I want to access bloc without BuildContext
}
呼吁集团
final testBloc = TestBloc.bloc();
I need this because i want to navigate the user from notification tap and there we don t have
BuildContext