简体   繁体   English

如何更改 Flutter 块 state

[英]How To I change Flutter bloc state

I am using bloc in my project but when I emit 2 or 3 times the same state my state does not change我在我的项目中使用 bloc 但是当我发出 2 或 3 倍相同的 state 我的 state 不会改变

 on<FetchActivePeriodsEvent>((event, emit) async {
  var model = await _offlineRepository.getPeriods(event.id, event.date);

  final state2 = state as LoadedLocationsState;

  emit(LoadedLocationsState(
      activeAppointments: state2.activeAppointments,
      nameAndSurname: state2.nameAndSurname,
      tc: state2.tc,
      locations: state2.locations,
      activePeriodModel: model.data?.oturumlar??[]));
});

How can I emit state with new values如何使用新值发出 state

If you want to emit a new state, you need an event to trigger a new state that would replace the old state.如果你想发出一个新的 state,你需要一个事件来触发一个新的 state 来替换旧的 state。 Blocs only move on a state to state basis so a new event would trigger a new state, a previous state will re-trigger itself. Blocs only move on a state to state basis so a new event would trigger a new state, a previous state will re-trigger itself.

So trigger new events and not states, because the emit function only emits new states.所以触发新事件而不是状态,因为发射 function 只发射新状态。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM