0

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

  @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 非常相似,不需要发布。

每当我滑动到登录/注册然后返回到注册/登录时,它都会给我一个错误:“状态不佳:流已被收听。”

4

1 回答 1

2

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

于 2019-03-01T06:23:41.273 回答