39

I just upgraded to rxdart 0.23.1 and suddenly I am getting errors wherever I have used the Observable class. I have read about the breaking changes in the documentation and it has specified to use the rxdart_codemod package which I have integrated in my pubspec.yaml file and running the following command pub global activate rxdart_codemod throws the -bash: pub: command not found error. I have installed flutter properly and flutter doctor also seems to be running fine. Is there some other class that have replace Observable, couldn't find anything about it in the docs. Of course I can replace the Observable with the Stream from Dart language but really interested to know what path does the rxdart package takes as it specifies it is taking advantage of the dart extension.Using methods like combineLatest2 is not possible with Dart's Stream so it won't be a good choice for replacement?

BraveEvidence
  • 53
  • 11
  • 45
  • 119

7 Answers7

82

The Observable can be replaced by Stream as I mentioned in the question but if you are using methods like combineLatest2 from Observable, then just replace Observable by abstract class Rx so you can use Rx.combineLatest2

BraveEvidence
  • 53
  • 11
  • 45
  • 119
43

Rxdart no longer needs a custom class to work.

It now relies on extension methods, which is a recent Dart feature (Dart 2.6) to implement all of the Observable features directly on Stream.

You can safely replace all your Observable by Stream.

Rémi Rousselet
  • 256,336
  • 79
  • 519
  • 432
17

Use Rx.combineLatest2 rather than Observable.combineLatest2

Observable no longer work!

TuGordoBello
  • 4,350
  • 9
  • 52
  • 78
goodBot
  • 231
  • 3
  • 3
6

You can use

flutter pub global activate rxdart_codemod 

instead of pub global activate rxdart_codemod.

Another option is to replace your Observable by Stream.

Kartik Shandilya
  • 3,796
  • 5
  • 24
  • 42
4

rxdart document changelog 0.23.0 :

ValueObservable -> ValueStream
ReplayObservable -> ReplayStream
ConnectableObservable -> ConnectableStream
ValueConnectableObservable -> ValueConnectableStream
ReplayConnectableObservable -> ReplayConnectableStream
ifredom
  • 979
  • 9
  • 6
2

Rxdart now implements it in RX.combineLatest2

2

In rxdart 0.26.0 I'm using CombineLatestStream<T, R> class with combine2<A, B, R> method:

import 'dart:async';
import 'validators.dart';
import 'package:rxdart/rxdart.dart';

class Bloc extends Validators {
  final _email = StreamController<String>.broadcast();
  final _password = StreamController<String>.broadcast();

  Stream<String> get email => _email.stream.transform(validateEmail);
  Stream<String> get password => _password.stream.transform(validatePassword);
  Stream<bool> get submitValid => CombineLatestStream.combine2(email, password, (email, password) => true);

  Function(String) get changeEmail => _email.sink.add;
  Function(String) get changePassword => _password.sink.add;

  dispose() {
    _email.close();
    _password.close();
  }
}
JDKot
  • 6,643
  • 2
  • 10
  • 12