【发布时间】:2019-09-07 01:27:55
【问题描述】:
我正在构建一个广播应用程序。就像在 Spotify 中一样,有一个带有当前标题和艺术家的栏,文本应该在一行中并具有给定的宽度。如何让文本从右到左再向后移动?
在使用自制动画的时候,我想有一个固定的移动文本的速度,所以我需要文本小部件的时间和宽度。
是否有执行此操作的包/内置选项? 还是我必须使用自制动画?如果是这样,我怎样才能获得文本小部件的宽度?
控制器和动画:
AnimationController(duration: Duration(seconds: 10), vsync: this);
animation = Tween<double>(begin: 0, end: 1)
.animate(CurvedAnimation(parent: _controller, curve: Curves.linear));
animation.addListener(() {
setState(() {});
});
_controller.repeat();
构建方法
double value =
-300 * (animation.value <= 0.5 ? animation.value : 1 - animation.value);
return Container(
child: SizedBox(
width: widget.width,
height: 24,
child: Transform.translate(
offset: Offset(value, 0),
child: widget.text,
),
),
);
【问题讨论】:
标签: text flutter flutter-layout flutter-animation