为了学习群体,我想出了这个问题.我有一些代码,在其中我生成了一些带有BLoC模式的按钮.然而,我不知道如何用dispatch(event)
方法更新特定的按钮属性.如何将参数传递给事件ChangeSomeValues
??
使用集团的部分
BlocBuilder(
bloc: myBloc,
builder: (context, state) {
return ListView.builder(
itemCount: state.buttonList.length,
itemBuilder: (context, index) {
return MyButton(
label: buttonList[index].label,
value: buttonList[index].value,
onPressed: myBloc.dispatch(ChangeSomeValues()),
);
}
);
}
),
MyBloc.飞奔
class MyBloc extends Bloc<MyEvent, MyState> {
@override
Stream<MyState> mapEventToState(MyEvent event) async* {
if (event is ChangeSomeValues) {
... modify specific parameters in list here ...
yield MyState1(modifiedList);
}
}
}
我知道如何使用事件更改值,但我找不到如何使用这种通用实现编辑List中的特定参数.