skip to Main Content

I have a bloc which has global state (BlocProvider is initialised before Material App). In the onPreesed callback of a button I have a bloc listener:

BlocListener<RiskAssesmentValueCubit, RiskAssesmentValueState>(
                    bloc: riskAss
                      ..checkActualVersusCalculated(user.customerId, riskAttitudeQuestionsDetails),
                    listener: (BuildContext context, RiskAssesmentValueState state) {
                      print('Listener called');

                      if (state is RiskAssesmentValueDifferent) {
                        print('Listener called');
                      }
                    },
                  );

the bloc: param is calling the method in the cubit correctly. The states in the cubit are updating. But the listener is never triggered. I grab the bloc in the build method

@override
  Widget build(BuildContext context) {
   final RiskAssesmentValueCubit riskAss = context.read<RiskAssesmentValueCubit>();

.....
} 

I tried a builder and that is also not being triggered. I think I might not understand the bloc: param correctly. But I think I should be able to access the builder/listener.

2

Answers


  1. Make sure you are emitting RiskAssesmentValueState state from the checkActualVersusCalculated() method.

    Login or Signup to reply.
  2. Can you show your bloc file.
    I think your need to emit(RiskAssesmentValueDifferent) or other emit your need when press button.
    And note that if your func is async, your need to add await – async to your event

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search