TextPainter constructor

TextPainter({
  1. InlineSpan? text,
  2. TextAlign textAlign = TextAlign.start,
  3. TextDirection? textDirection,
  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,
})

Creates a text painter that paints the given text.

The text and textDirection arguments are optional but text and textDirection must be non-null before calling layout.

The maxLines property, if non-null, must be greater than zero.

Implementation

TextPainter({
  InlineSpan? text,
  TextAlign textAlign = TextAlign.start,
  TextDirection? textDirection,
  @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,
}) : assert(text == null || text.debugAssertIsValid()),
     assert(maxLines == null || maxLines > 0),
     assert(textScaleFactor == 1.0 || identical(textScaler, TextScaler.noScaling), 'Use textScaler instead.'),
     _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 {
  // TODO(polina-c): stop duplicating code across disposables
  // https://github.com/flutter/flutter/issues/137435
  if (kFlutterMemoryAllocationsEnabled) {
    FlutterMemoryAllocations.instance.dispatchObjectCreated(
      library: _flutterPaintingLibrary,
      className: '$TextPainter',
      object: this,
    );
  }
}