animatedBuilder method
Widget showing partial text
Implementation
@override
Widget animatedBuilder(BuildContext context, Widget? child) {
/// Output of CurveTween is in the range [0, 1] for majority of the curves.
/// It is converted to [0, textCharacters.length + extraLengthForBlinks].
final textLen = textCharacters.length;
final typewriterValue = (_typewriterText.value.clamp(0, 1) *
(textCharacters.length + extraLengthForBlinks))
.round();
var showCursor = true;
var visibleString = text;
if (typewriterValue == 0) {
visibleString = '';
showCursor = false;
} else if (typewriterValue > textLen) {
showCursor = (typewriterValue - textLen) % 2 == 0;
} else {
visibleString = textCharacters.take(typewriterValue).toString();
}
return RichText(
text: TextSpan(
children: [
TextSpan(text: visibleString),
TextSpan(
text: cursor,
style:
showCursor ? null : const TextStyle(color: Colors.transparent),
)
],
style: DefaultTextStyle.of(context).style.merge(textStyle),
),
textAlign: textAlign,
);
}