getParagraphStyle method

ParagraphStyle getParagraphStyle({
  1. TextAlign? textAlign,
  2. TextDirection? textDirection,
  3. TextScaler textScaler = TextScaler.noScaling,
  4. String? ellipsis,
  5. int? maxLines,
  6. TextHeightBehavior? textHeightBehavior,
  7. Locale? locale,
  8. String? fontFamily,
  9. double? fontSize,
  10. FontWeight? fontWeight,
  11. FontStyle? fontStyle,
  12. double? height,
  13. StrutStyle? strutStyle,
})

The style information for paragraphs, encoded for use by dart:ui.

If the textScaleFactor argument is omitted, it defaults to one. The other arguments may be null. The maxLines argument, if specified and non-null, must be greater than zero.

If the font size on this style isn't set, it will default to 14 logical pixels.

Implementation

ui.ParagraphStyle getParagraphStyle({
  TextAlign? textAlign,
  TextDirection? textDirection,
  TextScaler textScaler = TextScaler.noScaling,
  String? ellipsis,
  int? maxLines,
  TextHeightBehavior? textHeightBehavior,
  Locale? locale,
  String? fontFamily,
  double? fontSize,
  FontWeight? fontWeight,
  FontStyle? fontStyle,
  double? height,
  StrutStyle? strutStyle,
}) {
  assert(maxLines == null || maxLines > 0);
  final TextLeadingDistribution? leadingDistribution = this.leadingDistribution;
  final TextHeightBehavior? effectiveTextHeightBehavior = textHeightBehavior
    ?? (leadingDistribution == null ? null : TextHeightBehavior(leadingDistribution: leadingDistribution));

  return ui.ParagraphStyle(
    textAlign: textAlign,
    textDirection: textDirection,
    // Here, we establish the contents of this TextStyle as the paragraph's default font
    // unless an override is passed in.
    fontWeight: fontWeight ?? this.fontWeight,
    fontStyle: fontStyle ?? this.fontStyle,
    fontFamily: fontFamily ?? this.fontFamily,
    fontSize: textScaler.scale(fontSize ?? this.fontSize ?? kDefaultFontSize),
    height: height ?? this.height,
    textHeightBehavior: effectiveTextHeightBehavior,
    strutStyle: strutStyle == null ? null : ui.StrutStyle(
      fontFamily: strutStyle.fontFamily,
      fontFamilyFallback: strutStyle.fontFamilyFallback,
      fontSize: switch (strutStyle.fontSize) {
        null => null,
        final double unscaled => textScaler.scale(unscaled),
      },
      height: strutStyle.height,
      leading: strutStyle.leading,
      leadingDistribution: strutStyle.leadingDistribution,
      fontWeight: strutStyle.fontWeight,
      fontStyle: strutStyle.fontStyle,
      forceStrutHeight: strutStyle.forceStrutHeight,
    ),
    maxLines: maxLines,
    ellipsis: ellipsis,
    locale: locale,
  );
}