从buald_value更新构建列表

发布于 2025-01-27 07:05:27 字数 780 浏览 2 评论 0 原文

如果满足某种条件,我想更新州内的式列表。这是我的还原器,

TravelDeductionsStateBuilder _travelDeductionBreakfastToggled(
        TravelDeductionsStateBuilder state,
        TravelDeductionBreakfastToggledAction action) =>
    state
      ..days = state.days.build().rebuild((d) {
        if (d[action.key].deductions.contains(TravelDeductionType.BREAKFAST)) {
          d[action.key]
              .deductions
              .rebuild((p0) => p0.remove(TravelDeductionType.BREAKFAST));
        } else {
          d[action.key]
              .deductions
              .rebuild((p0) => p0.add(TravelDeductionType.BREAKFAST));
        }
      }).toBuilder();

我需要将/删除枚举条目添加到扣除中,但似乎忽略了此更新,我无法相应地更新此列表。有什么提示可能出了什么问题吗?

I want to update the BuiltList in the state if some condition is met. Here is my reducer

TravelDeductionsStateBuilder _travelDeductionBreakfastToggled(
        TravelDeductionsStateBuilder state,
        TravelDeductionBreakfastToggledAction action) =>
    state
      ..days = state.days.build().rebuild((d) {
        if (d[action.key].deductions.contains(TravelDeductionType.BREAKFAST)) {
          d[action.key]
              .deductions
              .rebuild((p0) => p0.remove(TravelDeductionType.BREAKFAST));
        } else {
          d[action.key]
              .deductions
              .rebuild((p0) => p0.add(TravelDeductionType.BREAKFAST));
        }
      }).toBuilder();

I need to add/remove ENUM entry into deductions but it seems that this update is ignored and I am not able to update this list accordingly. Any tips of what may be wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

倦话 2025-02-03 07:05:27

如果有人想知道这是解决方案,

TravelDeductionsStateBuilder _travelDeductionBreakfastToggled(
        TravelDeductionsStateBuilder state,
        TravelDeductionBreakfastToggledAction action) =>
    state
      ..days = state.days.build().rebuild((d) {
        if (d[action.index]
            .deductions
            .contains(TravelDeductionType.BREAKFAST)) {
          d[action.index] = d[action.index].rebuild(
              (b) => b.deductions.remove(TravelDeductionType.BREAKFAST));
        } else {
          d[action.index] = d[action.index]
              .rebuild((b) => b.deductions.add(TravelDeductionType.BREAKFAST));
        }
      }).toBuilder();

您可以在此处找到说明

If anyone wonders this is the solution

TravelDeductionsStateBuilder _travelDeductionBreakfastToggled(
        TravelDeductionsStateBuilder state,
        TravelDeductionBreakfastToggledAction action) =>
    state
      ..days = state.days.build().rebuild((d) {
        if (d[action.index]
            .deductions
            .contains(TravelDeductionType.BREAKFAST)) {
          d[action.index] = d[action.index].rebuild(
              (b) => b.deductions.remove(TravelDeductionType.BREAKFAST));
        } else {
          d[action.index] = d[action.index]
              .rebuild((b) => b.deductions.add(TravelDeductionType.BREAKFAST));
        }
      }).toBuilder();

You can find the explanation here https://github.com/google/built_collection.dart/issues/259#issuecomment-1122390601

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文