build static method
GText
build({
- String? text,
- GDisplayObjectContainer? doc,
- Color? color,
- double width = double.infinity,
- TextDecoration? decoration,
- Color? decorationColor,
- TextDecorationStyle? decorationStyle,
- double? decorationThickness,
- FontWeight? fontWeight,
- FontStyle? fontStyle,
- TextBaseline? textBaseline,
- String? fontFamily,
- List<
String> ? fontFamilyFallback, - double? fontSize,
- double? letterSpacing,
- double? wordSpacing,
- double? height,
- Locale? locale,
- Paint? background,
- Paint? foreground,
- String? ellipsis,
- int? maxLines,
- List<
Shadow> ? shadows, - List<
FontFeature> ? fontFeatures, - TextAlign textAlign = ui.TextAlign.left,
- 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;
}