如何实现页面指示器根据计算百分比填充颜色?

问题描述 投票:0回答:1

it is page indicator ,which is filled with a color in specific percent, based on completing each section, and the percentage is show there ](https://i.stack.imgur.com/Tghlx.jpg)

我正在使用颤振。我的问题是,我想要如图所示的页面指示器和百分比。每一项都填充了特定的百分比值。而且有时一页指示器依赖多个页面,所以需要根据页数填充指示器。

flutter percentage flutter-pageview linearprogressindicator
1个回答
0
投票

创建一个变量

int totalScreen= 14;
并创建一个计算当前进度的方法:

 double calculateProgress() {
      int currentScreen=  13;

      return currentScreen/ totalScreen;
    }

然后根据您的代码使用它,对于我的场景,我使用了

LinearProgressIndicator
并将我的方法传递给
value
字段。

 LinearProgressIndicator(
                  value: calculateProgress(),
                  valueColor: const AlwaysStoppedAnimation<Color>(Majorella),
                  backgroundColor: Colors.grey.withOpacity(0.3),
                ),

© www.soinside.com 2019 - 2024. All rights reserved.