combine method

TextStyle combine(
  1. TextStyle? other
)

返回此 TextStyle 的副本,其中 other 中的非空字段替换了此 TextStyle 中相应的空字段。 换句话说,other 用于填充此 TextStyle 中的未指定(空)字段。 !!!: _package 字段是私有的,无法获取 package, 所以不能替换 package 字段。

Implementation

TextStyle combine(TextStyle? other) {
  if (other == null) {
    return this;
  }
  if (!other.inherit) {
    return other;
  }

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

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