createTextSpan static method

TextSpan createTextSpan(
  1. String? text,
  2. CSSRenderStyle renderStyle, {
  3. Color? color,
  4. double? height,
  5. TextSpan? oldTextSpan,
})

Implementation

static TextSpan createTextSpan(
  String? text,
  CSSRenderStyle renderStyle, {
  Color? color,
  double? height,
  TextSpan? oldTextSpan,
}) {
  // Ensure font is loaded for the specific weight before creating TextStyle
  List<String>? fontFamilies = renderStyle.fontFamily;
  if (fontFamilies != null && fontFamilies.isNotEmpty) {
    String primaryFontFamily = fontFamilies[0];
    // Fire and forget - the font will be available for the next frame
    CSSFontFace.ensureFontLoaded(primaryFontFamily, renderStyle.fontWeight, renderStyle);
  }

  TextStyle textStyle = createTextStyle(renderStyle, height: height, color: color);
  if (oldTextSpan != null && oldTextSpan.text == text && oldTextSpan.style == textStyle) {
    return oldTextSpan;
  }
  return TextSpan(text: text, style: textStyle, children: []);
}