fireOnLineCountChange method
void
fireOnLineCountChange(
- String text, {
- required BoxConstraints constraints,
- required TextStyle effectiveTextStyle,
- required TextScaler textScaler,
- required double effectiveCursorWidth,
Implementation
void fireOnLineCountChange(
String text, {
required BoxConstraints constraints,
required TextStyle effectiveTextStyle,
required TextScaler textScaler,
required double effectiveCursorWidth,
}) {
// Do nothing if the callback is null
if (widget.onLineCountChange == null) {
return;
}
final span = TextSpan(
text: text,
style: effectiveTextStyle,
);
final tp = TextPainter(
text: span,
textDirection: Directionality.of(
context,
),
textScaler: textScaler,
maxLines: widget.maxLines,
textAlign: widget.textAlign,
textWidthBasis: widget.expands
? TextWidthBasis.parent
: TextWidthBasis.longestLine,
);
// The default caret gap is 1 pixel, so we need to account for that
const caretGap = 1;
// default of TextField constructor
tp.layout(
maxWidth: constraints.maxWidth - caretGap - effectiveCursorWidth,
);
final numLines = tp.computeLineMetrics().length;
// Only fire callback if line count changed
if (numLines != _previousLineCount) {
_previousLineCount = numLines;
widget.onLineCountChange!(
numLines,
);
}
}