computeWidth static method
- 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,
Computes the 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.width 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 computeWidth({
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.width;
} finally {
painter.dispose();
}
}