I am new to Flutter and using Block for state management. I have two screens
- RegistrationScreen
- VerifyScreen
In 'RegistrationScreen' I have added my BlockConsumer as below
child: Center(
child: Column(
children: [
BlocConsumer<RegistrationCubit, RegistrationState>(
builder: (context, state) {
return state.maybeWhen(null,
setUpRegistration: () =>
createRegistrationForm(context),
orElse: () {
return createRegistrationForm(context);
});
},
listener: (context, state) {
state.maybeWhen(null,
registrationInProgress: () => {
showLoader(true),
},
registrationResponseReceived: (response) =>
requestForOTPOnSuccess(context, response),
registrationFailedGeneric: () =>
registrationFailureGeneric(
context,
"Error in registration",
"Something went wrong"),
orElse: () {});
},
),
],
),
),
Once we receive success from service we push to 'VerifyScreen' from 'RegistrationScreen'
And in 'VerifyScreen' I am trying to reuse RegistrationCubit in a BlockListner as below (Call Registration service again on a button click)
BlocListener<RegistrationCubit, RegistrationState>(
listener: (context, st) {
st.maybeWhen(null,
registrationInProgress: () => {
showLoader(true),
},
registrationResponseReceived: (_) => showGenericAlert(
context,
'My App',
'Code sent mobile number.'),
registrationFailedGeneric: () => showGenericAlert(context,
'Error', 'An error occurred. Please try again later.'),
orElse: () {});
},
child: Container(),
)
But instead of calling 'VerifyScreen' BlocListener, 'RegistrationScreen' listeners are being called.
Could you please guide why 'RegistrationScreen' listeners are being called from 'VerifyScreen'?