Not disposing the stream , but resetting the counter stream value to 0 and listening to it again


I have a counter bloc and showing the counter on second page, I want to reset the counter value to 0(ZERO) on navigating back to first page or on pressing back button without disposing the stream so that I can listen to stream throughout the app.

In short whenever returning to second page the stream count should start from 0.


import 'dart:async';

class CounterBloc {
  int _counter = 0;
  StreamController<int> _countController = StreamController<int>.broadcast();

  Stream<int> get counterStream =>;
  StreamSink<int> get counterSink => _countController.sink;

  void incrementCounter() {


You need to create a new method (action) inside your Bloc.

  void resetCounter() {
    _counter = 0;

Answered By – SempaiLeo

Answer Checked By – Marie Seifert (FlutterFixes Admin)

Leave a Reply

Your email address will not be published. Required fields are marked *