简体   繁体   English

在 flutter_bloc 的 bloc 中添加事件的问题

[英]problem in adding event in the bloc in flutter_bloc

I am using Flutter_bloc package to make a phone auth in flutte, everything work good, but my question is about adding events to the bloc, for example in my application, when i click on button like this code below, the event added to my loginBloc, and everything works good, but when i press back button in android device, and then return back by using normal navigater.pushNamed, and click the button again nothing happen?我正在使用 Flutter_bloc 包在 Flutter 中进行电话身份验证,一切正常,但我的问题是关于向 bloc 添加事件,例如在我的应用程序中,当我单击下面的代码时,事件添加到我的 loginBloc ,并且一切正常,但是当我在 android 设备中按下后退按钮,然后使用普通的导航器.pushNamed 返回,然后再次单击该按钮时没有任何反应? that mean the event not added to bloc or something like this?这意味着事件没有添加到集团或类似的东西? can anybody explain this problem?有人可以解释这个问题吗? thanks in advance: this is my sample code to add event when click button:提前致谢:这是我在单击按钮时添加事件的示例代码:

 child: RaisedButton(
              onPressed: () {
                if (_formKey.currentState.validate()) {
                  loginBloc.add(LoginPressesEvent(
                      phoNo: _phoneTextController.value.text));
                }
              },

For adding an 'Event' to 'Bloc' use this code:要将“事件”添加到“Bloc”,请使用以下代码:

BlocProvider.of<'YourBlocClass'>('blocContext').add('YourEvent()'));

'blocContext' is context parameter of `listener in BlocListener' : 'blocContext' 是'listener in BlocListener' 的上下文参数:

BlocProvider(
      create: (context) => BlocClass()..add(Fetch()),
      child: BlocListener<BlocClass, BaseState>(
            listener: (listenerContext, state) {
                // listenerContext: store this parameter to Field
                // and use that everywhere in your StateClass
            },

or context parameter of 'builder in Bloc Builder`或“Bloc Builder”中的“builder”的上下文参数

BlocProvider(
      create: (context) => BlocClass()..add(Fetch()),
      child: BlocBuilder<IndexBloc, BaseState>(
            builder: (builderContext, state) {
                // builderContext: store this parameter to Field
                // and use that everywhere in your StateClass
            },

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM