flutter - Flutter 中的 LinearPercentIndicator

标签 flutter dart indicator

我打算使用指示器显示我的最终分数。

这是代码:

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/

相关文章:

在查看后台运行的应用程序时显示的 flutter 更改图标

user-interface - 为什么当我点击它时切换 Flutter 没有改变值,而只是在拖动时?

flutter - 如何在 Flutter 中更新现有文件(Path_Provider)

flutter - 如何将 Flutter 标签栏指示器更改为与 google play store 完全相同

iphone - 即使表比 View 大,TableViewController 也不会闪烁滚动指示器

listview - flutter 调整ListView child 的宽度

flutter - RXDART CombinelastStream函数不起作用

json - 解析JSON以转换为Model类

flutter - 在 Flutter/Dart 中动态更改按钮的背景颜色

python - 将指标函数应用于列表