type 'BehaviorSubject<dynamic>' is not a subtype of type 'Stream<String>' of 'stream'


I have this weird error I’m getting and I can’t seem to fix this. I am implementing the bloc pattern in my login page. I can’t seem to point out what I am doing wrong. Here is my code


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

class LoginBloc extends Object with Validators {
  final _emailController = BehaviorSubject<dynamic>();
  final _passwordController = BehaviorSubject<dynamic>();

  Function(String) get emailChanged => _emailController.sink.add;
  Function(String) get passwordChanged => _passwordController.sink.add;

  Stream<String> get emailValidator => _emailController.stream.transform(emailValidators);
  Stream<String> get passwordValidator =>  _passwordController.stream.transform(passwordValidators);

  Stream<bool> get submitCheck => Rx.combineLatest2(emailValidator, passwordValidator, (e, p) => true);

  dispose() {

mixin Validators {
  var emailValidators =
  StreamTransformer<String, String>.fromHandlers(handleData: (email, sink) {
   if (email.contains("@")) {
   } else {
     sink.addError("Email is not valid");

  var passwordValidators = StreamTransformer<String, String>.fromHandlers(
     handleData: (password, sink) {
    if (password.length > 0) {
    } else {
      sink.addError("Password Field should not be empty");

final loginBloc = LoginBloc();

here is the widget i created calling the bloc

  Widget _emailPasswordWidget() {
return Column(
  children: <Widget>[
  margin: EdgeInsets.symmetric(vertical: 10),
  child: Column(
    crossAxisAlignment: CrossAxisAlignment.start,
    children: <Widget>[
        'Email ID',
        style: TextStyle(fontWeight: FontWeight.bold, fontSize: 15),
        height: 10,
        stream: loginBloc.emailValidator,
        builder: (context, snapshot) {
          return TextField(
              onChanged: loginBloc.emailChanged,
              obscureText: false,
              decoration: InputDecoration(
                  errorText: snapshot.error,
                  border: InputBorder.none,
                  fillColor: Color(0xfff3f3f4),
                  filled: true));

I would appreciate any help whatsoever. I have checked online and I have not seen any help. I am using rxdart version ^0.23.1. I have used a streamcontroller instead of the behaviour subject and I have used a publishsubject too and i still get the error.


there is no need for the BehaviorSubject to be of type dynamic when everything going through will be Strings, so the best fix is to type it like so :


Answered By – Benoit Jadinon

Answer Checked By – Dawn Plyler (FlutterFixes Volunteer)

Leave a Reply

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