Flutter – using rxDart BehaviorSubject with Observable for global state management


I am just trying the BehaviorSubject example code from here

installed rxdart and observable from pub.dev, but this line errs

Observable get stream$ => _counter.stream;

error: A value of type ‘ValueStream’ can’t be returned from function ‘stream$’ because it has a return type of ‘Observable’. (return_of_invalid_type at lib\models\globals.dart:54)


I guess that Observable class is deprecated since Dart 2.7 in which extension methods are introduced, so you have to use the normal Stream class and import RxDart plugin to get the different capabilities that RxDart offers. In case you want to combine two streams or more you can use Rx class. I also encourage you to use flutter_bloc plugin which deals with InheritedWidget, StreamBuilder, and Streams in a great way.

Answered By – Yusuf Abdelaziz

Answer Checked By – Senaida (FlutterFixes Volunteer)

Leave a Reply

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