getProperty<T> method
T?
getProperty<T>([
- dynamic def
Implementation
T? getProperty<T>([dynamic def]) {
if (this is Text) {
final title = this as Text;
switch (T) {
case String:
return (title.data ?? title.textSpan?.toPlainText()) as T?;
case InlineSpan:
return (title.textSpan ??
TextSpan(
text: title.data ?? '',
style:
title.getProperty<TextStyle>()?.merge(def as TextStyle?) ??
def as TextStyle?,
)) as T?;
case TextStyle:
return title.style as T?;
case TextAlign:
return title.textAlign as T?;
case TextHeightBehavior:
return title.textHeightBehavior as T?;
case TextWidthBasis:
return title.textWidthBasis as T?;
}
} else if (this is RichText) {
final title = this as RichText;
switch (T) {
case String:
return title.text.toPlainText() as T?;
case InlineSpan:
if (T is InlineSpan) {
final span = title.text;
span.style?.merge(def as TextStyle?);
return span as T;
}
return title.text as T;
case TextStyle:
return (title.text.style as T?) ?? def as T?;
case TextAlign:
return title.textAlign as T?;
case TextHeightBehavior:
return title.textHeightBehavior as T?;
case TextWidthBasis:
return title.textWidthBasis as T?;
}
} else if (this is Icon) {
final title = this as Icon;
switch (T) {
case String:
if (title.icon?.codePoint == null) return null;
return String.fromCharCode(title.icon!.codePoint) as T?;
case InlineSpan:
return TextSpan(
text: String.fromCharCode(title.icon!.codePoint),
style: title.getProperty<TextStyle>(),
) as T?;
case TextStyle:
return TextStyle(
color: title.color,
fontSize: title.size,
fontFamily: title.icon?.fontFamily,
package: title.icon?.fontPackage,
) as T?;
case TextAlign:
return null;
case TextHeightBehavior:
return null;
case TextWidthBasis:
return null;
}
}
return null;
}