使用观察者的设计模式而不是在flutter中使用一个好主意吗?
问题是我有一个应用程序,需要在跨小部件上管理数据,然后收听修改(例如,只要窗口小部件“ y”更改变量时,在窗口小部件“ x”中执行操作)。
因此,我在想,而不是使用整个软件包,而是在我的依赖项中添加库(我的意思是提供商),而且由于Dart是面向对象的编程语言...我可以使用观察者设计模式(pub-sub)。这样,我才能收听变量的修改,只有在需要的情况下进行重建!
每次互动都非常感谢!!感谢你!
The thing is that I have an app where I need to manage data across widgets, and listen to modifications (like perform an action in widget "X" whenever the value of a variable in widget "Y" changes).
So I was thinking, instead of using a whole package and adding a library to my dependencies (I mean provider) and since dart is an Object-oriented programming language... I can use the observer design pattern (pub-sub). this way I can listen to variables' modifications and perform rebuilds only where needed!
Every interaction is highly appreciated!! THANK U!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
提供商
软件包仅在那里使事情变得更容易。我认为建立自己的或使用酒吧式的bub会不会容易。Flutter已经提供了详细的国家管理介绍可能先退房。首先使用Core Flutter框架提供的工具。然后,您将找出哪些好处
提供商
,riverpod
,redux
,rx
等。它们是否对您的用例有益。the
provider
package is only there to make things easier. I think building your own, or using, a pub-sub wouldn't be any easier.Flutter already provides a detailed introduction on state management which you should probably check out first. Start by using the tools provided by the core flutter framework. Then you will find out what benefits
provider
,riverpod
,redux
,rx
, etc. bring to the table and whether they are beneficial to your use cases.