在flutter中使用provider时,同屏使用多个consumer会影响性能吗?

发布于 2025-01-10 09:21:17 字数 297 浏览 2 评论 0原文

当在 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 技术交流群。

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

发布评论

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

评论(1

旧情勿念 2025-01-17 09:21:17

最重要的是仅将依赖于提供者的小部件包装到消费者中,以便仅重建这些小部件。

Most important thing is to wrap only the widgets that depends on a provider into a Consumer, so that only those are rebuild.

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