Flutter 获取颤振阵营内最后一个屈服状态的访问权限
我有两个屏幕:第一个是项目列表,第二个是用于编辑或创建项目的表单页面。每个页面分别通过使用Flutter 获取颤振阵营内最后一个屈服状态的访问权限,flutter,bloc,Flutter,Bloc,我有两个屏幕:第一个是项目列表,第二个是用于编辑或创建项目的表单页面。每个页面分别通过使用flatter\u BloC库的专用BloC-ItemListBloc和FormBloc进行管理。每当在表单上调用submit时,我都希望在ItemListBloc中对此作出反应,并在列表中修改或插入项,以避免从后端重新读取整个内容 这就是我努力实现这一目标的方式: ItemListBloc({ @required this.itemFormBloc, ... }) { itemFormSub
flatter\u BloC
库的专用BloC-ItemListBloc
和FormBloc
进行管理。每当在表单上调用submit时,我都希望在ItemListBloc
中对此作出反应,并在列表中修改或插入项,以避免从后端重新读取整个内容
这就是我努力实现这一目标的方式:
ItemListBloc({ @required this.itemFormBloc, ... }) {
itemFormSub = itemFormBloc.state.listen((state) {
if (state is FormSubmitted) {
dispatch(ModifyOrInsert(isEdit: state.isEdit, item: state.isItem));
}
});
}
@override
Stream<ItemListState> mapEventToState(
ItemListEvent event,
) async* {
if (event is ModifyOrInsert) {
yield* _modifyOrInsert(isEdit: event.isEdit, item: event.item);
}
}
Stream<ItemListState> _modifyOrInsert({bool isEdit, Item item}) async* {
// How to get access to the list of items here?
}
ItemListBloc({@required this.itemFormBloc,…}){
itemFormSub=itemFormBloc.state.listen((状态){
如果(状态已提交){
分派(修改或插入(isEdit:state.isEdit,项:state.isItem));
}
});
}
@凌驾
流映射事件状态(
ItemListEvent事件,
)异步*{
如果(事件为ModifyOrInsert){
收益率*\修改或插入(isEdit:event.isEdit,item:event.item);
}
}
流_modifyOrInsert({bool isEdit,Item})异步*{
//如何访问此处的项目列表?
}
与Redux-y全局状态不同,我有许多状态,可以对它们进行操作并将其中一个声明为当前状态。ItemListBloc
的最后一个状态通常是ItemsLoaded
,它保存整个项目列表。我需要访问此状态,获取项目,更新列表中的项目(如果是编辑),在列表中添加项目(如果是创建的),然后静默地yield
updatedItemsLoaded
状态