How to express flutter hollow Widget

In Flutter, the way to represent an empty Widget is to use  SizedBox.shrink() or  Container().

SizedBox.shrink() Creates an empty box of zero size, which has no visual effect but can take up some space. Example usage:

SizedBox.shrink()
复制代码

Container() Creates an empty container with zero visual area, which is  SizedBox.shrink() similar to but has some additional properties, such as color, border, etc. can be set. Example usage:

Container()
复制代码

In terms of performance, SizedBox.shrink() it will be  Container() better than , because  SizedBox.shrink() it is just an empty box, it does not need to do any drawing operations, but  Container() it needs to create a  RenderObject sum  RenderBox, and it needs to do some measurement and layout operations.

But in practical applications, this gap is insignificant, so when using an empty Widget, you should consider the use scene and the required attributes. If you need an empty container, and you need to set some attributes, such as color, border, etc. , it  Container() is more convenient to use. If you only need a placeholder and don't need to set any properties, then it  SizedBox.shrink() is more appropriate to use.

Guess you like

Origin blog.csdn.net/qq_28563283/article/details/130614664