gpt4 book ai didi

flutter - 两个不同的 block 导致 "Bad state: Stream has already been listened to."

转载 作者:IT王子 更新时间:2023-10-29 07:22:30 26 4
gpt4 key购买 nike

我是新手。我在同一个脚手架上有一个登录(和 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 非常相似,不需要发布。

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

最佳答案

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

关于flutter - 两个不同的 block 导致 "Bad state: Stream has already been listened to.",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54938698/

26 4 0