Skip to content

Commit dcc8e30

Browse files
authored
Add clipRotatedLinearGradient param (#227)
1 parent 30c4389 commit dcc8e30

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

lib/circular_percent_indicator.dart

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,10 @@ class CircularPercentIndicator extends StatefulWidget {
107107
/// Set to true if you want to rotate linear gradient in accordance to the [startAngle].
108108
final bool rotateLinearGradient;
109109

110+
/// Set true if you want to display only part of [linearGradient] based on percent value.
111+
/// Works only if [rotateLinearGradient] is true.
112+
final bool clipRotatedLinearGradient;
113+
110114
/// Return current percent value if animation is true.
111115
final Function(double value)? onPercentValue;
112116

@@ -140,6 +144,7 @@ class CircularPercentIndicator extends StatefulWidget {
140144
this.onAnimationEnd,
141145
this.widgetIndicator,
142146
this.rotateLinearGradient = false,
147+
this.clipRotatedLinearGradient = false,
143148
this.progressBorderColor,
144149
this.onPercentValue,
145150
}) : super(key: key) {
@@ -280,6 +285,7 @@ class _CircularPercentIndicatorState extends State<CircularPercentIndicator>
280285
linearGradient: widget.linearGradient,
281286
maskFilter: widget.maskFilter,
282287
rotateLinearGradient: widget.rotateLinearGradient,
288+
clipRotatedLinearGradient: widget.clipRotatedLinearGradient,
283289
),
284290
child: (widget.center != null)
285291
? Center(child: widget.center)
@@ -396,6 +402,7 @@ class _CirclePainter extends CustomPainter {
396402
final bool reverse;
397403
final MaskFilter? maskFilter;
398404
final bool rotateLinearGradient;
405+
final bool clipRotatedLinearGradient;
399406

400407
_CirclePainter({
401408
required this.lineWidth,
@@ -413,6 +420,7 @@ class _CirclePainter extends CustomPainter {
413420
this.arcType,
414421
this.maskFilter,
415422
required this.rotateLinearGradient,
423+
required this.clipRotatedLinearGradient,
416424
}) {
417425
_paintBackground.color = backgroundColor;
418426
_paintBackground.style = PaintingStyle.stroke;
@@ -469,7 +477,9 @@ class _CirclePainter extends CustomPainter {
469477
radians(-90 - progress + startAngle) - correction)
470478
: GradientRotation(radians(-90.0 + startAngle) - correction),
471479
startAngle: radians(0).toDouble(),
472-
endAngle: radians(progress).toDouble(),
480+
endAngle: clipRotatedLinearGradient
481+
? radians(360).toDouble()
482+
: radians(progress).toDouble(),
473483
tileMode: TileMode.clamp,
474484
colors: reverse
475485
? linearGradient!.colors.reversed.toList()

0 commit comments

Comments
 (0)