layout method

  1. @override
void layout(
  1. BoxConstraints constraints
)
override

Implementation

@override
void layout(BoxConstraints constraints) {
  super.layout(constraints);

  // Wrap text to the constraint width when softWrap is enabled and the
  // width is bounded.  Without this, long text would be silently clipped
  // during paint() instead of reflowing to multiple lines.
  final wrapWidth = softWrap && constraints.hasBoundedWidth
      ? constraints.maxWidth.toInt()
      : null;
  if (_wrappedText == null ||
      _lastText != text ||
      _lastSoftWrap != softWrap ||
      _lastWrapWidth != wrapWidth) {
    if (wrapWidth != null && wrapWidth > 0) {
      _wrappedText = Layout.wrapLines(text, wrapWidth);
    } else {
      _wrappedText = text;
    }
    _lastText = text;
    _lastSoftWrap = softWrap;
    _lastWrapWidth = wrapWidth;
  }

  final width = Layout.getWidth(_wrappedText!).toDouble();
  final height = Layout.getHeight(_wrappedText!).toDouble();
  size = constraints.constrain(Size(width, height));
}