computeMaxIntrinsicWidth static method

double computeMaxIntrinsicWidth({
  1. required InlineSpan text,
  2. required TextDirection textDirection,
  3. TextAlign textAlign = TextAlign.start,
  4. @Deprecated('Use textScaler instead. ' 'Use of textScaleFactor was deprecated in preparation for the upcoming nonlinear text scaling support. ' 'This feature was deprecated after v3.12.0-2.0.pre.') double textScaleFactor = 1.0,
  5. TextScaler textScaler = TextScaler.noScaling,
  6. int? maxLines,
  7. String? ellipsis,
  8. Locale? locale,
  9. StrutStyle? strutStyle,
  10. TextWidthBasis textWidthBasis = TextWidthBasis.parent,
  11. TextHeightBehavior? textHeightBehavior,
  12. double minWidth = 0.0,
  13. double maxWidth = double.infinity,
})

Computes the max intrinsic width of a configured TextPainter.

This is a convenience method that creates a text painter with the supplied parameters, lays it out with the supplied minWidth and maxWidth, and returns its TextPainter.maxIntrinsicWidth making sure to dispose the underlying resources. Doing this operation is expensive and should be avoided whenever it is possible to preserve the TextPainter to paint the text or get other information about it.

Implementation

static double computeMaxIntrinsicWidth({
  required InlineSpan text,
  required TextDirection textDirection,
  TextAlign textAlign = TextAlign.start,
  @Deprecated(
    'Use textScaler instead. '
    'Use of textScaleFactor was deprecated in preparation for the upcoming nonlinear text scaling support. '
    'This feature was deprecated after v3.12.0-2.0.pre.',
  )
  double textScaleFactor = 1.0,
  TextScaler textScaler = TextScaler.noScaling,
  int? maxLines,
  String? ellipsis,
  Locale? locale,
  StrutStyle? strutStyle,
  TextWidthBasis textWidthBasis = TextWidthBasis.parent,
  TextHeightBehavior? textHeightBehavior,
  double minWidth = 0.0,
  double maxWidth = double.infinity,
}) {
  assert(
    textScaleFactor == 1.0 || identical(textScaler, TextScaler.noScaling),
    'Use textScaler instead.',
  );
  final TextPainter painter = TextPainter(
    text: text,
    textAlign: textAlign,
    textDirection: textDirection,
    textScaler: textScaler == TextScaler.noScaling ? TextScaler.linear(textScaleFactor) : textScaler,
    maxLines: maxLines,
    ellipsis: ellipsis,
    locale: locale,
    strutStyle: strutStyle,
    textWidthBasis: textWidthBasis,
    textHeightBehavior: textHeightBehavior,
  )..layout(minWidth: minWidth, maxWidth: maxWidth);

  try {
    return painter.maxIntrinsicWidth;
  } finally {
    painter.dispose();
  }
}