在flutter中使用provider时,同屏使用多个consumer会影响性能吗?
当在 flutter 中使用提供程序包时,您可以用消费者扭曲脚手架,但随后在每个通知侦听器调用时,整个屏幕都会重建,因此我仅将消费者用于依赖于提供程序的小部件,但我被告知这样做会创建多个监听器会影响性能,所以我的问题是:
在同一屏幕上使用多个消费者会影响性能吗?如果是的话我怎样才能避免不必要的重建?如果答案是在消费者中使用子参数那么我如何标记多个小部件以便它们不会重建?因为 child 参数仅提供一个要标记的小部件。
另一个问题:
当使用notifylisteners时,所有相应的消费者都会被触发重建,有没有办法只重建特定的消费者?
when using the provider package in flutter ,you can warp the scaffold with a consumer but then on every notifylisteners call the whole screen will rebuild so I used consumer only for the widgets that depend on the provider, but I was told that doing so will create multiple listeners which will affect performance, so my question is:
Does using multiple consumers on the same screen affect the performance? if yes then how can I avoid unnecessary rebuilds? if the answer is to use the child parameter in the consumer then how can I mark multiple widgets so that they won't rebuild? as the child parameter only offers one widget to be marked.
another question :
when using notifylisteners all the corresponding consumers are triggered to rebuild is there is a way to rebuild only specific consumers?.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最重要的是仅将依赖于提供者的小部件包装到消费者中,以便仅重建这些小部件。
Most important thing is to wrap only the widgets that depends on a provider into a Consumer, so that only those are rebuild.