Я создаю приложение для радио. Как и в 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,
),
),
);