如何更新aList< map>'与集体和平等?
我仍然是Bloc Architecture的初学者。到目前为止,使用int
,bool
和其他基本数据类型时,UI更新会更新。但是,当涉及列表和地图时,它确实使我感到困惑。我的代码基本上是这样的:
// STATE CLASS
class MyBlocState extends Equatable {
final List someData;
const MyBlocState({required this.someData});
@override
List<Object> get props => [someData];
// I tried doing this too. Not sure if it's correct. It didn't work anyway!
List<Object> get props => [...someData];
}
// INITIAL STATE CLASS
class MyBlocInitial extends MyBlocState {
MyBlocInitial() : super(someData: [{"a": "unknown", "bool": false}, {"b": "unknown", "bool": false}]);
}
// EVENT CLASS
...
...
// BLOC CLASS
class MyBloc extends Bloc<MyBlocEvent, MyBlocState> {
MyBloc() : super(MyBlocInitial()) {
on<UpdateSomeDataEvent>((event, emit) {
var newData = [{"a": "Apple", "bool": true}, {"b": "Blue", "bool": true}]
emit(MyBlocState(someData: newData));
});
}
}
我尝试使用list.from
,map.from
,清空数组并再次填充它,我最终使我刚刚复杂化代码没有任何效果。我知道这是关于“平等”的东西,比较了以前和新状态,但是我对如何围绕它的工作一无所知。与此相关的任何额外信息将不胜感激。感谢您的时间。
I am still a beginner with BLoC architecture. So far the UI updates when using int
, bool
, and other basic data types. But when it comes to Lists and Maps it really confuses me. My code basically looks like this:
// STATE CLASS
class MyBlocState extends Equatable {
final List someData;
const MyBlocState({required this.someData});
@override
List<Object> get props => [someData];
// I tried doing this too. Not sure if it's correct. It didn't work anyway!
List<Object> get props => [...someData];
}
// INITIAL STATE CLASS
class MyBlocInitial extends MyBlocState {
MyBlocInitial() : super(someData: [{"a": "unknown", "bool": false}, {"b": "unknown", "bool": false}]);
}
// EVENT CLASS
...
...
// BLOC CLASS
class MyBloc extends Bloc<MyBlocEvent, MyBlocState> {
MyBloc() : super(MyBlocInitial()) {
on<UpdateSomeDataEvent>((event, emit) {
var newData = [{"a": "Apple", "bool": true}, {"b": "Blue", "bool": true}]
emit(MyBlocState(someData: newData));
});
}
}
I tried creating new instances, using List.from
, Map.from
, emptying the array and filling it again, and I just ended up complicating the code without any effects. I know it's something concerning 'Equatable', comparing previous and new states, but I have no clue on how to work around it. Any extra information related to this will be deeply appreciated. Thanks for your time.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论