build static method

GText build({
  1. String? text,
  2. GDisplayObjectContainer? doc,
  3. Color? color,
  4. double width = double.infinity,
  5. TextDecoration? decoration,
  6. Color? decorationColor,
  7. TextDecorationStyle? decorationStyle,
  8. double? decorationThickness,
  9. FontWeight? fontWeight,
  10. FontStyle? fontStyle,
  11. TextBaseline? textBaseline,
  12. String? fontFamily,
  13. List<String>? fontFamilyFallback,
  14. double? fontSize,
  15. double? letterSpacing,
  16. double? wordSpacing,
  17. double? height,
  18. Locale? locale,
  19. Paint? background,
  20. Paint? foreground,
  21. String? ellipsis,
  22. int? maxLines,
  23. List<Shadow>? shadows,
  24. List<FontFeature>? fontFeatures,
  25. TextAlign textAlign = ui.TextAlign.left,
  26. TextDirection direction = ui.TextDirection.ltr,
})

Creates a new GText object with the given properties and adds it to the specified GDisplayObjectContainer instance.

The text argument is the text to be displayed. The doc argument is the display object container to which the text will be added. The width argument is the width of the text box, which defaults to double.infinity. If the textAlign argument is not ui.TextAlign.left, the width argument must be specified.

The remaining arguments correspond to properties of the painting.TextStyle and ui.ParagraphStyle classes. Refer to their respective documentation for more information.

Returns the newly created GText instance.

Throws an exception if textAlign is not ui.TextAlign.left and width is not specified.

Implementation

static GText build({
  String? text,
  GDisplayObjectContainer? doc,
  ui.Color? color,
  double width = double.infinity,
  ui.TextDecoration? decoration,
  ui.Color? decorationColor,
  ui.TextDecorationStyle? decorationStyle,
  double? decorationThickness,
  ui.FontWeight? fontWeight,
  ui.FontStyle? fontStyle,
  ui.TextBaseline? textBaseline,
  String? fontFamily,
  List<String>? fontFamilyFallback,
  double? fontSize,
  double? letterSpacing,
  double? wordSpacing,
  double? height,
  ui.Locale? locale,
  ui.Paint? background,
  ui.Paint? foreground,
  String? ellipsis,
  int? maxLines,
  List<ui.Shadow>? shadows,
  List<ui.FontFeature>? fontFeatures,
  ui.TextAlign textAlign = ui.TextAlign.left,
  ui.TextDirection direction = ui.TextDirection.ltr,
}) {
  if (width == double.infinity && textAlign != ui.TextAlign.left) {
    throw "[GText] To use $textAlign you need to specify the `width`";
  }
  final style = painting.TextStyle(
    color: color,
    decoration: decoration,
    decorationColor: decorationColor,
    decorationStyle: decorationStyle,
    decorationThickness: decorationThickness,
    fontWeight: fontWeight,
    fontStyle: fontStyle,
    textBaseline: textBaseline,
    fontFamily: fontFamily,
    fontFamilyFallback: fontFamilyFallback,
    fontSize: fontSize,
    letterSpacing: letterSpacing,
    wordSpacing: wordSpacing,
    height: height,
    locale: locale,
    background: background,
    foreground: foreground,
    shadows: shadows,
    fontFeatures: fontFeatures,
  );
  final tf = GText(
    text: text,
    width: width,
    textStyle: style,
    paragraphStyle: ui.ParagraphStyle(
      maxLines: maxLines,
      ellipsis: ellipsis,
      textAlign: textAlign,
      textDirection: direction,
    ),
  );
  doc?.addChild(tf);
  return tf;
}