[英]Flutter Circular progress indicator not working properly on android
[英]Flutter: How to achieve a Radial Widget like this in flutter? Circular breadcrumbs/ step progress indicator
计算你的面积:
右上角为Offset zero (x=0, y = 0),可以将计算出来的数据传给Positioned Widget
这里的简单代码供您参考:
Widget build(BuildContext context) {
double areaRadius = MediaQuery.of(context).size.width;
double bigCircleRadius = areaRadius * 0.8;
double smallCircleRadius = areaRadius * 0.15;
double imageRadius = areaRadius * 0.6;
return Scaffold(
appBar: AppBar(
automaticallyImplyLeading: true,
),
body: SizedBox(
height: areaRadius,
width: areaRadius,
child: Stack(
children: [
///Bottom Layer --> BIG Circle
Positioned(
top: areaRadius * 0.1,
left: areaRadius * 0.1,
child: Container(
width: bigCircleRadius,
height: bigCircleRadius,
decoration: BoxDecoration(
shape: BoxShape.circle,
border: Border.all(
color: Colors.black.withOpacity(0.1),
width: 4.0
)
),
),
),
Positioned(
top: areaRadius * 0.2,
left: areaRadius * 0.2,
child: Container(
width: imageRadius,
height: imageRadius,
decoration: const BoxDecoration(
image: DecorationImage(
image: AssetImage("assets/images/burger.png"),
fit: BoxFit.contain
),
shape: BoxShape.circle
),
),
),
///you can use trigonometry for this <---- Create a Offset(x,y) left is X and top is Y
Positioned(
left: (areaRadius * 0.5) - (smallCircleRadius /2),
top: (areaRadius * 0.1) - (smallCircleRadius /2),
child: Container(
width: smallCircleRadius,
height: smallCircleRadius,
decoration: const BoxDecoration(
color: Colors.blue,
shape: BoxShape.circle
),
child: const Center(
child: Text("1", style: TextStyle(color: Colors.white, fontSize: 20.0),),
),
),
),
Positioned(
left: (areaRadius * 0.25) - (smallCircleRadius/2),
top: (areaRadius * 0.8) - (smallCircleRadius /2),
child: Container(
width: smallCircleRadius,
height: smallCircleRadius,
decoration: const BoxDecoration(
color: Colors.grey,
shape: BoxShape.circle
),
child: const Center(
child: Text("2", style: TextStyle(color: Colors.black, fontSize: 20.0),),
),
),
),
Positioned(
left: (areaRadius * 0.75) - (smallCircleRadius/2),
top: (areaRadius * 0.8) - (smallCircleRadius /2),
child: Container(
width: smallCircleRadius,
height: smallCircleRadius,
decoration: const BoxDecoration(
color: Colors.grey,
shape: BoxShape.circle
),
child: const Center(
child: Text("3", style: TextStyle(color: Colors.black, fontSize: 20.0),),
),
),
),
]
),
),
);
}
结果如下:
@Sayyid J 您的答案非常适合 static 3 数字指示器。 但我的情况是这个数字是动态的。 它可能是 2,3,4,5,6.. 步骤。
所以我创建了这个 function 来根据索引构建小部件
_buildChildren(context,aR,sCR,c){
final children = <Widget>[];
var theta = 360/c;
for (var i = 1; i <= c; i++) {
children.add( _customChild(
sCR,
(aR /2)*(sin (2 * math.pi * theta*(i-1) / 360)+1),
(aR/2)*(cos (2 * math.pi * theta*(i-1) / 360)-1)*-1,
i
));
}
return children;
}
_customChild(smallCircleRadius,x,y,i){
print("${x.toString()} ${y.toString()}");
return Positioned(
left: x,
top: y,
child: Container(
width: smallCircleRadius,
height: smallCircleRadius,
decoration: const BoxDecoration(
color: Colors.cyan,
shape: BoxShape.circle
),
child: Center(
child: Text(i.toString(), style: TextStyle(color: Colors.white, fontSize: 20.0),),
),
),
);
}
但结果有点不对齐,如下所示
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.