flutter - 如何根据百分比指示器更改文本

标签 flutter dart

我有一个百分比指示器,我想在其属性为9.0时在带有百分比类型(如90%)的文本小部件中显示其百分比
这样的事情。如您所见,它的百分比超出了其区域,它显示了当前百分比
enter image description here
这是我的指标:

  child: LinearPercentIndicator(
              width: MediaQuery.of(context).size.width - 50,
              animation: true,
              lineHeight: 6.0,
              animationDuration: 2000,
              percent: 0.6,
              linearStrokeCap: LinearStrokeCap.roundAll,
              backgroundColor: Color(0xffD2D9EC),
            ),
我想将percent: 0.6,转换为int。然后在文本小部件中显示它,而我想做的恰恰相反。这意味着我想将int转换为double并以指标百分比显示。我想更改一次,就像用户进入页面时一样。从API中获取并在其中显示。

最佳答案

var percentValue = 0.6;

child: LinearPercentIndicator(
              width: MediaQuery.of(context).size.width - 50,
              animation: true,
              lineHeight: 6.0,
              animationDuration: 2000,
              percent: percentValue,
              linearStrokeCap: LinearStrokeCap.roundAll,
              backgroundColor: Color(0xffD2D9EC),
            ),


Text(_determineText(percentValue), style: TextStyle(color: Colors.black))


_determineText(percentValue){
 var value = percentValue * 100; //0.6 -> 60
 return (‘%’+(value.toString());
}

关于flutter - 如何根据百分比指示器更改文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64443610/

相关文章:

flutter - Dart 围绕一个人物,但作为 double

android - flutter nfc 插件只扫描一次

flutter - 产生 RenderBox 溢出的英雄动画

android - 尝试播放 flutter dart 时视频缓冲

android - flutter : How to Fix SuffixIcon at the bottom of the Multiline Enable TextField?

text - 如何使用 MediaQuery 为 Flutter 中的文本设置 scaleFactor?

android - Flutter:如何修复 "A RenderFlex overflowed by pixels "错误?

firebase - Flutter中创建文档后返回新创建的Document ID

flutter - 如何改变复选框的状态?

flutter - 我无法向您的应用添加耀斑闪屏