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