Dart 如何在颤振中制作进度条?
我正在努力使电弧进度条在颤振。 下图是我想要实现的目标 我只能在Flatter的小部件目录中找到Dart 如何在颤振中制作进度条?,dart,flutter,Dart,Flutter,我正在努力使电弧进度条在颤振。 下图是我想要实现的目标 我只能在Flatter的小部件目录中找到CircularProgressIndicator 我厌倦了下面的包裹 但无法实现arc进度条 如果您有任何帮助,我们将不胜感激。您可以像这样使用Circularpercenticator: @override Widget build(BuildContext context) { double yourPercentage = 0.5;
CircularProgressIndicator
我厌倦了下面的包裹
但无法实现arc进度条
如果您有任何帮助,我们将不胜感激。您可以像这样使用
Circularpercenticator
:
@override
Widget build(BuildContext context) {
double yourPercentage = 0.5;
return Scaffold(
body: Center(
child: CircularPercentIndicator(
radius: 100.0,
startAngle: 220,
percent: 0.775 * yourPercentage,
animation: true,
backgroundColor: Colors.transparent,
center: Text("50%"),
),
),
);
}
只需根据需要更改yourPercentage
变量即可
更新(2019年5月16日)
我更新了我的代码(尚未在pub上发布),但您可以这样使用:
在pubspec.yaml中
percent_indicator:
git:
url: https://github.com/diegoveloper/flutter_percent_indicator.git
代码
说明:您可以在堆栈中使用两个
circularProgressIndicator
小部件和一个Text小部件
,并向circularProgressIndicator
提供值,使其成为弧形进度条
这是我的回购计划
import 'package:flutter/material.dart';
class DownloadProgressIndicator extends StatelessWidget {
DownloadProgressIndicator({
this.color =Colors.blue,
this.backgroundColor = Colors.black12,
this.content,
this.value,
this.strokeWidth = 4.0,
});
final Color color;
final Color backgroundColor;
final Widget content;
final double value;
final double strokeWidth;
@override
Widget build(BuildContext context) {
return Stack(
fit: StackFit.expand,
children: <Widget>[
backgroundColor != null ?
CircularProgressIndicator(
valueColor: AlwaysStoppedAnimation(backgroundColor),
value: 1,
strokeWidth: strokeWidth,
): Container(),
CircularProgressIndicator(
valueColor: AlwaysStoppedAnimation(color),
value: value,
strokeWidth: strokeWidth,
),
content != null ?
Center(
child: content,
) : Container(),
],
);
}
}
导入“包装:颤振/材料.省道”;
类DownloadProgressIndicator扩展了无状态小部件{
下载进度指示器({
this.color=Colors.blue,
this.backgroundColor=Colors.black12,
这个.内容,,
这个,这个价值,,
该值为0.strokeWidth=4.0,
});
最终颜色;
最终颜色背景色;
最终小部件内容;
最终双值;
最终双冲程宽度;
@凌驾
小部件构建(构建上下文){
返回堆栈(
fit:StackFit.expand,
儿童:[
背景颜色!=空?
循环压缩机指示器(
valueColor:AlwaysStoppedAnimation(背景色),
价值:1,
strokeWidth:strokeWidth,
):Container(),
循环压缩机指示器(
valueColor:AlwaysStoppedAnimation(颜色),
价值:价值,
strokeWidth:strokeWidth,
),
内容!=空?
居中(
孩子:内容,
):Container(),
],
);
}
}
将所需的进度作为值传递
。如果您需要从不同角度开始圆弧,可以将此小部件放入Transform.rotate
小部件中。不确切,但它会解决你的问题
更新:在观察你的图像之后
您可以将一些值传递给背景循环压缩器指示器,然后将其从底部开始旋转。
假设你的背景弧从0到75。现在你需要标准化你的进度值(例如值*75/100),这样你的前台进度指示器的进度值就会在0到75英尺之间。也可以旋转前景弧。您可以使用类似下面的Flitter CustomPaint类来实现这一点。
这将形成与您在图像链接中共享的弧相同的弧。
这里,百分比值可以是0-0.7中的任意值
import'dart:math';
进口“包装:颤振/材料.省道”;
类ArcIndicator扩展了CustomPainter{
最终颜色;
最终颜色线条颜色;
最后的两个百分点;
最终双倍宽度;
电弧指示器({
这种颜色,
这是线条颜色,
这个百分之零点五,,
这是宽度
});
@凌驾
空心油漆(帆布,尺寸){
绘制bgLine=Paint()…颜色=bgColor
..strokeCap=strokeCap.round
..冲程宽度=宽度
..风格=绘画风格.笔划;
绘制完成线条=绘制()…颜色=线条颜色
..strokeCap=strokeCap.round
..冲程宽度=宽度
..风格=绘画风格.笔划;
偏移量=偏移量(size.width/2,size.height/2);
双半径=最小值(尺寸.宽度/2,尺寸.高度/2);
帆布拉弧(
矩形自圆(中心:偏移,半径:半径),
2.5,
2*pi*0.7,
假,,
bgLine);
双扫掠角=2*pi*百分比;
帆布拉弧(
矩形自圆(中心:偏移,半径:半径),
2.5,
扫掠角,
假,,
完成线);
}
@凌驾
bool应重新绘制(自定义代理){
返回true;
}
}
这不是圆弧进度条,而是完整的圆形进度条。我想要像@diegoveloper这样的东西,我也需要应用背景色,如果我应用背景色,那么它会显示为一个完整的圆形进度条,为什么你要将0.775乘以前面的PropertyTanks作为你的答案,但这并不完全是问题所指定的。他/她想要这样的输出,i.stack.imgur.com/mLjUe.pngYes我知道并且已经提到过。这是非常接近他/她需要的只是需要一些修改,以旋转和限制在一定程度上的进展。这就是我所说的小修改。哇,这对我的用例也非常有效。谢谢我唯一想要的改变是,100%的,我不希望拱门完工。像这样的
import 'package:flutter/material.dart';
class DownloadProgressIndicator extends StatelessWidget {
DownloadProgressIndicator({
this.color =Colors.blue,
this.backgroundColor = Colors.black12,
this.content,
this.value,
this.strokeWidth = 4.0,
});
final Color color;
final Color backgroundColor;
final Widget content;
final double value;
final double strokeWidth;
@override
Widget build(BuildContext context) {
return Stack(
fit: StackFit.expand,
children: <Widget>[
backgroundColor != null ?
CircularProgressIndicator(
valueColor: AlwaysStoppedAnimation(backgroundColor),
value: 1,
strokeWidth: strokeWidth,
): Container(),
CircularProgressIndicator(
valueColor: AlwaysStoppedAnimation(color),
value: value,
strokeWidth: strokeWidth,
),
content != null ?
Center(
child: content,
) : Container(),
],
);
}
}