I have defined a bloc named "AppBloc" that manage user login/logout activity of user:
class AppBloc extends Bloc<AppEvent, AppState> {
AppBloc()
: super(
const AppStateLoggedOut(
isLoading: false,
),
) {
on<AppEventGoToRegistration>((event, emit) {
emit(
const AppStateIsInRegistrationView(
isLoading: false,
),
);
});
}
}
In that AppBloc, I want to define user
variable: User user
and want to get that variable from another screen by call AppBloc().User
. But I can not do the constructor for AppBloc()
.
try: Add variable: User user
to constructor of AppBloc
UPDATE:
You can use BlocProvider.of
to get the registered bloc in the context
.
BlocProvider.of<AppBloc>(context).state