asNullableText method
- TextStyle? style,
- StrutStyle? strutStyle,
- TextAlign? textAlign,
- TextDirection? textDirection,
- Locale? locale,
- bool? softWrap,
- TextOverflow? overflow,
- TextScaler? textScaler,
- int? maxLines,
- String? semanticsLabel,
- TextWidthBasis? textWidthBasis,
- bool validate = true,
- String? defaultText,
- string dateFormat = "",
Converts the object to a nullable Text widget with the specified properties.
If the object is null, it returns null.
If the object is already a Text widget, it returns the object itself.
If validate
is true and the object is not valid (see isValid()), it returns null.
Otherwise, it converts the object to a Text widget with the string representation of the object.
The style
, strutStyle
, textAlign
, textDirection
, locale
, softWrap
,
overflow
, textScaler
, maxLines
, semanticsLabel
, and textWidthBasis
parameters are used to customize the appearance and behavior of the Text widget.
Returns a nullable Text widget with the specified properties.
Implementation
Text? asNullableText({
TextStyle? style,
StrutStyle? strutStyle,
TextAlign? textAlign,
TextDirection? textDirection,
Locale? locale,
bool? softWrap,
TextOverflow? overflow,
TextScaler? textScaler,
int? maxLines,
String? semanticsLabel,
TextWidthBasis? textWidthBasis,
bool validate = true,
String? defaultText,
string dateFormat = "",
}) {
Text? text;
locale ??= platformLocale;
if (this == null && defaultText == null) return null;
if (this is Text) {
text = this as Text;
} else {
if (validate == false || this.isValid()) {
if (this is Map || this is List) {
text = Text(jsonEncode(this));
} else if (this is DateTime) {
text = Text((this as DateTime).format(dateFormat, locale.toLanguageTag()));
} else {
text = Text("$this" | defaultText);
}
} else if (defaultText != null) {
text = Text(defaultText);
}
}
return text?.copyWith(
style: style,
strutStyle: strutStyle,
textAlign: textAlign,
textDirection: textDirection,
locale: locale,
softWrap: softWrap,
overflow: overflow,
textScaler: textScaler,
maxLines: maxLines,
semanticsLabel: semanticsLabel,
textWidthBasis: textWidthBasis,
);
}