两个不同的集团导致“糟糕的状态:流已被收听”。

问题描述 投票:0回答:1

我是新来的人。我在同一个脚手架上有一个登录(和集团)和注册(和集团)小部件:

  @override
  Widget build(BuildContext context) {
    _init(context);
    return Scaffold(
        resizeToAvoidBottomPadding: false,
        body: SingleChildScrollView(
            child: new Container(
                height: MediaQuery.of(context).size.height,
                width: MediaQuery.of(context).size.width,
                child: PageView(
                  controller: _controller,
                  physics: new AlwaysScrollableScrollPhysics(),
                  children: <Widget>[LoginPage(), HomePage(), SignupPage()],
                  scrollDirection: Axis.horizontal,
                ))));
  }
}

登录集团:

class LoginBloc extends Validators {
  //service
  final AppStoreApplication _application;

  final BehaviorSubject<String> _email = BehaviorSubject<String>();
  final BehaviorSubject<String> _password = BehaviorSubject<String>();
  CompositeSubscription _compositeSubscription = CompositeSubscription();
  final BehaviorSubject<bool> _isShowLoading = BehaviorSubject<bool>();

  LoginBloc(this._application);

  //Add data to streams login-form
  Stream<String> get email => _email.stream.transform(validateEmail);
  Stream<String> get password => _password.stream.transform(validatePassword);
  Stream<bool> get isShowLoading => _isShowLoading.stream;
  Stream<bool> get submitValid =>
      Observable.combineLatest2(email, password, (e, p) => true);



  // Change data form-login
  Function(String) get changeEmail => _email.sink.add;
  Function(String) get changePassword => _password.sink.add;

  submit() async {
     AuthenticationBloc bloc;
    //_isShowLoading.add(true);
    final email = _email.value;
    final password = _password.value;
    _application.appStoreAPIRepository
        .login(email, password)
        .listen((User user) {
      Preferences.setToken(user.token);

      bloc.emitEvent(AuthenticationEventLogin(name: user.displayname));
      //_isShowLoading.add(false);
    });

    //_compositeSubscription.add(subscription);
  }

  void dispose() {
    _compositeSubscription?.clear();
    _isShowLoading?.close();
    _email?.close();
    _password?.close();
  }
}

Register Bloc与Login Bloc非常相似,不需要发布。

每当我刷到登录/注册然后再回到注册/登录时,它都会给我一个错误:“状态不好:已经收听了流。”

flutter rxdart bloc
1个回答
1
投票

解决了!我为登录和注册创建了两个单独的文件。它修复了问题。

© www.soinside.com 2019 - 2024. All rights reserved.