当我使用Equatable时,如何发射空状态多次以上

发布于 2025-02-01 03:26:39 字数 446 浏览 4 评论 0原文

我试图发出多次状态,因为我正在验证一种表格,不需要在构造函数上添加任何东西并制作复制功能

    class PersonUnValid extends PersonState {

  const PersonUnValid();

  @override
  List<Object> get props => [];

}
  void validate() {
    personKey.currentState!.save();
    if (Formz.validate(personForm.inputs) == FormzStatus.valid) {
      emit(const PersonValid());
      return;
    }
    emit(PersonUnValid());
  }

I am trying to emit a state more than one time because I am validating a form no need to add any thing on the constructor and make copyWith func etc..

so could you help me with other solutions?

    class PersonUnValid extends PersonState {

  const PersonUnValid();

  @override
  List<Object> get props => [];

}
  void validate() {
    personKey.currentState!.save();
    if (Formz.validate(personForm.inputs) == FormzStatus.valid) {
      emit(const PersonValid());
      return;
    }
    emit(PersonUnValid());
  }

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

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

发布评论

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

评论(1

往日 2025-02-08 03:26:39

emit()如果(状态)相同,则不会发出新状态。这是设计。请参阅:

/// Updates the [state] to the provided [state].
/// [emit] does nothing if the [state] being emitted
/// is equal to the current [state].
void emit(State state) {
...
if (state == _state && _emitted) return;
...

当状态相同时,您期望UI应该更改?

emit() will not emit a new state, if it (the state) is identical. This is by design. See:

/// Updates the [state] to the provided [state].
/// [emit] does nothing if the [state] being emitted
/// is equal to the current [state].
void emit(State state) {
...
if (state == _state && _emitted) return;
...

What do you expect the UI should change when the state is the same?

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