title: Dart: Listeners on stream never trigger onError function
body: <p>I am building a flutter app and using Bloc. I am adding a <code>sink.addError('some error text')</code> on a stream's sink. </p>
  
  <p>In the Bloc, i have added a listener to the stream, which has functions like <code>onDone</code>, <code>onError</code>, and the <code>data</code>. Now what happens is, everything that i add in a sink, even <code>sink.addError</code> is classified as data, and not error. I want to figure out, how to differentiate the data added in sink, and the errors added in sink.addError. </p>
  
  <p>Initially i thought <code>onError(error){}</code>, is not getting called. Is it that, the <code>sink.addError('some error text')</code> is also considered data in stream. If it is, then i need a way to differentiate data, and error data. Here is some code, to help you get the gist of my question:
  </p>
  
  <pre class="lang-dart prettyprint-override"><code>class Bloc extends Object with Validators { 
    final _controller;   
    final DataBloc dataBloc;
  
    BlocTextField({ this.dataBloc}) : _controller = initMethod(dataBloc);
  
    //TODO: Issue with Stream.listen where onError is never called   
    static BehaviorSubject&lt;dynamic&gt; initMethod(DataBloc dataBloc) {
      final _controller = new BehaviorSubject&lt;dynamic&gt;();
  
      _controller.stream.listen((data) {
        print("Data in "+ data);
      }, onError: (error) {
        print("Error in "+ error);
      });
  
      return _controller;
    }
  
    //To change data to our Stream using Sink.   
    Function(dynamic) get changeField=&gt; _controller.sink.add;
  
    //To add field data from Stream.   
    textFieldStream =&gt; _controller.stream.transform(validateField());
  
    dispose() {
       _textFieldController.close();  
    } 
  }
  </code></pre>
  
  <p>Now when i try to add data in this stream. Here is my validator
  </p>
  
  <pre class="lang-dart prettyprint-override"><code>class Validators {
    validateField() {
      return StreamTransformer&lt;dynamic, dynamic&gt;.fromHandlers(
        handleData: (FieldStream, sink) {
          sink.addError("Some error here");
      });
    }
  }
  </code></pre>
  
  <p>Console output is: <code>Data in some error here</code>. </p>
  
  <p>Here are my flutter doctor results:</p>
  
  <pre class="lang-dart prettyprint-override"><code>flutter doctor
  Doctor summary (to see all details, run flutter doctor -v):
  [✓] Flutter (Channel beta, v0.9.4, on Mac OS X 10.13.6 17G3025, locale en-US)
  [✓] Android toolchain - develop for Android devices (Android SDK 28.0.0)
  [✓] iOS toolchain - develop for iOS devices (Xcode 9.4.1)
  [✓] Android Studio (version 3.2)
  [✓] VS Code (version 1.27.2)
  [✓] Connected devices (1 available)
  
  • No issues found!
  </code></pre>
  
  <p>Please let me know, a valid solution!</p>