使用Flutter拥有大量嵌套小部件是不是很糟糕?

前端之家收集整理的这篇文章主要介绍了使用Flutter拥有大量嵌套小部件是不是很糟糕?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个强大的 Android开发背景,现在我正在尝试使用Flutter开发我的第一个应用程序.

Android社区的一个常识是,嵌套视图太多很糟糕.这对性能有害. (这就是为什么存在ConstraintLayout的原因之一)

但是,在很多Flutter教程中,我看到人们嵌套了很多小部件.

有人可以确认用Flutter嵌套小部件不是问题吗?如果我这样做,我的应用会遭受糟糕的表现吗?

提前致谢

解决方法

嵌套小部件不是问题,实际上是推荐的.
实际上,默认计数器应用程序包含不少于150个小部件.

小部件是轻量级对象,专门针对每帧创建和销毁吨数进行优化. Flutter FAQ进一步证实了这一点:

Rather than having each widget provide a large number of parameters,Flutter embraces composition. Widgets are built out of smaller widgets that you can reuse and combine in novel ways to make custom widgets. For example,rather than subclassing a generic button widget,RaisedButton combines a Material widget with a GestureDetector widget. The Material widget provides the visual design and the GestureDetector widget provides the interaction design.

这句话说你应该有目的地嵌套小部件.

猜你在找的Flutter相关文章