提问人:Mo_ 提问时间:5/25/2022 更新时间:5/25/2022 访问量:280
当我使用 equatable 时,如何多次发出空状态
How to emit empty state more than one time when I am using equatable
问:
我正在尝试多次发出状态,因为我正在验证表单,无需在构造函数上添加任何东西并制作 copyWith func 等。
那么你能帮我提供其他解决方案吗?
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());
}
答:
0赞
Robert Sandberg
5/25/2022
#1
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 应该更改什么?
评论
1赞
Mo_
5/25/2022
是的,我明白了,我在 GitHub 上发现了一个问题,公平所有者在这种情况下建议从基类中删除等值并添加到子类中
评论