@@ -3,60 +3,55 @@ import 'package:getflutter/types/gf_progress_type.dart';
33import 'package:vector_math/vector_math_64.dart' as math;
44
55class GFProgressBar extends StatefulWidget {
6-
76 GFProgressBar ({
87 Key key,
98 this .percentage = 0.2 ,
109 this .circleWidth = 5.0 ,
1110 this .circleStartAngle = 0.0 ,
1211 this .radius,
1312 this .backgroundColor = const Color (0xFFB8C7CB ),
14- Color progressBarColor,
13+ this . progressBarColor = Colors .red ,
1514 this .linearGradient,
1615 this .animation = false ,
17- this .animationDuration = 500 ,
16+ this .animationDuration = 700 ,
1817 this .child,
1918 this .autoLive = true ,
2019 this .animateFromLastPercentage = false ,
2120 this .reverse = false ,
2221 this .mask,
23- this .type,
22+ this .type = GFProgressType .linear ,
2423 this .progressHeadType,
2524 this .lineHeight = 5.0 ,
2625 this .width,
2726 this .fromRightToLeft = false ,
2827 this .leading,
2928 this .trailing,
30- this .padding = const EdgeInsets . symmetric (horizontal : 10 ) ,
29+ this .padding ,
3130 this .alignment = MainAxisAlignment .start,
3231 this .clipLinearGradient = false ,
3332 }) : super (key: key) {
3433 if (linearGradient != null && progressBarColor != null ) {
3534 throw ArgumentError (
36- 'Cannot provide both linearGradient and progressBarColor' );
35+ ' linearGradient and progressBarColor cannot be given ' );
3736 }
38- _progressBarColor = progressBarColor ?? Colors .red;
3937
4038 assert (circleStartAngle >= 0.0 );
4139 if (percentage < 0.0 || percentage > 1.0 ) {
42- throw Exception ('Percent value must be a double between 0.0 and 1.0' );
40+ throw Exception ('Percentage value must be between 0.0 and 1.0' );
4341 }
4442 }
4543
46-
4744 ///width of the Progress bar
4845 final double width;
4946
5047 ///Height of the Progress Bar
5148 final double lineHeight;
5249
53- ///type of [Color] or [GFColor] used to change the backgroundColor of the progress bar
50+ ///type of [Color] or GFColors used to change the backgroundColor of the progress bar
5451 final dynamic backgroundColor;
5552
56- Color get progressBarColor => _progressBarColor;
57-
5853 ///type of Color , used to change the color of the active progress line
59- dynamic _progressBarColor ;
54+ final Color progressBarColor ;
6055
6156 ///type of bool which allows the progress line to animate when the percentage values are changed
6257 final bool animation;
@@ -79,7 +74,7 @@ class GFProgressBar extends StatefulWidget {
7974 ///type of EdgeInsets which gives padding to the GFProgressBar
8075 final EdgeInsets padding;
8176
82- /// set true if you want to animate the linear from the last progressPercentage value you set
77+ /// set true if you want to animate the progress bar from the last percentage value you set
8378 final bool animateFromLastPercentage;
8479
8580 /// If present, this will make the progress bar colored by this gradient.
@@ -100,19 +95,19 @@ class GFProgressBar extends StatefulWidget {
10095 /// If no [linearGradient] is specified this option is ignored.
10196 final bool clipLinearGradient;
10297
103- ///type of [GFProgressType] which changes the shape of progress bar based on the type ie, circle and linear
98+ ///type of [GFProgressType] which changes the shape of progress bar based on the type ie, circular and linear
10499 final GFProgressType type;
105100
106101 ///type of [GFProgressHeadType] which changes the shape of progress head based on the type ie, circular and square
107102 final GFProgressHeadType progressHeadType;
108103
109- ///type of double which defines the width of the arc Circle in CircularProgressBar
104+ ///type of double which defines the thickness of the circle's arc in Circular Progress bar
110105 final double circleWidth;
111106
112107 ///type of double in which the angle on the circle starts to progress (in degrees, eg: 0.0, 45.0, 90.0)
113108 final double circleStartAngle;
114109
115- ///type of bool used to display the progress in reverse mode
110+ ///type of bool used to display the progress in reverse direction
116111 final bool reverse;
117112
118113 ///type of double used to show the radius of Circular Progress Bar
@@ -121,27 +116,26 @@ class GFProgressBar extends StatefulWidget {
121116 ///type of double which should be from 0 to 1 to indicate the progress of the ProgressBars
122117 final double percentage;
123118
124-
125-
126119 @override
127120 _GFProgressBarState createState () => _GFProgressBarState ();
128121}
129122
130123class _GFProgressBarState extends State <GFProgressBar >
131124 with TickerProviderStateMixin , AutomaticKeepAliveClientMixin {
132- AnimationController _animationController, circular_animation_controller ;
133- Animation _animation, circular_animation ;
134- double _progressPercent = 0.0 ;
135- double _percentage = 0.0 ;
125+ AnimationController _animationController, circularAnimationController ;
126+ Animation _animation, circularAnimation ;
127+ double _progressPercent = 0 ;
128+ double _percentage = 0 ;
136129
137130 @override
138131 void initState () {
132+ super .initState ();
139133 if (widget.animation) {
140- _animationController = AnimationController (
134+ _animationController = AnimationController (
141135 vsync: this ,
142136 duration: Duration (milliseconds: widget.animationDuration));
143- _animation = Tween (begin : 0.0 , end : widget.percentage)
144- .animate (_animationController)
137+ _animation =
138+ Tween (begin : 0 , end : widget.percentage) .animate (_animationController)
145139 ..addListener (() {
146140 setState (() {
147141 _progressPercent = _animation.value;
@@ -153,17 +147,17 @@ class _GFProgressBarState extends State<GFProgressBar>
153147 }
154148
155149 if (widget.animation) {
156- circular_animation_controller = AnimationController (
150+ circularAnimationController = AnimationController (
157151 vsync: this ,
158152 duration: Duration (milliseconds: widget.animationDuration));
159- circular_animation = Tween (begin: 0. 0 , end: widget.percentage)
160- .animate (circular_animation_controller )
153+ circularAnimation = Tween (begin: 0 , end: widget.percentage)
154+ .animate (circularAnimationController )
161155 ..addListener (() {
162156 setState (() {
163- _percentage = circular_animation .value;
157+ _percentage = circularAnimation .value;
164158 });
165159 });
166- circular_animation_controller .forward ();
160+ circularAnimationController .forward ();
167161 } else {
168162 _updateProgress ();
169163 }
@@ -175,7 +169,7 @@ class _GFProgressBarState extends State<GFProgressBar>
175169 });
176170 }
177171
178- void _updateprogressPercent () {
172+ void _updateprogressPercent () {
179173 setState (() {
180174 _progressPercent = widget.percentage;
181175 });
@@ -186,8 +180,8 @@ class _GFProgressBarState extends State<GFProgressBar>
186180 if (_animationController != null ) {
187181 _animationController.dispose ();
188182 }
189- if (circular_animation_controller != null ) {
190- circular_animation_controller .dispose ();
183+ if (circularAnimationController != null ) {
184+ circularAnimationController .dispose ();
191185 }
192186 super .dispose ();
193187 }
@@ -205,23 +199,23 @@ class _GFProgressBarState extends State<GFProgressBar>
205199 : 0.0 ,
206200 end: widget.percentage)
207201 .animate (_animationController);
208- _animationController.forward (from: 0.0 );
202+ _animationController.forward (from: 0 );
209203 } else {
210204 _updateprogressPercent ();
211205 }
212206 }
213207 if (oldWidget.percentage != widget.percentage ||
214208 oldWidget.circleStartAngle != widget.circleStartAngle) {
215- if (circular_animation_controller != null ) {
216- circular_animation_controller .duration =
209+ if (circularAnimationController != null ) {
210+ circularAnimationController .duration =
217211 Duration (milliseconds: widget.animationDuration);
218- circular_animation = Tween (
212+ circularAnimation = Tween (
219213 begin: widget.animateFromLastPercentage
220214 ? oldWidget.percentage
221215 : 0.0 ,
222216 end: widget.percentage)
223- .animate (circular_animation_controller );
224- circular_animation_controller .forward (from: 0. 0 );
217+ .animate (circularAnimationController );
218+ circularAnimationController .forward (from: 0 );
225219 } else {
226220 _updateProgress ();
227221 }
@@ -231,13 +225,14 @@ class _GFProgressBarState extends State<GFProgressBar>
231225 @override
232226 Widget build (BuildContext context) {
233227 super .build (context);
234- final item = List <Widget >() ;
228+ final item = < Widget > [] ;
235229 if (widget.leading != null ) {
236230 item.add (widget.leading);
237231 }
238232 final hasSetWidth = widget.width != null ;
239- var containerWidget = Container (
240- width: hasSetWidth ? widget.width : double .infinity,
233+ final containerWidget = Container (
234+ margin: EdgeInsets .only (left: 10 , right: 10 ),
235+ width: hasSetWidth ? widget.width : MediaQuery .of (context).size.width,
241236 height: widget.lineHeight,
242237 padding: widget.padding,
243238 child: widget.type == GFProgressType .linear
@@ -287,7 +282,8 @@ class _GFProgressBarState extends State<GFProgressBar>
287282 return widget.type == GFProgressType .linear
288283 ? Material (
289284 color: Colors .transparent,
290- child: Container (
285+ child: Container (
286+ width: MediaQuery .of (context).size.width,
291287 child: Row (
292288 mainAxisAlignment: widget.alignment,
293289 crossAxisAlignment: CrossAxisAlignment .center,
@@ -296,8 +292,9 @@ class _GFProgressBarState extends State<GFProgressBar>
296292 )
297293 : Material (
298294 child: Container (
295+ width: MediaQuery .of (context).size.width,
299296 child: Column (
300- crossAxisAlignment: CrossAxisAlignment .center,
297+ crossAxisAlignment: CrossAxisAlignment .center,
301298 mainAxisAlignment: MainAxisAlignment .spaceBetween,
302299 children: item,
303300 )),
@@ -309,19 +306,6 @@ class _GFProgressBarState extends State<GFProgressBar>
309306}
310307
311308class LinearPainter extends CustomPainter {
312- final Paint _paintBackground = new Paint ();
313- final Paint _paintLine = new Paint ();
314- final circleWidth;
315- final progress;
316- final child;
317- final fromRightToLeft;
318- final Color progressBarColor;
319- final Color backgroundColor;
320- final LinearGradient linearGradient;
321- final MaskFilter mask;
322- final bool clipLinearGradient;
323- GFProgressHeadType progressHeadType;
324-
325309 LinearPainter ({
326310 this .circleWidth,
327311 this .progress,
@@ -338,23 +322,36 @@ class LinearPainter extends CustomPainter {
338322 _paintBackground.style = PaintingStyle .stroke;
339323 _paintBackground.strokeWidth = circleWidth;
340324
341- _paintLine.color = progress.toString () == " 0.0"
342- ? progressBarColor.withOpacity (0.0 )
325+ _paintLine.color = progress.toString () == ' 0.0'
326+ ? progressBarColor.withOpacity (0 )
343327 : progressBarColor;
344328 _paintLine.style = PaintingStyle .stroke;
345329 _paintLine.strokeWidth = circleWidth;
346330
347331 if (progressHeadType == GFProgressHeadType .square) {
348- _paintLine.strokeCap = StrokeCap .square ;
332+ _paintLine.strokeCap = StrokeCap .butt ;
349333 } else {
350334 _paintLine.strokeCap = StrokeCap .round;
351335 _paintBackground.strokeCap = StrokeCap .round;
352336 }
353337 }
354338
339+ final Paint _paintBackground = Paint ();
340+ final Paint _paintLine = Paint ();
341+ final double circleWidth;
342+ final double progress;
343+ final Widget child;
344+ final bool fromRightToLeft;
345+ final Color progressBarColor;
346+ final Color backgroundColor;
347+ final LinearGradient linearGradient;
348+ final MaskFilter mask;
349+ final bool clipLinearGradient;
350+ GFProgressHeadType progressHeadType;
351+
355352 @override
356353 void paint (Canvas canvas, Size size) {
357- final start = Offset (0.0 , size.height / 2 );
354+ final start = Offset (0 , size.height / 2 );
358355 final end = Offset (size.width, size.height / 2 );
359356 canvas.drawLine (start, end, _paintBackground);
360357
@@ -378,7 +375,7 @@ class LinearPainter extends CustomPainter {
378375 }
379376
380377 Shader _createGradientShaderRightToLeft (Size size, double xProgress) {
381- Offset shaderEndPoint =
378+ final Offset shaderEndPoint =
382379 clipLinearGradient ? Offset .zero : Offset (xProgress, size.height);
383380 return linearGradient.createShader (
384381 Rect .fromPoints (
@@ -389,7 +386,7 @@ class LinearPainter extends CustomPainter {
389386 }
390387
391388 Shader _createGradientShaderLeftToRight (Size size, double xProgress) {
392- Offset shaderEndPoint = clipLinearGradient
389+ final Offset shaderEndPoint = clipLinearGradient
393390 ? Offset (size.width, size.height)
394391 : Offset (xProgress, size.height);
395392 return linearGradient.createShader (
@@ -401,26 +398,10 @@ class LinearPainter extends CustomPainter {
401398 }
402399
403400 @override
404- bool shouldRepaint (CustomPainter oldDelegate) {
405- return true ;
406- }
401+ bool shouldRepaint (CustomPainter oldDelegate) => true ;
407402}
408403
409404class CirclePainter extends CustomPainter {
410- final Paint _paintBackground = Paint ();
411- final Paint _paintLine = Paint ();
412- final double circleWidth;
413- final double progress;
414- final double radius;
415- final Color progressBarColor;
416- final Color backgroundColor;
417- final double circleStartAngle;
418- final LinearGradient linearGradient;
419- final Color arcBackgroundColor;
420- final bool reverse;
421- final MaskFilter mask;
422- final GFProgressHeadType progressHeadType;
423-
424405 CirclePainter (
425406 {this .circleWidth,
426407 this .progress,
@@ -446,6 +427,19 @@ class CirclePainter extends CustomPainter {
446427 _paintLine.strokeCap = StrokeCap .square;
447428 }
448429 }
430+ final Paint _paintBackground = Paint ();
431+ final Paint _paintLine = Paint ();
432+ final double circleWidth;
433+ final double progress;
434+ final double radius;
435+ final Color progressBarColor;
436+ final Color backgroundColor;
437+ final double circleStartAngle;
438+ final LinearGradient linearGradient;
439+ final Color arcBackgroundColor;
440+ final bool reverse;
441+ final MaskFilter mask;
442+ final GFProgressHeadType progressHeadType;
449443
450444 @override
451445 void paint (Canvas canvas, Size size) {
@@ -464,9 +458,9 @@ class CirclePainter extends CustomPainter {
464458 );
465459 }
466460
467- double fixedStartAngle = circleStartAngle;
461+ final double fixedStartAngle = circleStartAngle;
468462
469- double circleStartAngleFixedMargin = 1.0 ;
463+ const double circleStartAngleFixedMargin = 1 ;
470464
471465 if (reverse) {
472466 final start = math
@@ -499,7 +493,6 @@ class CirclePainter extends CustomPainter {
499493 }
500494
501495 @override
502- bool shouldRepaint (CustomPainter oldDelegate) {
503- return true ;
504- }
496+ bool shouldRepaint (CustomPainter oldDelegate) => true ;
505497}
498+
0 commit comments