在提供商类中存储小部件并在多个小部件中重复使用小部件

发布于 2025-01-28 09:04:11 字数 326 浏览 2 评论 0原文

嘿,堆栈溢出社区,如果这个问题不是一个好问题,请轻松对我放松:)

初始化一个小部件(例如siziedbox)在提供商类中具有固定高度的小部件是否有任何优势在列内。

我的想法是,因为我一旦初始化它就会比继续在小部件树内所有其他小部件中一遍又一遍地创建相同的小部件要高。

我的直觉是,它不会每次重新创建无状态小部件,而是会引用我最初在提供商中定义的相同的盒子。另外,这将使在我所有页面上拥有相同的填充变得更加容易。

例如,在C中,您可以为新对象分配新内存,也可以将指针存储到该对象的指针,然后使用该指针来获取这样的对象。显然,我可能完全错了,因此我的问题。

提前致谢 :)

Hey Stack overflow community please go easy on me if this question is not a good one :)

Is there any advantage to initialising a widget such as SizedBox with a fixed height within a Provider class that I will use in all my widgets to create a padding within columns.

My thoughts were that because I initialise it once it will be more efficient than to keep creating the same widget over and over again inside all other widgets within my widget tree.

My intuition is that instead of recreating the stateless widget each time, it will reference that same SizedBox that I defined initially in my provider. Also this will make it easier to have the same padding across all of my pages.

For example in C you can either allocate new memory for a new object or store the pointer to that object and just use that pointer to get the object like that. Obviously I might be completely wrong and hence my question.

Thanks in advance :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文