作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我打算使用指标显示我的最终分数。
这是代码:
LinearPercentIndicator(
width: MediaQuery.of(context).size.width - 50,
animation: true,
lineHeight: 25.0,
animationDuration: 2500,
percent: 0.0,
center: Text('$finalD'),
linearStrokeCap: LinearStrokeCap.roundAll,
progressColor: Colors.yellow,
),
如何更改
百分比 在 $finalD 中保存值?
最佳答案
根据您的代码,这就是我已经实现的,让我知道它是否有效或者您想要任何:
import 'package:flutter/material.dart';
import 'package:percent_indicator/linear_percent_indicator.dart';
void main() => runApp(MyApp());
class MyApp extends StatefulWidget {
MyApp({Key key}) : super(key: key);
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: SafeArea(child: SampleApp()),
),
);
}
}
class SampleApp extends StatefulWidget {
SampleApp({Key key}) : super(key: key);
@override
_SampleAppState createState() => _SampleAppState();
}
class _SampleAppState extends State<SampleApp> {
String finalD = '';
double percentage;
@override
void initState() {
// TODO: implement initState
super.initState();
//This is you value 10 where you divide by 100 then you get the value
// between 0 -1 which is expected by the linerprogressindicator
percentage = 10 /100; // Here you get your percentage and the assign it to the percentage
finalD = (percentage*100).toString(); // here you asign to the String
// or convert it to int as :finalD =(percentage * 100).toInt().toString();
}
@override
Widget build(BuildContext context) {
return Container(
child: Center(
child: LinearPercentIndicator(
width: MediaQuery.of(context).size.width - 50,
animation: true,
lineHeight: 25.0,
animationDuration: 2500,
percent: percentage,
center: Text('$finalD'),
linearStrokeCap: LinearStrokeCap.roundAll,
progressColor: Colors.yellow,
),
),
);
}
}
关于flutter - Flutter 中的 LinearPercentIndicator,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62642995/
我打算使用指标显示我的最终分数。 这是代码: LinearPercentIndicator( width: MediaQuery.of(context).size.
我是一名优秀的程序员,十分优秀!