preferredSize property

  1. @override
Size get preferredSize

The size this widget would prefer if it were otherwise unconstrained.

In many cases it's only necessary to define one preferred dimension. For example the Scaffold only depends on its app bar's preferred height. In that case implementations of this method can just return Size.fromHeight(myAppBarHeight).

Implementation

@override
Size get preferredSize {
  if (height != null) {
    return scrollDirection == Axis.horizontal
        ? Size.fromHeight(height!)
        : Size.fromWidth(height!);
  } else if ((text != null || child != null) && icon != null) {
    return scrollDirection == Axis.horizontal
        ? const Size.fromHeight(_kTextAndIconTabHeight)
        : const Size.fromWidth(_kTextAndIconTabHeight);
  } else {
    return scrollDirection == Axis.horizontal
        ? const Size.fromHeight(_kTabHeight)
        : const Size.fromWidth(_kTabHeight);
  }
}