【问题标题】:Flutter LinearPercentIndicator use the animation duration on my functionFlutter LinearPercentIndicator 在我的函数上使用动画持续时间
【发布时间】:2022-01-19 08:54:47
【问题描述】:

我有一个线性百分比指示器,其中有一个百分比和一个动画持续时间,动画持续时间设置为 api 返回的任何计时器 * 1000,因为动画持续时间接受毫秒,在我的函数中,如果用户获得在特定时间内回答正确,例如,如果 api 以 60 秒的时间返回,如果用户在 1 秒到 20 秒内得到正确的答案,那么他将获得 3 星评级,从 21 到 40 秒 2 星评级,从 41 到60 和正确的答案,他得到 1 星评级。现在在函数中,唯一的条件是如果用户得到正确或错误的答案,我需要在那里设置一个计时器,具体取决于用户完成问题的时间以及他选择的正确或错误答案。他的评分取决于时间和正确或错误的答案。

                     child: Container(
                        height: 30,
                        child: RotatedBox(
                          quarterTurns: -2,
                          child: LinearPercentIndicator(  // the linearPercentIndicator
                            animation: true,
                            width: 320.0,
                            lineHeight: 12.0,
                            percent: 1.0,
                            animationDuration: data[widget.CurrentIndex].timer * 1000,
                            backgroundColor: Colors.pink.shade200,
                            progressColor: Colors.pink.shade400,
                          ),
                        ),
                      ),

                                    String joinedWords =
                                    selectedWords.join(" ").toString();

                                    String _setRatingInAlert() {  // the function witch i want to 
                                                                     use the animation duration
                                      if (joinedWords ==
                                          data[widget.CurrentIndex].sentence) {
                                        starsRating =
                                        'assets/threestars_small.png';
                                      } else {
                                        starsRating =
                                        'assets/onestar_small.png';
                                      }
                                      return starsRating;
                                    }

【问题讨论】:

    标签: flutter dart flutter-layout


    【解决方案1】:

    -> 使用这个容器

     Container(
                height: 30,
                child: LinearPercentIndicator(
                  animation: true,
                  width: 320.0,
                  restartAnimation: true,
                  alignment:  MainAxisAlignment.start,
                  lineHeight: 12.0,
                  percent: 1.0,
                  animationDuration:3000,
                  backgroundColor: Colors.red,
                  progressColor: Colors.black38,
                ),
              ),
    

    【讨论】:

    • 这将如何帮助我实现我在描述中提出的要求
    • 你的代码动画持续时间是 int 值
    • 你正在转换 int 值
    • 它是 int data[widget.CurrentIndex].timer 返回一个 int
    • 阅读我需要的描述
    猜你喜欢
    • 2019-10-30
    • 1970-01-01
    • 2023-03-14
    • 2018-06-15
    • 2014-03-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-19
    相关资源
    最近更新 更多