首页 > 解决方案 > 如何知道 animated_text_kit 包中当前正在播放的文本?

问题描述

我想弄清楚但我不知道

这是我的代码,几乎相同的示例代码

SizedBox(
  width: 250.0,
  child: TypewriterAnimatedTextKit(
    onTap: () {},
    text: ['aaaaa','bbbbb','ccccc','ddddd'],
    textStyle: TextStyle(
      color: kBlueGray,
      fontSize: 20.sp,
    ),
    speed: Duration(milliseconds: 550),
    textAlign: TextAlign.start,
  ),
),

文本列表实际上是搜索的关键字。所以我想让用户在没有文本字段输入的情况下进行搜索。

标签: flutter

解决方案


这是我的答案

List<String> animatedTextList = ["Iron man", "Superman", "Joker", "Hulk", "Dude"];
String currentAnimatedText;

  @override
  void initState() {
    currentAnimatedText = animatedTextList[0];
    super.initState();
  }

**********

SizedBox(
    width: 0.60.sw,
    child: Padding(
      padding: EdgeInsets.all(4.h),
      child: SizedBox(
        width: 250.0,
        child: TypewriterAnimatedTextKit(
          onNext: (value, value2) {
            currentAnimatedText =
                animatedTextList[value + 1];
            print(currentAnimatedText);
          },
          onTap: () {
            print(currentAnimatedText);
          },
          text: animatedTextList,
          textStyle: TextStyle(
            color: kBlueGray,
            fontSize: 20.sp,
          ),
          speed: Duration(milliseconds: 550),
          textAlign: TextAlign.start,
        ),
      ),
    ),
    ),

推荐阅读