When to use SizedBox.shrink()
to return an empty box¶
Ever needed to return an empty box (that takes no space) in Flutter?
There’s a widget for that → SizedBox.shrink()
This is more performant than returning an empty Container
(which is complex inside and can’t be declared as a const
widget).
Note that in many cases, you can avoid returning a widget in the first place.
For example, if you are inside a Row
or Column
, you can just use the collection-if operator instead. 👇
Previous | Next |
---|---|
–enable-asserts flag in Dart / Flutter | Flutter app localization in 5 min |
Last update:
18 septembre 2023
Created: 18 septembre 2023
Created: 18 septembre 2023