简体   繁体   English

如何以编程方式从Bloc更改Flutter中的步进器?

[英]How to programatically change Stepper in Flutter from Bloc?

I'm using flutter_bloc and I'm trying to work out how to change the current step in a Stepper while conforming to the Bloc pattern. 我正在使用flutter_bloc,并且试图找出如何在符合Bloc模式的同时更改步进器中的当前步骤。 I have only been successful using setState() but this feels like the wrong thing to do when using Bloc. 我仅成功使用setState(),但这在使用Bloc时感觉做错了。

Essentially I have two forms in two steps, which take place in a stepper. 从本质上讲,我在两个步骤中有两种形式,它们是在步进器中进行的。 I would want the details from the first step (two textboxes) to be validated as per certain rules, and then the "current step" in the Stepper to be changed accordingly. 我希望按照某些规则验证第一步(两个文本框)中的详细信息,然后相应地更改步进器中的“当前步骤”。 I have set up a listener on the page that contains the stepper, and it is recieving events okay, but changing the active step isn't rebuilding the widget tree. 我已经在包含步进器的页面上设置了一个侦听器,它可以正常接收事件,但是更改活动步骤并不能重建小部件树。 I'm a bit stuck :( Any help would be great. 我有点卡住了:(任何帮助都会很棒。

Edit: I can change the currentstep in the view layer (as in the integer where the currentStep is stored) but the visuals on the Stepper are not updated. 编辑:我可以在视图层中更改currentstep(就像在其中存储currentStep的整数一样),但是不会更新Stepper上的视觉效果。 They are updated if I call setState (but it feels like this is the wrong thing to do in Bloc). 如果我调用setState,它们将被更新(但感觉这是在Bloc中做错的事情)。

您可以查看此要点 ,以获取有关如何在flutter_bloc中使用步进器的示例

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

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