flutter LinearPercentIndicator在每次更改百分比值时重置动画

gijlo24d  于 2023-05-19  发布在  Flutter
关注(0)|答案(1)|浏览(195)

我使用线性百分比指示器作为进度条。每次更改此百分比值时,动画都会从0变为当前进度数。我希望动画从上一个进度号到当前进度号。
如果没有动画,则该条进行正确的“跳转”(从最后一个数字到当前数字),但是需要动画。
问题是如何的GIF:

它应该是:

我的代码:

Consumer<ProgressBarProvider>(
 builder: (BuildContext context, value, Widget? child) {
   return LinearPercentBar:
      Center(
         child: LinearPercentIndicator(
              animation: true,
              progressColor: Theme.of(context).primaryColor,
              backgroundColor: Color.fromRGBO(217, 217, 217, 1),
              percent: value.getPercentProgress,
              lineHeight: 15,
              linearStrokeCap: LinearStrokeCap.roundAll,
              barRadius: Radius.circular(30),
              restartAnimation: false,
       )
   );
}

我使用Provider库来管理百分比和项目数变量的状态。
我想知道我如何离开动画从一个数字到下一个没有动画去所有的方式,以目前的数字

cgvd09ve

cgvd09ve1#

我解决了!我只需要添加参数

animateFromLastPercent: true,

转换成线性百分比指示器。是这样的:

LinearPercentIndicator(
      animation: true,
      animationDuration: 500,
      animateFromLastPercent: true,
      progressColor: Theme.of(context).primaryColor,
      backgroundColor: Color.fromRGBO(217, 217, 217, 1),
      percent: value.getPercentProgress,
      lineHeight: 15,
      linearStrokeCap: LinearStrokeCap.roundAll,
      barRadius: Radius.circular(30),
      restartAnimation: false,
)

相关问题