import 'dart:async'; import 'package:rxdart/rxdart.dart'; import 'package:rxdart/subjects.dart'; class DebugBloc { int _counter = 0; bool _debugScreenEnabled = false; static const debugSwitchValue = 3; final _incrementController = StreamController(); final _debugDisableController = StreamController(); final _debugEnabledStatus$ = BehaviorSubject(); DebugBloc() { print('init: Debug BLOC'); _incrementController.stream.listen((void _) { _counter = _counter + 1; print('counterBloc: debug counter = $_counter / $debugSwitchValue'); if(_counter % debugSwitchValue == 0){ _debugScreenEnabled = !_debugScreenEnabled; _debugEnabledStatus$.add(_debugScreenEnabled); _counter = 0; } }); _debugDisableController.stream.listen((void _){ if(_debugScreenEnabled){ _counter = 0; _debugScreenEnabled = false; _debugEnabledStatus$.add(_debugScreenEnabled); } }); } Sink get debugCounterIncrement => _incrementController.sink; Sink get debugDisable => _debugDisableController.sink; Stream get debugEnabledStatus$ => _debugEnabledStatus$.stream; void dispose() { _incrementController.close(); _debugDisableController.close(); _debugEnabledStatus$.close(); } }