merge method

TextStyle merge (TextStyle other)

Returns a new text style that is a combination of this style and the given other style.

If the given other text style has its TextStyle.inherit set to true, its null properties are replaced with the non-null properties of this text style. The other style inherits the properties of this style. Another way to think of it is that the "missing" properties of the other style are filled by the properties of this style.

If the given other text style has its TextStyle.inherit set to false, returns the given other style unchanged. The other style does not inherit properties of this style.

If the given text style is null, returns this text style.

One of color or foreground must be null, and if this or other has foreground specified it will be given preference over any color parameter.

Similarly, One of backgroundColor or background must be null, and if this or other has background specified it will be given preference over any backgroundColor parameter.

Implementation

TextStyle merge(TextStyle other) {
  if (other == null)
    return this;
  if (!other.inherit)
    return other;

  String mergedDebugLabel;
  assert(() {
    if (other.debugLabel != null || debugLabel != null)
      mergedDebugLabel = '(${debugLabel ?? _kDefaultDebugLabel}).merge(${other.debugLabel ?? _kDefaultDebugLabel})';
    return true;
  }());

  return copyWith(
    color: other.color,
    backgroundColor: other.backgroundColor,
    fontFamily: other.fontFamily,
    fontFamilyFallback: other.fontFamilyFallback,
    fontSize: other.fontSize,
    fontWeight: other.fontWeight,
    fontStyle: other.fontStyle,
    letterSpacing: other.letterSpacing,
    wordSpacing: other.wordSpacing,
    textBaseline: other.textBaseline,
    height: other.height,
    locale: other.locale,
    foreground: other.foreground,
    background: other.background,
    shadows: other.shadows,
    decoration: other.decoration,
    decorationColor: other.decorationColor,
    decorationStyle: other.decorationStyle,
    decorationThickness: other.decorationThickness,
    debugLabel: mergedDebugLabel,
  );
}