updateBounds method

  1. @override
  2. @internal
void updateBounds()
override

Implementation

@override
@internal
void updateBounds() {
  lines.clear();
  var lineHeight = 0.0;
  final maxBoxWidth = _fixedSize ? width : _boxConfig.maxWidth;
  text.split(' ').forEach((word) {
    final wordLines = word.split('\n');
    final possibleLine =
        lines.isEmpty ? wordLines[0] : '${lines.last} ${wordLines[0]}';
    final metrics = textRenderer.getLineMetrics(possibleLine);
    lineHeight = max(lineHeight, metrics.height);

    _updateMaxWidth(metrics.width);
    final bool canAppend;
    if (metrics.width <= maxBoxWidth - _boxConfig.margins.horizontal) {
      canAppend = lines.isNotEmpty;
    } else {
      canAppend = lines.isNotEmpty && lines.last == '';
    }

    if (canAppend) {
      lines.last = '${lines.last} ${wordLines[0]}';
      wordLines.removeAt(0);
      if (wordLines.isNotEmpty) {
        lines.addAll(wordLines);
      }
    } else {
      lines.addAll(wordLines);
    }
  });
  _totalLines = lines.length;
  _lineHeight = lineHeight;
  size = _recomputeSize();
}