title: Listening of bloc getting called multiple times
body: <p>I have this code for listening to bloc on my screen.</p>
  <pre><code>late MyBloc myBloc;
  
  @override
    void initState() {
      print('inside init state');
      super.initState();
      myBloc = BlocProvider.of&lt;MyBloc&gt;(context);
      myBloc.stream.listen((state) {
        if (state is MyAddCompletedState) {
          print('listening to bloc');
        }
      }
  }
  </code></pre>
  <p>If I add an event, it will print <em><strong>listening to bloc</strong></em> once. If I go to another screen and return to this same screen, it will print <em><strong>listening to bloc</strong></em> twice. It seems like the first <em><strong>listen</strong></em> I did was still active. Next, I tried to <em><strong>close</strong></em> the bloc on my dispose thinking that it would stop the first <em><strong>listen</strong></em>. So that when I come back to the screen it will have a fresh <em><strong>listen</strong></em> but it will have an error: <em><strong>Bad state: Cannot add new events after calling close</strong></em>. I tried to research about this and some mention to dispose the bloc but it doesn't have that syntax anymore. Please help on how to properly close or stop it from listening once I have change screen. Thanks!</p>
  <pre><code>//this is found on my screen
  late MyBloc myBloc;
  
  @override
    void initState() {
      print('inside init state');
      super.initState();
      myBloc = BlocProvider.of&lt;MyBloc&gt;(context);
      myBloc.stream.listen((state) {
        if (state is MyAddCompletedState) {
          print('listening to bloc');
        }
      }
  }
  
    @override
    void dispose() {
      myBloc.close();
      // myBloc.dispose(); --&gt; I saw some tutorial to use this but it doesn't work
      super.dispose();
    }
  </code></pre>
  <p>This is on my main.dart:</p>
  <pre><code>    return FutureBuilder(
          future: InitFirst.instance.initialize(),
          builder: (context, AsyncSnapshot snapshot) {
            return MultiBlocProvider(
              providers: [
                BlocProvider&lt;MyBloc&gt;(
                  create: (context) =&gt; MyBloc(
                    authenticationRepository: authenticationRepository,
                    userDataRepository: userDataRepository,
                  ),
                ),
              ...
  </code></pre>
  <p>This is the part where I trigger the event. After this event run, the stream.listen will get triggered. But it will be triggered multiple times every time I visit the my screen.</p>
  <pre><code>    myBloc.add(MyAddEvent(
          selectedName,
          selectedCount);
  </code></pre>
  <p>Additional note: this event is triggering an update in Firebase which I need to check if it got completed that is why I do the <em><strong>stream.listen</strong></em>.</p>