Skip to content

Commit

Permalink
Added Half Arc for Circular Percent Circular Percent Indicator (diego…
Browse files Browse the repository at this point in the history
…veloper#99)

* Added Half Arc for Circular Percent Circular Percent Indicator
Closes: diegoveloper#98

* added sample for Half Arc
  • Loading branch information
vivekgugnani authored Dec 20, 2020
1 parent 24bf093 commit 298c2e0
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 4 deletions.
11 changes: 11 additions & 0 deletions example/lib/sample_circular_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,17 @@ class _SampleCircularPageState extends State<SampleCircularPage> {
setState(() => state = 'End Animation at 50%'),
),
const SizedBox(height: 20),
CircularPercentIndicator(
radius: 80.0,
backgroundColor: Colors.white,
percent: .7,
lineWidth: 10,
backgroundWidth: 15,
fillColor: Colors.transparent,
circularStrokeCap: CircularStrokeCap.round,
arcBackgroundColor: Colors.transparent,
arcType: ArcType.HALF,
),
],
),
),
Expand Down
31 changes: 27 additions & 4 deletions lib/circular_percent_indicator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,13 @@ class CirclePainter extends CustomPainter {
_paintBackground.color = backgroundColor;
_paintBackground.style = PaintingStyle.stroke;
_paintBackground.strokeWidth = backgroundWidth;

if (circularStrokeCap == CircularStrokeCap.round) {
_paintBackground.strokeCap = StrokeCap.round;
} else if (circularStrokeCap == CircularStrokeCap.butt) {
_paintBackground.strokeCap = StrokeCap.butt;
} else {
_paintBackground.strokeCap = StrokeCap.square;
}
if (arcBackgroundColor != null) {
_paintBackgroundStartAngle.color = arcBackgroundColor;
_paintBackgroundStartAngle.style = PaintingStyle.stroke;
Expand Down Expand Up @@ -369,7 +375,24 @@ class CirclePainter extends CustomPainter {
@override
void paint(Canvas canvas, Size size) {
final center = Offset(size.width / 2, size.height / 2);
canvas.drawCircle(center, radius, _paintBackground);
double fixedStartAngle = startAngle;
final rectForArc = Rect.fromCircle(center: center, radius: radius);
double startAngleFixedMargin = 1.0;
if (arcType != null) {
if (arcType == ArcType.FULL) {
fixedStartAngle = 220;
startAngleFixedMargin = 172 / fixedStartAngle;
} else {
fixedStartAngle = 270;
startAngleFixedMargin = 135 / fixedStartAngle;
}
}
if (arcType == ArcType.HALF) {
canvas.drawArc(rectForArc, radians(-90.0 + fixedStartAngle),
radians(360 * startAngleFixedMargin), false, _paintBackground);
} else {
canvas.drawCircle(center, radius, _paintBackground);
}

if (maskFilter != null) {
_paintLine.maskFilter = maskFilter;
Expand Down Expand Up @@ -413,9 +436,9 @@ class CirclePainter extends CustomPainter {
}
}

double fixedStartAngle = startAngle;
fixedStartAngle = startAngle;

double startAngleFixedMargin = 1.0;
startAngleFixedMargin = 1.0;
if (arcType != null) {
if (arcType == ArcType.FULL) {
fixedStartAngle = 220;
Expand Down

0 comments on commit 298c2e0

Please sign in to comment.