如何更新aList< map>'与集体和平等?

发布于 2025-01-26 06:30:48 字数 1151 浏览 1 评论 0原文

我仍然是Bloc Architecture的初学者。到目前为止,使用intbool和其他基本数据类型时,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.frommap.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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文