pushStyle method Null safety

void pushStyle(
  1. TextStyle style
)

Applies the given style to the added text until pop is called.

See pop for details.

Implementation

void pushStyle(TextStyle style) {
  final List<String> fullFontFamilies = <String>[];
  fullFontFamilies.add(style._fontFamily);
  if (style._fontFamilyFallback != null) {
    fullFontFamilies.addAll(style._fontFamilyFallback!);
  }

  final Int32List encoded = style._encoded;
  final TextLeadingDistribution finalLeadingDistribution = style._leadingDistribution ?? _defaultLeadingDistribution;
  // ensure the enum can be represented using 1 bit.
  assert(TextLeadingDistribution.values.length <= 2);

  // Use the leading distribution from the paragraph's style if it's not
  // explicitly set in `style`.
  encoded[0] |= finalLeadingDistribution.index << 0;

  ByteData? encodedFontFeatures;
  final List<FontFeature>? fontFeatures = style._fontFeatures;
  if (fontFeatures != null) {
    encodedFontFeatures = ByteData(fontFeatures.length * FontFeature._kEncodedSize);
    int byteOffset = 0;
    for (final FontFeature feature in fontFeatures) {
      feature._encode(ByteData.view(encodedFontFeatures.buffer, byteOffset, FontFeature._kEncodedSize));
      byteOffset += FontFeature._kEncodedSize;
    }
  }

  ByteData? encodedFontVariations;
  final List<FontVariation>? fontVariations = style._fontVariations;
  if (fontVariations != null) {
    encodedFontVariations = ByteData(fontVariations.length * FontVariation._kEncodedSize);
    int byteOffset = 0;
    for (final FontVariation variation in fontVariations) {
      variation._encode(ByteData.view(encodedFontVariations.buffer, byteOffset, FontVariation._kEncodedSize));
      byteOffset += FontVariation._kEncodedSize;
    }
  }

  _pushStyle(
    encoded,
    fullFontFamilies,
    style._fontSize ?? 0,
    style._letterSpacing ?? 0,
    style._wordSpacing ?? 0,
    style._height ?? 0,
    style._decorationThickness ?? 0,
    _encodeLocale(style._locale),
    style._background?._objects,
    style._background?._data,
    style._foreground?._objects,
    style._foreground?._data,
    Shadow._encodeShadows(style._shadows),
    encodedFontFeatures,
    encodedFontVariations,
  );
}