gpt4 book ai didi

flutter - Flutter 中的 LinearPercentIndicator

转载 作者:行者123 更新时间:2023-12-03 02:55:01 33 4
gpt4 key购买 nike

我打算使用指标显示我的最终分数。
这是代码:

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/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com