diff --git a/lib/src/colorize.dart b/lib/src/colorize.dart index 01850f4..9cf612e 100644 --- a/lib/src/colorize.dart +++ b/lib/src/colorize.dart @@ -15,7 +15,7 @@ class ColorizeAnimatedTextKit extends StatefulWidget { /// Define the [Duration] of the pause between texts /// - /// By default it is set to 500 milliseconds. + /// By default it is set to 1000 milliseconds. final Duration pause; /// Adds the onTap [VoidCallback] to the animated widget. @@ -62,22 +62,31 @@ class ColorizeAnimatedTextKit extends StatefulWidget { /// The [List] should contain at least two values of [Color] in it. final List colors; - const ColorizeAnimatedTextKit( - {Key key, - @required this.text, - this.textStyle, - @required this.colors, - this.speed, - this.pause, - this.onTap, - this.onNext, - this.onFinished, - this.alignment = AlignmentDirectional.topStart, - this.textAlign = TextAlign.start, - this.totalRepeatCount = 3, - this.repeatForever = false, - this.isRepeatingAnimation = true}) - : super(key: key); + const ColorizeAnimatedTextKit({ + Key key, + @required this.text, + this.textStyle, + @required this.colors, + this.speed = const Duration(milliseconds: 200), + this.pause = const Duration(milliseconds: 1000), + this.onTap, + this.onNext, + this.onFinished, + this.alignment = AlignmentDirectional.topStart, + this.textAlign = TextAlign.start, + this.totalRepeatCount = 3, + this.repeatForever = false, + this.isRepeatingAnimation = true, + }) : assert(null != text), + assert(null != colors && colors.length > 1), + assert(null != speed), + assert(null != pause), + assert(null != alignment), + assert(null != textAlign), + assert(null != totalRepeatCount), + assert(null != repeatForever), + assert(null != isRepeatingAnimation), + super(key: key); @override _ColorizeTextState createState() => _ColorizeTextState(); @@ -86,17 +95,15 @@ class ColorizeAnimatedTextKit extends StatefulWidget { class _ColorizeTextState extends State with TickerProviderStateMixin { AnimationController _controller; + Timer _timer; - Animation _colorShifter, _fadeIn, _fadeOut; + Animation _colorShifter, _fadeIn, _fadeOut; double _tuning; - Duration _speed; - Duration _pause; - - List _texts = []; - int _index; + final _textCharacters = []; + bool _isCurrentlyPausing = false; int _currentRepeatCount; @@ -105,22 +112,21 @@ class _ColorizeTextState extends State void initState() { super.initState(); - _speed = widget.speed ?? const Duration(milliseconds: 200); - _pause = widget.pause ?? const Duration(milliseconds: 1000); - _index = -1; - _currentRepeatCount = 0; - widget.text.forEach((text) { - _texts.add({'text': text, 'speed': _speed, 'pause': _pause}); + _textCharacters.add(text.characters); }); + _currentRepeatCount = 0; + _nextAnimation(); } @override void dispose() { + _timer?.cancel(); + _controller?.stop(); _controller?.dispose(); super.dispose(); } @@ -131,25 +137,25 @@ class _ColorizeTextState extends State onTap: widget.onTap, child: _isCurrentlyPausing || !_controller.isAnimating ? Text( - _texts[_index]['text'], + widget.text[_index], style: widget.textStyle, textAlign: widget.textAlign, ) : AnimatedBuilder( animation: _controller, builder: (BuildContext context, Widget child) { - Shader linearGradient = LinearGradient(colors: widget.colors) - .createShader( - Rect.fromLTWH(0.0, 0.0, _colorShifter.value, 0.0)); + final linearGradient = + LinearGradient(colors: widget.colors).createShader( + Rect.fromLTWH(0.0, 0.0, _colorShifter.value, 0.0), + ); return Opacity( opacity: _fadeIn.value != 1.0 ? _fadeIn.value : _fadeOut.value, child: Text( - _texts[_index]['text'], - style: widget.textStyle != null - ? widget.textStyle.merge(TextStyle( - foreground: Paint()..shader = linearGradient)) - : widget.textStyle, + widget.text[_index], + style: widget.textStyle?.merge( + TextStyle(foreground: Paint()..shader = linearGradient), + ), textAlign: widget.textAlign, ), ); @@ -159,7 +165,7 @@ class _ColorizeTextState extends State } void _nextAnimation() { - final bool isLast = _index == widget.text.length - 1; + final isLast = _index == widget.text.length - 1; _isCurrentlyPausing = false; @@ -186,30 +192,38 @@ class _ColorizeTextState extends State if (mounted) setState(() {}); + final textLen = _textCharacters[_index].length; _controller = AnimationController( - duration: _texts[_index]['speed'] * _texts[_index]['text'].length, + duration: widget.speed * textLen, vsync: this, ); _tuning = (300.0 * widget.colors.length) * (widget.textStyle.fontSize / 24.0) * 0.75 * - (_texts[_index]['text'].length / 15.0); + (textLen / 15.0); - _fadeIn = Tween(begin: 0.0, end: 1.0).animate(CurvedAnimation( + _fadeIn = Tween(begin: 0.0, end: 1.0).animate( + CurvedAnimation( parent: _controller, - curve: const Interval(0.0, 0.1, curve: Curves.easeOut))); + curve: const Interval(0.0, 0.1, curve: Curves.easeOut), + ), + ); - _fadeOut = Tween(begin: 1.0, end: 1.0).animate(CurvedAnimation( + _fadeOut = Tween(begin: 1.0, end: 1.0).animate( + CurvedAnimation( parent: _controller, - curve: const Interval(0.9, 1.0, curve: Curves.easeIn))); + curve: const Interval(0.9, 1.0, curve: Curves.easeIn), + ), + ); _colorShifter = Tween(begin: 0.0, end: widget.colors.length * _tuning).animate( - CurvedAnimation( - parent: _controller, - curve: const Interval(0.0, 1.0, curve: Curves.easeIn))) - ..addStatusListener(_animationEndCallback); + CurvedAnimation( + parent: _controller, + curve: const Interval(0.0, 1.0, curve: Curves.easeIn), + ), + )..addStatusListener(_animationEndCallback); _controller?.forward(); } @@ -217,7 +231,8 @@ class _ColorizeTextState extends State void _animationEndCallback(state) { if (state == AnimationStatus.completed) { _isCurrentlyPausing = true; - Timer(_texts[_index]['pause'], _nextAnimation); + assert(null == _timer || !_timer.isActive); + _timer = Timer(widget.pause, _nextAnimation); } } } diff --git a/lib/src/fade.dart b/lib/src/fade.dart index 98ed56d..68ddf17 100644 --- a/lib/src/fade.dart +++ b/lib/src/fade.dart @@ -110,12 +110,10 @@ class FadeAnimatedTextKit extends StatefulWidget { class _FadeTextState extends State with SingleTickerProviderStateMixin { - Animation _fadeIn, _fadeOut; + Animation _fadeIn, _fadeOut; AnimationController _controller; - final _texts = >[]; - int _index; bool _isCurrentlyPausing = false; @@ -132,13 +130,6 @@ class _FadeTextState extends State _currentRepeatCount = 0; - widget.text.forEach((text) { - _texts.add({ - 'text': text, - 'pause': widget.pause, - }); - }); - _initAnimation(); _nextAnimation(); } @@ -154,7 +145,7 @@ class _FadeTextState extends State @override Widget build(BuildContext context) { final textWidget = Text( - _texts[_index]['text'], + widget.text[_index], style: widget.textStyle, textAlign: widget.textAlign, ); @@ -198,7 +189,7 @@ class _FadeTextState extends State } void _nextAnimation() { - final bool isLast = _index == widget.text.length - 1; + final isLast = _index == widget.text.length - 1; _isCurrentlyPausing = false; @@ -229,7 +220,7 @@ class _FadeTextState extends State } void _setPause() { - final bool isLast = _index == widget.text.length - 1; + final isLast = _index == widget.text.length - 1; _isCurrentlyPausing = true; if (mounted) setState(() {}); @@ -242,7 +233,7 @@ class _FadeTextState extends State if (state == AnimationStatus.completed) { _isCurrentlyPausing = true; assert(null == _timer || !_timer.isActive); - _timer = Timer(_texts[_index]['pause'], _nextAnimation); + _timer = Timer(widget.pause, _nextAnimation); } } @@ -254,16 +245,20 @@ class _FadeTextState extends State _nextAnimation(); } } else { - final int pause = _texts[_index]['pause'].inMilliseconds; - final int left = widget.duration.inMilliseconds; - _controller?.stop(); _setPause(); assert(null == _timer || !_timer.isActive); - _timer = - Timer(Duration(milliseconds: max(pause, left)), _nextAnimation); + _timer = Timer( + Duration( + milliseconds: max( + widget.pause.inMilliseconds, + widget.duration.inMilliseconds, + ), + ), + _nextAnimation, + ); } } diff --git a/lib/src/rotate.dart b/lib/src/rotate.dart index 6331c36..8f1db95 100644 --- a/lib/src/rotate.dart +++ b/lib/src/rotate.dart @@ -112,9 +112,8 @@ class _RotatingTextState extends State double _transitionHeight; - Animation _fadeIn, _fadeOut, _slideIn, _slideOut; - - final _texts = >[]; + Animation _fadeIn, _fadeOut; + Animation _slideIn, _slideOut; int _index; @@ -135,13 +134,6 @@ class _RotatingTextState extends State _currentRepeatCount = 0; - widget.text.forEach((text) { - _texts.add({ - 'text': text, - 'pause': widget.pause, - }); - }); - _initAnimation(); _nextAnimation(); } @@ -157,7 +149,7 @@ class _RotatingTextState extends State @override Widget build(BuildContext context) { final textWidget = Text( - _texts[_index]['text'], + widget.text[_index], style: widget.textStyle, textAlign: widget.textAlign, ); @@ -246,7 +238,7 @@ class _RotatingTextState extends State } void _nextAnimation() { - final bool isLast = _index == widget.text.length - 1; + final isLast = _index == widget.text.length - 1; _isCurrentlyPausing = false; @@ -277,7 +269,7 @@ class _RotatingTextState extends State } void _setPause() { - final bool isLast = _index == widget.text.length - 1; + final isLast = _index == widget.text.length - 1; _isCurrentlyPausing = true; if (mounted) setState(() {}); @@ -289,7 +281,7 @@ class _RotatingTextState extends State void _animationEndCallback(state) { if (state == AnimationStatus.completed) { assert(null == _timer || !_timer.isActive); - _timer = Timer(_texts[_index]['pause'], _nextAnimation); + _timer = Timer(widget.pause, _nextAnimation); } } @@ -304,7 +296,7 @@ class _RotatingTextState extends State _setPause(); assert(null == _timer || !_timer.isActive); - _timer = Timer(_texts[_index]['pause'], _nextAnimation); + _timer = Timer(widget.pause, _nextAnimation); } } diff --git a/lib/src/scale.dart b/lib/src/scale.dart index 5a239fd..fae0aee 100644 --- a/lib/src/scale.dart +++ b/lib/src/scale.dart @@ -119,9 +119,7 @@ class _ScaleTextState extends State with SingleTickerProviderStateMixin { AnimationController _controller; - Animation _fadeIn, _fadeOut, _scaleIn, _scaleOut; - - final _texts = >[]; + Animation _fadeIn, _fadeOut, _scaleIn, _scaleOut; int _index; @@ -139,13 +137,6 @@ class _ScaleTextState extends State _currentRepeatCount = 0; - widget.text.forEach((text) { - _texts.add({ - 'text': text, - 'pause': widget.pause, - }); - }); - // init controller and animations _initAnimation(); // Start animation @@ -163,7 +154,7 @@ class _ScaleTextState extends State @override Widget build(BuildContext context) { final textWidget = Text( - _texts[_index]['text'], + widget.text[_index], style: widget.textStyle, textAlign: widget.textAlign, ); @@ -223,7 +214,7 @@ class _ScaleTextState extends State } void _nextAnimation() { - final bool isLast = _index == widget.text.length - 1; + final isLast = _index == widget.text.length - 1; _isCurrentlyPausing = false; @@ -254,7 +245,7 @@ class _ScaleTextState extends State } void _setPause() { - final bool isLast = _index == widget.text.length - 1; + final isLast = _index == widget.text.length - 1; _isCurrentlyPausing = true; setState(() {}); @@ -267,7 +258,7 @@ class _ScaleTextState extends State if (state == AnimationStatus.completed) { _isCurrentlyPausing = true; assert(null == _timer || !_timer.isActive); - _timer = Timer(_texts[_index]['pause'], _nextAnimation); + _timer = Timer(widget.pause, _nextAnimation); } } @@ -279,16 +270,20 @@ class _ScaleTextState extends State _nextAnimation(); } } else { - final int pause = _texts[_index]['pause'].inMilliseconds; - final int left = widget.duration.inMilliseconds; - _controller.stop(); _setPause(); assert(null == _timer || !_timer.isActive); - _timer = - Timer(Duration(milliseconds: max(pause, left)), _nextAnimation); + _timer = Timer( + Duration( + milliseconds: max( + widget.pause.inMilliseconds, + widget.duration.inMilliseconds, + ), + ), + _nextAnimation, + ); } } diff --git a/lib/src/text_liquid_fill.dart b/lib/src/text_liquid_fill.dart index 7eea31c..65cb31d 100644 --- a/lib/src/text_liquid_fill.dart +++ b/lib/src/text_liquid_fill.dart @@ -78,7 +78,7 @@ class _TextLiquidFillState extends State AnimationController _waveController, _loadController; - Animation _loadValue; + Animation _loadValue; @override void initState() { @@ -94,7 +94,13 @@ class _TextLiquidFillState extends State duration: widget.loadDuration, ); - _loadValue = Tween(begin: 0.0, end: 100.0).animate(_loadController); + _loadValue = Tween(begin: 0.0, end: 100.0).animate(_loadController) + ..addStatusListener((status) { + if (AnimationStatus.completed == status) { + // Stop the repeating wave when the load has completed + _waveController.stop(); + } + }); _waveController.repeat(); _loadController.forward(); @@ -186,7 +192,7 @@ class WavePainter extends CustomPainter { final height = size.height ?? 200; final path = Path(); path.moveTo(0.0, baseHeight); - for (double i = 0.0; i < width; i++) { + for (var i = 0.0; i < width; i++) { path.lineTo( i, baseHeight + sin((i / width * _pi2) + (waveAnimation.value * _pi2)) * 8, diff --git a/lib/src/typer.dart b/lib/src/typer.dart index 6da7bc7..5e46ca6 100644 --- a/lib/src/typer.dart +++ b/lib/src/typer.dart @@ -95,12 +95,12 @@ class TyperAnimatedTextKit extends StatefulWidget { class _TyperState extends State with TickerProviderStateMixin { AnimationController _controller; - Animation _typingText; - - final _texts = >[]; + Animation _typingText; int _index; + final _textCharacters = []; + bool _isCurrentlyPausing = false; Timer _timer; @@ -112,12 +112,7 @@ class _TyperState extends State _index = -1; widget.text.forEach((text) { - _texts.add({ - 'text': text, - 'chars': text.characters, - 'speed': widget.speed, - 'pause': widget.pause, - }); + _textCharacters.add(text.characters); }); // Start animation @@ -134,7 +129,7 @@ class _TyperState extends State @override Widget build(BuildContext context) { - final text = _texts[_index]['text']; + final text = widget.text[_index]; return GestureDetector( onTap: _onTap, child: _isCurrentlyPausing || !_controller.isAnimating @@ -146,9 +141,9 @@ class _TyperState extends State : AnimatedBuilder( animation: _controller, builder: (BuildContext context, Widget child) { - final textCharacters = _texts[_index]['chars']; + final textCharacters = _textCharacters[_index]; final textLen = textCharacters.length; - final int offset = + final offset = textLen < _typingText.value ? textLen : _typingText.value; return Text( @@ -162,7 +157,7 @@ class _TyperState extends State } void _nextAnimation() { - final bool isLast = _index == widget.text.length - 1; + final isLast = _index == widget.text.length - 1; _isCurrentlyPausing = false; @@ -184,9 +179,9 @@ class _TyperState extends State if (mounted) setState(() {}); - final textLen = _texts[_index]['chars'].length; + final textLen = _textCharacters[_index].length; _controller = AnimationController( - duration: _texts[_index]['speed'] * textLen, + duration: widget.speed * textLen, vsync: this, ); @@ -197,7 +192,7 @@ class _TyperState extends State } void _setPause() { - final bool isLast = _index == widget.text.length - 1; + final isLast = _index == widget.text.length - 1; _isCurrentlyPausing = true; if (mounted) setState(() {}); @@ -210,7 +205,7 @@ class _TyperState extends State if (state == AnimationStatus.completed) { _setPause(); assert(null == _timer || !_timer.isActive); - _timer = Timer(_texts[_index]['pause'], _nextAnimation); + _timer = Timer(widget.pause, _nextAnimation); } } @@ -222,17 +217,23 @@ class _TyperState extends State _nextAnimation(); } } else { - final int pause = _texts[_index]['pause'].inMilliseconds; - final int left = _texts[_index]['speed'].inMilliseconds * - (_texts[_index]['chars'].length - _typingText.value); + final left = widget.speed.inMilliseconds * + (_textCharacters[_index].length - _typingText.value); _controller.stop(); _setPause(); assert(null == _timer || !_timer.isActive); - _timer = - Timer(Duration(milliseconds: max(pause, left)), _nextAnimation); + _timer = Timer( + Duration( + milliseconds: max( + widget.pause.inMilliseconds, + left, + ), + ), + _nextAnimation, + ); } } diff --git a/lib/src/typewriter.dart b/lib/src/typewriter.dart index a248e72..c3c9c53 100644 --- a/lib/src/typewriter.dart +++ b/lib/src/typewriter.dart @@ -111,12 +111,12 @@ class _TypewriterState extends State with TickerProviderStateMixin { AnimationController _controller; - Animation _typewriterText; - - final _texts = >[]; + Animation _typewriterText; int _index; + final _textCharacters = []; + bool _isCurrentlyPausing = false; Timer _timer; @@ -132,12 +132,7 @@ class _TypewriterState extends State _currentRepeatCount = 0; widget.text.forEach((text) { - _texts.add({ - 'text': text, - 'chars': text.characters, - 'speed': widget.speed, - 'pause': widget.pause, - }); + _textCharacters.add(text.characters); }); _nextAnimation(); @@ -153,7 +148,7 @@ class _TypewriterState extends State @override Widget build(BuildContext context) { - final text = _texts[_index]['text']; + final text = widget.text[_index]; return GestureDetector( onTap: _onTap, child: _isCurrentlyPausing || !_controller.isAnimating @@ -173,14 +168,14 @@ class _TypewriterState extends State : AnimatedBuilder( animation: _controller, builder: (BuildContext context, Widget child) { - final textCharacters = _texts[_index]['chars']; + final textCharacters = _textCharacters[_index]; final textLen = textCharacters.length; - String visibleString = text; - Color suffixColor = Colors.transparent; + var visibleString = text; + var suffixColor = Colors.transparent; if (_typewriterText.value == 0) { - visibleString = ""; + visibleString = ''; } else if (_typewriterText.value > textLen) { - visibleString = textCharacters.take(textLen).toString(); + visibleString = text; suffixColor = (_typewriterText.value - textLen) % 2 == 0 ? widget.textStyle.color : Colors.transparent; @@ -209,7 +204,7 @@ class _TypewriterState extends State } void _nextAnimation() { - final bool isLast = _index == widget.text.length - 1; + final isLast = _index == widget.text.length - 1; _isCurrentlyPausing = false; @@ -236,21 +231,23 @@ class _TypewriterState extends State if (mounted) setState(() {}); + final textLen = _textCharacters[_index].length; _controller = AnimationController( - duration: _texts[_index]['speed'] * _texts[_index]['text'].length, + duration: widget.speed * textLen, vsync: this, ); - _typewriterText = - StepTween(begin: 0, end: _texts[_index]['text'].length + 8) - .animate(_controller) - ..addStatusListener(_animationEndCallback); + _typewriterText = StepTween( + begin: 0, + end: textLen + 8, + ).animate(_controller) + ..addStatusListener(_animationEndCallback); _controller.forward(); } void _setPause() { - final bool isLast = _index == widget.text.length - 1; + final isLast = _index == widget.text.length - 1; _isCurrentlyPausing = true; if (mounted) setState(() {}); @@ -263,7 +260,7 @@ class _TypewriterState extends State if (state == AnimationStatus.completed) { _setPause(); assert(null == _timer || !_timer.isActive); - _timer = Timer(_texts[_index]['pause'], _nextAnimation); + _timer = Timer(widget.pause, _nextAnimation); } } @@ -275,17 +272,23 @@ class _TypewriterState extends State _nextAnimation(); } } else { - final int pause = _texts[_index]['pause'].inMilliseconds; - final int left = _texts[_index]['speed'].inMilliseconds * - (_texts[_index]['text'].length - _typewriterText.value); + final left = widget.speed.inMilliseconds * + (_textCharacters[_index].length - _typewriterText.value); _controller.stop(); _setPause(); assert(null == _timer || !_timer.isActive); - _timer = - Timer(Duration(milliseconds: max(pause, left)), _nextAnimation); + _timer = Timer( + Duration( + milliseconds: max( + widget.pause.inMilliseconds, + left, + ), + ), + _nextAnimation, + ); } } diff --git a/lib/src/wavy.dart b/lib/src/wavy.dart index ce16e5c..f1854a3 100644 --- a/lib/src/wavy.dart +++ b/lib/src/wavy.dart @@ -120,7 +120,7 @@ class _WavyAnimatedTextKitState extends State } Future _nextAnimation() async { - final bool isLast = _index == widget.text.length - 1; + final isLast = _index == widget.text.length - 1; // Handling onNext callback if (_index > -1) { @@ -153,7 +153,7 @@ class _WavyAnimatedTextKitState extends State } void _setPause() { - final bool isLast = _index == widget.text.length - 1; + final isLast = _index == widget.text.length - 1; if (mounted) setState(() {}); @@ -172,24 +172,23 @@ class _WTextPainter extends CustomPainter { final double progress; final String text; // Private class to store text information - List<_TextLayoutInfo> _textLayoutInfo = []; + final _textLayoutInfo = <_TextLayoutInfo>[]; final TextStyle textStyle; @override void paint(Canvas canvas, Size size) { - if (_textLayoutInfo.length == 0) { + if (_textLayoutInfo.isEmpty) { // calculate the initial position of each char calculateLayoutInfo(text, _textLayoutInfo); } canvas.save(); - if (_textLayoutInfo != null) - for (_TextLayoutInfo textLayout in _textLayoutInfo) { + if (_textLayoutInfo != null) { + for (var textLayout in _textLayoutInfo) { // offset required to center the characters final centerOffset = Offset(size.width / 2, (size.height / 2 - textLayout.height / 2)); if (textLayout.isMoving) { - double p = progress * 2; - p = p > 1 ? 1 : p; + final p = math.min(progress * 2, 1.0); // drawing the char if the text is moving drawText( canvas, @@ -211,6 +210,7 @@ class _WTextPainter extends CustomPainter { ); } } + } canvas.restore(); } @@ -226,11 +226,11 @@ class _WTextPainter extends CustomPainter { } void calculateMove() { - double height = _textLayoutInfo[0].height; - int txtInMoInd = progress.floor(); - double percent = progress - txtInMoInd; - int txtInMoOdd = (progress - .5).floor(); - int txtInMoEven = txtInMoInd * 2; + final height = _textLayoutInfo[0].height; + final txtInMoInd = progress.floor(); + final percent = progress - txtInMoInd; + final txtInMoOdd = (progress - .5).floor(); + final txtInMoEven = txtInMoInd * 2; // Calculating movement of the char at odd place if (txtInMoOdd < (text.length - 1) / 2 && !txtInMoOdd.isNegative) { @@ -252,10 +252,9 @@ class _WTextPainter extends CustomPainter { void drawText(Canvas canvas, String text, Offset offset, _TextLayoutInfo textLayoutInfo) { var textPainter = TextPainter( - text: TextSpan(text: text, style: textStyle), - textDirection: TextDirection.ltr) - ..textDirection = TextDirection.ltr - ..layout(); + text: TextSpan(text: text, style: textStyle), + textDirection: TextDirection.ltr, + )..layout(); textPainter.paint( canvas, @@ -270,30 +269,33 @@ class _WTextPainter extends CustomPainter { list.clear(); // creating a textPainter to get data about location and offset for chars - TextPainter textPainter = TextPainter( + final textPainter = TextPainter( text: TextSpan(text: text, style: textStyle), textDirection: TextDirection.ltr, maxLines: 1, ); textPainter.layout(); - for (int i = 0; i < text.length; i++) { - var forCaret = - textPainter.getOffsetForCaret(TextPosition(offset: i), Rect.zero); + for (var i = 0; i < text.length; i++) { + var forCaret = textPainter.getOffsetForCaret( + TextPosition(offset: i), + Rect.zero, + ); var offsetX = forCaret.dx; if (i > 0 && offsetX == 0) { break; } // creating layout for each char - var textLayoutInfo = _TextLayoutInfo() - ..text = text[i] - ..offsetX = offsetX - ..offsetY = forCaret.dy - ..width = textPainter.width - ..height = textPainter.height - ..baseline = textPainter - .computeDistanceToActualBaseline(TextBaseline.ideographic); + final textLayoutInfo = _TextLayoutInfo( + text: text[i], + offsetX: offsetX, + offsetY: forCaret.dy, + width: textPainter.width, + height: textPainter.height, + baseline: textPainter + .computeDistanceToActualBaseline(TextBaseline.ideographic), + ); list.add(textLayoutInfo); } @@ -301,12 +303,21 @@ class _WTextPainter extends CustomPainter { } class _TextLayoutInfo { - String text; - double offsetX; - double offsetY; - double baseline; - double width; - double height; + final String text; + final double offsetX; + final double offsetY; + final double width; + final double height; + final double baseline; double riseHeight; bool isMoving = false; + + _TextLayoutInfo({ + @required this.text, + @required this.offsetX, + @required this.offsetY, + @required this.width, + @required this.height, + @required this.baseline, + }); }