Flutter GETX -variable.value = newValue 和variable(newValue) 之间有什么区别?
我一直在想,在flutter getx库中,如果我以这种方式定义了可观察的变量
Rxn<MyClass> myObsObject = Rxn<MyClass>();
,我可以通过以下方式更新其值:
myObsObject(newValue) / myObsObject(null)
或以等效的方式
myObsObject.value = newValue / myObsObject.value = null
今天,我发现这两种方法不是等效,因为在某些情况下(不知道如何重现ATM)在某些情况下采用第一种方式,但第二次使用getx
widget的构建器,而第二个则没有。
那么上面两种方法之间的差异是什么?
I've always been thinking that in Flutter GetX library, if I have an observable variable defined in this way
Rxn<MyClass> myObsObject = Rxn<MyClass>();
I could update its value by doing:
myObsObject(newValue) / myObsObject(null)
or in an EQUIVALENT WAY
myObsObject.value = newValue / myObsObject.value = null
Today I discovered that the 2 methods are NOT equivalent, since doing the first way in some cases (don't know how to reproduce ATM) doesn't retrigger the builder of a GetX
widget, while the second does.
So what is/are the difference(s) between the two methods up above?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你可以检查第一种方法的实现,你会发现它是这样的:
所以基本上,它仍然对
value
进行赋值除非值为null。因此,
myObsObject(newValue)
在所有情况下都应该可以正常工作,除非newValue
为null
You can check the implementation of the first way and you will see that it is this:
So basically, it still does the assignment to
value
except when the value is null.So
myObsObject(newValue)
should work fine in all cases except whennewValue
isnull