From c1c5ddb6266727e84604680edb9584654eee9d79 Mon Sep 17 00:00:00 2001 From: Bardez Date: Fri, 26 May 2023 13:15:02 -0300 Subject: [PATCH 1/7] Adding progressBorderColor property on progressBar (#196) * adding progressBorderColor on progressBar draw * fixing border colors on linear percent and adding examples * removing unnecessary parse comparsion on progress(double) * refactoring border correction symmetrics --------- Co-authored-by: Thiago Carvalho Ribeiro Bardez - TBA --- example/ios/Flutter/AppFrameworkInfo.plist | 2 +- example/ios/Runner.xcodeproj/project.pbxproj | 10 +- .../xcshareddata/xcschemes/Runner.xcscheme | 2 +- example/ios/Runner/Info.plist | 4 + example/lib/sample_circular_page.dart | 66 ++++++++++++ example/lib/sample_linear_page.dart | 14 +++ example/pubspec.lock | 35 ++++-- lib/circular_percent_indicator.dart | 49 ++++++++- lib/linear_percent_indicator.dart | 42 +++++++- pubspec.lock | 102 ++++++++++-------- 10 files changed, 259 insertions(+), 67 deletions(-) diff --git a/example/ios/Flutter/AppFrameworkInfo.plist b/example/ios/Flutter/AppFrameworkInfo.plist index 9367d48..9625e10 100644 --- a/example/ios/Flutter/AppFrameworkInfo.plist +++ b/example/ios/Flutter/AppFrameworkInfo.plist @@ -21,6 +21,6 @@ CFBundleVersion 1.0 MinimumOSVersion - 8.0 + 11.0 diff --git a/example/ios/Runner.xcodeproj/project.pbxproj b/example/ios/Runner.xcodeproj/project.pbxproj index 14ac4c4..8f55860 100644 --- a/example/ios/Runner.xcodeproj/project.pbxproj +++ b/example/ios/Runner.xcodeproj/project.pbxproj @@ -3,7 +3,7 @@ archiveVersion = 1; classes = { }; - objectVersion = 46; + objectVersion = 54; objects = { /* Begin PBXBuildFile section */ @@ -141,7 +141,7 @@ 97C146E61CF9000F007C117D /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 0910; + LastUpgradeCheck = 1300; ORGANIZATIONNAME = "The Chromium Authors"; TargetAttributes = { 97C146ED1CF9000F007C117D = { @@ -186,6 +186,7 @@ /* Begin PBXShellScriptBuildPhase section */ 3B06AD1E1E4923F5004D2608 /* Thin Binary */ = { isa = PBXShellScriptBuildPhase; + alwaysOutOfDate = 1; buildActionMask = 2147483647; files = ( ); @@ -200,6 +201,7 @@ }; 9740EEB61CF901F6004384FC /* Run Script */ = { isa = PBXShellScriptBuildPhase; + alwaysOutOfDate = 1; buildActionMask = 2147483647; files = ( ); @@ -292,7 +294,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 8.0; + IPHONEOS_DEPLOYMENT_TARGET = 11.0; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; @@ -339,7 +341,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 8.0; + IPHONEOS_DEPLOYMENT_TARGET = 11.0; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; TARGETED_DEVICE_FAMILY = "1,2"; diff --git a/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme b/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme index 1263ac8..1c19f4b 100644 --- a/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme +++ b/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme @@ -1,6 +1,6 @@ UIViewControllerBasedStatusBarAppearance + CADisableMinimumFrameDurationOnPhone + + UIApplicationSupportsIndirectInputEvents + diff --git a/example/lib/sample_circular_page.dart b/example/lib/sample_circular_page.dart index 61a55c5..bf900ad 100644 --- a/example/lib/sample_circular_page.dart +++ b/example/lib/sample_circular_page.dart @@ -337,6 +337,72 @@ class _SampleCircularPageState extends State { arcBackgroundColor: Colors.transparent, arcType: ArcType.HALF, ), + const SizedBox(height: 20), + Padding( + padding: const EdgeInsets.only(bottom: 18.0), + child: Center( + child: Text( + "With different border color", + style: TextStyle(fontWeight: FontWeight.bold, fontSize: 17.0), + ), + ), + ), + Row( + mainAxisAlignment: MainAxisAlignment.spaceEvenly, + children: [ + CircularPercentIndicator( + radius: 40.0, + progressColor: Colors.yellow, + progressBorderColor: Colors.green, + percent: .2, + lineWidth: 15, + center: Text( + "20.0%", + style: + TextStyle(fontWeight: FontWeight.bold, fontSize: 12.0), + ), + backgroundWidth: 15, + fillColor: Colors.transparent, + circularStrokeCap: CircularStrokeCap.round, + arcBackgroundColor: Colors.yellow[200], + arcType: ArcType.FULL, + ), + CircularPercentIndicator( + radius: 40.0, + progressColor: Colors.white, + progressBorderColor: Colors.blue, + percent: .9, + lineWidth: 10, + center: Text( + "90.0%", + style: + TextStyle(fontWeight: FontWeight.bold, fontSize: 12.0), + ), + backgroundWidth: 15, + fillColor: Colors.transparent, + circularStrokeCap: CircularStrokeCap.round, + arcBackgroundColor: Colors.transparent, + arcType: ArcType.FULL, + ), + CircularPercentIndicator( + radius: 40.0, + progressColor: Colors.red, + progressBorderColor: Colors.black, + percent: .4, + lineWidth: 10, + backgroundWidth: 15, + fillColor: Colors.transparent, + circularStrokeCap: CircularStrokeCap.round, + arcBackgroundColor: Colors.grey, + arcType: ArcType.FULL, + center: Text( + "40.0%", + style: + TextStyle(fontWeight: FontWeight.bold, fontSize: 12.0), + ), + ), + ], + ), ], ), ), diff --git a/example/lib/sample_linear_page.dart b/example/lib/sample_linear_page.dart index 7098340..e866d15 100644 --- a/example/lib/sample_linear_page.dart +++ b/example/lib/sample_linear_page.dart @@ -275,6 +275,20 @@ class _SampleLinearPageState extends State { ), ), Text('Custom Edges'), + Padding( + padding: EdgeInsets.all(15), + child: LinearPercentIndicator( + lineHeight: 20, + center: Text('90%'), + progressColor: Colors.white, + progressBorderColor: Colors.green, + barRadius: Radius.elliptical(5, 10), + percent: .9, + animation: true, + animationDuration: 1400, + ), + ), + Text('Custom Border Color'), ], ), ), diff --git a/example/pubspec.lock b/example/pubspec.lock index 1940e8e..1d4bbd0 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -5,35 +5,47 @@ packages: dependency: transitive description: name: characters - url: "https://pub.dartlang.org" + sha256: e6a326c8af69605aec75ed6c187d06b349707a27fbff8222ca9cc2cff167975c + url: "https://pub.dev" source: hosted - version: "1.2.0" + version: "1.2.1" collection: dependency: transitive description: name: collection - url: "https://pub.dartlang.org" + sha256: cfc915e6923fe5ce6e153b0723c753045de46de1b4d63771530504004a45fae0 + url: "https://pub.dev" source: hosted - version: "1.16.0" + version: "1.17.0" flutter: dependency: "direct main" description: flutter source: sdk version: "0.0.0" + js: + dependency: transitive + description: + name: js + sha256: "5528c2f391ededb7775ec1daa69e65a2d61276f7552de2b5f7b8d34ee9fd4ab7" + url: "https://pub.dev" + source: hosted + version: "0.6.5" material_color_utilities: dependency: transitive description: name: material_color_utilities - url: "https://pub.dartlang.org" + sha256: d92141dc6fe1dad30722f9aa826c7fbc896d021d792f80678280601aff8cf724 + url: "https://pub.dev" source: hosted - version: "0.1.4" + version: "0.2.0" meta: dependency: transitive description: name: meta - url: "https://pub.dartlang.org" + sha256: "6c268b42ed578a53088d834796959e4a1814b5e9e164f147f580a386e5decf42" + url: "https://pub.dev" source: hosted - version: "1.7.0" + version: "1.8.0" percent_indicator: dependency: "direct main" description: @@ -50,9 +62,10 @@ packages: dependency: transitive description: name: vector_math - url: "https://pub.dartlang.org" + sha256: "80b3257d1492ce4d091729e3a67a60407d227c27241d6927be0130c98e741803" + url: "https://pub.dev" source: hosted - version: "2.1.2" + version: "2.1.4" sdks: - dart: ">=2.14.0 <3.0.0" + dart: ">=2.17.0-0 <3.0.0" flutter: ">=2.12.0" diff --git a/lib/circular_percent_indicator.dart b/lib/circular_percent_indicator.dart index 617aced..3c34dca 100644 --- a/lib/circular_percent_indicator.dart +++ b/lib/circular_percent_indicator.dart @@ -37,6 +37,9 @@ class CircularPercentIndicator extends StatefulWidget { ///First color applied to the complete circle final Color fillColor; + ///Color of the border of the progress bar , default = null + final Color? progressBorderColor; + ///Color of the background of the circle , default = transparent final Color backgroundColor; @@ -130,6 +133,7 @@ class CircularPercentIndicator extends StatefulWidget { this.onAnimationEnd, this.widgetIndicator, this.rotateLinearGradient = false, + this.progressBorderColor, }) : super(key: key) { if (linearGradient != null && progressColor != null) { throw ArgumentError( @@ -250,6 +254,7 @@ class _CircularPercentIndicatorState extends State painter: _CirclePainter( progress: _percent * 360, progressColor: widget.progressColor, + progressBorderColor: widget.progressBorderColor, backgroundColor: widget.backgroundColor, startAngle: widget.startAngle, circularStrokeCap: widget.circularStrokeCap, @@ -363,12 +368,14 @@ class _ArcAngles { class _CirclePainter extends CustomPainter { final Paint _paintBackground = Paint(); final Paint _paintLine = Paint(); + final Paint _paintLineBorder = Paint(); final Paint _paintBackgroundStartAngle = Paint(); final double lineWidth; final double backgroundWidth; final double progress; final double radius; final Color progressColor; + final Color? progressBorderColor; final Color backgroundColor; final CircularStrokeCap circularStrokeCap; final double startAngle; @@ -386,6 +393,7 @@ class _CirclePainter extends CustomPainter { required this.radius, required this.progressColor, required this.backgroundColor, + this.progressBorderColor, this.startAngle = 0.0, this.circularStrokeCap = CircularStrokeCap.butt, this.linearGradient, @@ -409,8 +417,16 @@ class _CirclePainter extends CustomPainter { _paintLine.color = progressColor; _paintLine.style = PaintingStyle.stroke; - _paintLine.strokeWidth = lineWidth; + _paintLine.strokeWidth = + progressBorderColor != null ? lineWidth - 2 : lineWidth; _paintLine.strokeCap = circularStrokeCap.strokeCap; + + if (progressBorderColor != null) { + _paintLineBorder.color = progressBorderColor!; + _paintLineBorder.style = PaintingStyle.stroke; + _paintLineBorder.strokeWidth = lineWidth; + _paintLineBorder.strokeCap = circularStrokeCap.strokeCap; + } } @override @@ -428,7 +444,7 @@ class _CirclePainter extends CustomPainter { } if (maskFilter != null) { - _paintLine.maskFilter = maskFilter; + _paintLineBorder.maskFilter = _paintLine.maskFilter = maskFilter; } if (linearGradient != null) { if (rotateLinearGradient && progress > 0) { @@ -436,7 +452,7 @@ class _CirclePainter extends CustomPainter { if (_paintLine.strokeCap != StrokeCap.butt) { correction = math.atan(_paintLine.strokeWidth / 2 / radius); } - _paintLine.shader = SweepGradient( + _paintLineBorder.shader = _paintLine.shader = SweepGradient( transform: reverse ? GradientRotation( radians(-90 - progress + startAngle) - correction) @@ -451,7 +467,8 @@ class _CirclePainter extends CustomPainter { Rect.fromCircle(center: center, radius: radius), ); } else if (!rotateLinearGradient) { - _paintLine.shader = linearGradient!.createShader( + _paintLineBorder.shader = + _paintLine.shader = linearGradient!.createShader( Rect.fromCircle(center: center, radius: radius), ); } @@ -472,6 +489,18 @@ class _CirclePainter extends CustomPainter { radians(360 * startAngleFixedMargin - 90.0 + fixedStartAngle) .toDouble(); final end = radians(-progress * startAngleFixedMargin).toDouble(); + if (progressBorderColor != null) { + canvas.drawArc( + Rect.fromCircle( + center: center, + radius: radius, + ), + start, + end, + false, + _paintLineBorder, + ); + } canvas.drawArc( Rect.fromCircle( center: center, @@ -485,6 +514,18 @@ class _CirclePainter extends CustomPainter { } else { final start = radians(-90.0 + fixedStartAngle).toDouble(); final end = radians(progress * startAngleFixedMargin).toDouble(); + if (progressBorderColor != null) { + canvas.drawArc( + Rect.fromCircle( + center: center, + radius: radius, + ), + start, + end, + false, + _paintLineBorder, + ); + } canvas.drawArc( Rect.fromCircle( center: center, diff --git a/lib/linear_percent_indicator.dart b/lib/linear_percent_indicator.dart index 7bc68df..f325be2 100644 --- a/lib/linear_percent_indicator.dart +++ b/lib/linear_percent_indicator.dart @@ -3,6 +3,10 @@ import 'package:flutter/material.dart'; @Deprecated('This property is no longer used, please use barRadius instead.') enum LinearStrokeCap { butt, round, roundAll } +extension ExtDouble on double { + bool get isZero => this.toString() == '0.0'; +} + // ignore: must_be_immutable class LinearPercentIndicator extends StatefulWidget { ///Percent value between 0.0 and 1.0 @@ -15,6 +19,9 @@ class LinearPercentIndicator extends StatefulWidget { ///Color of the background of the Line , default = transparent final Color fillColor; + ///Color of the border of the progress bar , default = null + final Color? progressBorderColor; + ///First color applied to the complete line Color get backgroundColor => _backgroundColor; late Color _backgroundColor; @@ -116,6 +123,7 @@ class LinearPercentIndicator extends StatefulWidget { this.restartAnimation = false, this.onAnimationEnd, this.widgetIndicator, + this.progressBorderColor, }) : super(key: key) { if (linearGradient != null && progressColor != null) { throw ArgumentError( @@ -257,6 +265,7 @@ class _LinearPercentIndicatorState extends State isRTL: widget.isRTL, progress: _percent, progressColor: widget.progressColor, + progressBorderColor: widget.progressBorderColor, linearGradient: widget.linearGradient, backgroundColor: widget.backgroundColor, barRadius: widget.barRadius ?? @@ -320,9 +329,11 @@ class _LinearPercentIndicatorState extends State class _LinearPainter extends CustomPainter { final Paint _paintBackground = new Paint(); final Paint _paintLine = new Paint(); + final Paint _paintLineBorder = new Paint(); final double progress; final bool isRTL; final Color progressColor; + final Color? progressBorderColor; final Color backgroundColor; final Radius barRadius; final LinearGradient? linearGradient; @@ -336,6 +347,7 @@ class _LinearPainter extends CustomPainter { required this.progressColor, required this.backgroundColor, required this.barRadius, + this.progressBorderColor, this.linearGradient, this.maskFilter, required this.clipLinearGradient, @@ -343,9 +355,14 @@ class _LinearPainter extends CustomPainter { }) { _paintBackground.color = backgroundColor; - _paintLine.color = progress.toString() == "0.0" - ? progressColor.withOpacity(0.0) - : progressColor; + _paintLine.color = + progress == 0 ? progressColor.withOpacity(0.0) : progressColor; + + if (progressBorderColor != null) { + _paintLineBorder.color = progress == 0 + ? progressBorderColor!.withOpacity(0.0) + : progressBorderColor!; + } } @override @@ -358,6 +375,7 @@ class _LinearPainter extends CustomPainter { canvas.clipPath(backgroundPath); if (maskFilter != null) { + _paintLineBorder.maskFilter = maskFilter; _paintLine.maskFilter = maskFilter; } @@ -371,8 +389,13 @@ class _LinearPainter extends CustomPainter { // Then draw progress line final xProgress = size.width * progress; Path linePath = Path(); + Path linePathBorder = Path(); + double factor = progressBorderColor != null ? 2 : 0; + double correction = factor * 2; //Left and right or top an down if (isRTL) { if (linearGradient != null) { + _paintLineBorder.shader = + _createGradientShaderRightToLeft(size, xProgress); _paintLine.shader = _createGradientShaderRightToLeft(size, xProgress); } linePath.addRRect(RRect.fromRectAndRadius( @@ -381,10 +404,21 @@ class _LinearPainter extends CustomPainter { barRadius)); } else { if (linearGradient != null) { + _paintLineBorder.shader = + _createGradientShaderLeftToRight(size, xProgress); _paintLine.shader = _createGradientShaderLeftToRight(size, xProgress); } + if (progressBorderColor != null) { + linePathBorder.addRRect(RRect.fromRectAndRadius( + Rect.fromLTWH(0, 0, xProgress, size.height), barRadius)); + } linePath.addRRect(RRect.fromRectAndRadius( - Rect.fromLTWH(0, 0, xProgress, size.height), barRadius)); + Rect.fromLTWH( + factor, factor, xProgress - correction, size.height - correction), + barRadius)); + } + if (progressBorderColor != null) { + canvas.drawPath(linePathBorder, _paintLineBorder); } canvas.drawPath(linePath, _paintLine); } diff --git a/pubspec.lock b/pubspec.lock index 8910fc6..9b2215e 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -5,51 +5,50 @@ packages: dependency: transitive description: name: async - url: "https://pub.dartlang.org" + sha256: bfe67ef28df125b7dddcea62755991f807aa39a2492a23e1550161692950bbe0 + url: "https://pub.dev" source: hosted - version: "2.8.2" + version: "2.10.0" boolean_selector: dependency: transitive description: name: boolean_selector - url: "https://pub.dartlang.org" + sha256: "6cfb5af12253eaf2b368f07bacc5a80d1301a071c73360d746b7f2e32d762c66" + url: "https://pub.dev" source: hosted - version: "2.1.0" + version: "2.1.1" characters: dependency: transitive description: name: characters - url: "https://pub.dartlang.org" + sha256: e6a326c8af69605aec75ed6c187d06b349707a27fbff8222ca9cc2cff167975c + url: "https://pub.dev" source: hosted - version: "1.2.0" - charcode: - dependency: transitive - description: - name: charcode - url: "https://pub.dartlang.org" - source: hosted - version: "1.3.1" + version: "1.2.1" clock: dependency: transitive description: name: clock - url: "https://pub.dartlang.org" + sha256: cb6d7f03e1de671e34607e909a7213e31d7752be4fb66a86d29fe1eb14bfb5cf + url: "https://pub.dev" source: hosted - version: "1.1.0" + version: "1.1.1" collection: dependency: transitive description: name: collection - url: "https://pub.dartlang.org" + sha256: cfc915e6923fe5ce6e153b0723c753045de46de1b4d63771530504004a45fae0 + url: "https://pub.dev" source: hosted - version: "1.16.0" + version: "1.17.0" fake_async: dependency: transitive description: name: fake_async - url: "https://pub.dartlang.org" + sha256: "511392330127add0b769b75a987850d136345d9227c6b94c96a04cf4a391bf78" + url: "https://pub.dev" source: hosted - version: "1.3.0" + version: "1.3.1" flutter: dependency: "direct main" description: flutter @@ -60,34 +59,46 @@ packages: description: flutter source: sdk version: "0.0.0" + js: + dependency: transitive + description: + name: js + sha256: "5528c2f391ededb7775ec1daa69e65a2d61276f7552de2b5f7b8d34ee9fd4ab7" + url: "https://pub.dev" + source: hosted + version: "0.6.5" matcher: dependency: transitive description: name: matcher - url: "https://pub.dartlang.org" + sha256: "16db949ceee371e9b99d22f88fa3a73c4e59fd0afed0bd25fc336eb76c198b72" + url: "https://pub.dev" source: hosted - version: "0.12.11" + version: "0.12.13" material_color_utilities: dependency: transitive description: name: material_color_utilities - url: "https://pub.dartlang.org" + sha256: d92141dc6fe1dad30722f9aa826c7fbc896d021d792f80678280601aff8cf724 + url: "https://pub.dev" source: hosted - version: "0.1.4" + version: "0.2.0" meta: dependency: transitive description: name: meta - url: "https://pub.dartlang.org" + sha256: "6c268b42ed578a53088d834796959e4a1814b5e9e164f147f580a386e5decf42" + url: "https://pub.dev" source: hosted - version: "1.7.0" + version: "1.8.0" path: dependency: transitive description: name: path - url: "https://pub.dartlang.org" + sha256: db9d4f58c908a4ba5953fcee2ae317c94889433e5024c27ce74a37f94267945b + url: "https://pub.dev" source: hosted - version: "1.8.1" + version: "1.8.2" sky_engine: dependency: transitive description: flutter @@ -97,51 +108,58 @@ packages: dependency: transitive description: name: source_span - url: "https://pub.dartlang.org" + sha256: dd904f795d4b4f3b870833847c461801f6750a9fa8e61ea5ac53f9422b31f250 + url: "https://pub.dev" source: hosted - version: "1.8.2" + version: "1.9.1" stack_trace: dependency: transitive description: name: stack_trace - url: "https://pub.dartlang.org" + sha256: c3c7d8edb15bee7f0f74debd4b9c5f3c2ea86766fe4178eb2a18eb30a0bdaed5 + url: "https://pub.dev" source: hosted - version: "1.10.0" + version: "1.11.0" stream_channel: dependency: transitive description: name: stream_channel - url: "https://pub.dartlang.org" + sha256: "83615bee9045c1d322bbbd1ba209b7a749c2cbcdcb3fdd1df8eb488b3279c1c8" + url: "https://pub.dev" source: hosted - version: "2.1.0" + version: "2.1.1" string_scanner: dependency: transitive description: name: string_scanner - url: "https://pub.dartlang.org" + sha256: "556692adab6cfa87322a115640c11f13cb77b3f076ddcc5d6ae3c20242bedcde" + url: "https://pub.dev" source: hosted - version: "1.1.0" + version: "1.2.0" term_glyph: dependency: transitive description: name: term_glyph - url: "https://pub.dartlang.org" + sha256: a29248a84fbb7c79282b40b8c72a1209db169a2e0542bce341da992fe1bc7e84 + url: "https://pub.dev" source: hosted - version: "1.2.0" + version: "1.2.1" test_api: dependency: transitive description: name: test_api - url: "https://pub.dartlang.org" + sha256: ad540f65f92caa91bf21dfc8ffb8c589d6e4dc0c2267818b4cc2792857706206 + url: "https://pub.dev" source: hosted - version: "0.4.9" + version: "0.4.16" vector_math: dependency: transitive description: name: vector_math - url: "https://pub.dartlang.org" + sha256: "80b3257d1492ce4d091729e3a67a60407d227c27241d6927be0130c98e741803" + url: "https://pub.dev" source: hosted - version: "2.1.2" + version: "2.1.4" sdks: - dart: ">=2.17.0-0 <3.0.0" + dart: ">=2.18.0 <3.0.0" flutter: ">=2.12.0" From 5ed18db69cb9c2d51e33a879fae5bc111c3cad4a Mon Sep 17 00:00:00 2001 From: fenghezhou <109515842+motionz-von@users.noreply.github.com> Date: Fri, 4 Aug 2023 10:14:05 +0800 Subject: [PATCH 2/7] fix: divide 0 error when archType is not null (#200) --- lib/circular_percent_indicator.dart | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/circular_percent_indicator.dart b/lib/circular_percent_indicator.dart index 3c34dca..d346b7d 100644 --- a/lib/circular_percent_indicator.dart +++ b/lib/circular_percent_indicator.dart @@ -322,7 +322,8 @@ class _CircularPercentIndicatorState extends State double getCurrentPercent(double percent) { if (widget.arcType != null) { final angle = _getStartAngleFixedMargin(widget.arcType!).fixedStartAngle; - final fixedPercent = 1.0 / widget.percent * _percent; + final fixedPercent = + widget.percent > 0 ? 1.0 / widget.percent * _percent : 0; late double margin; if (widget.arcType == ArcType.HALF) { margin = 180 * widget.percent; From 522b5e9911bc6babafc11d10142de0f62e7bc911 Mon Sep 17 00:00:00 2001 From: Victor Manuel Lagunas Franco Date: Fri, 6 Oct 2023 15:57:45 +0900 Subject: [PATCH 3/7] Check in linear percent indicator state is null if the size is null (#203) --- example/ios/Runner.xcodeproj/project.pbxproj | 1 + lib/linear_percent_indicator.dart | 92 +++++++++++--------- 2 files changed, 50 insertions(+), 43 deletions(-) diff --git a/example/ios/Runner.xcodeproj/project.pbxproj b/example/ios/Runner.xcodeproj/project.pbxproj index 8f55860..a827609 100644 --- a/example/ios/Runner.xcodeproj/project.pbxproj +++ b/example/ios/Runner.xcodeproj/project.pbxproj @@ -191,6 +191,7 @@ files = ( ); inputPaths = ( + "${TARGET_BUILD_DIR}/${INFOPLIST_PATH}", ); name = "Thin Binary"; outputPaths = ( diff --git a/lib/linear_percent_indicator.dart b/lib/linear_percent_indicator.dart index f325be2..26a77f7 100644 --- a/lib/linear_percent_indicator.dart +++ b/lib/linear_percent_indicator.dart @@ -252,50 +252,56 @@ class _LinearPercentIndicatorState extends State final hasSetWidth = widget.width != null; final percentPositionedHorizontal = _containerWidth * _percent - _indicatorWidth / 3; - var containerWidget = Container( - width: hasSetWidth ? widget.width : double.infinity, - height: widget.lineHeight, - padding: widget.padding, - child: Stack( - clipBehavior: Clip.none, - children: [ - CustomPaint( - key: _containerKey, - painter: _LinearPainter( - isRTL: widget.isRTL, - progress: _percent, - progressColor: widget.progressColor, - progressBorderColor: widget.progressBorderColor, - linearGradient: widget.linearGradient, - backgroundColor: widget.backgroundColor, - barRadius: widget.barRadius ?? - Radius.zero, // If radius is not defined, set it to zero - linearGradientBackgroundColor: - widget.linearGradientBackgroundColor, - maskFilter: widget.maskFilter, - clipLinearGradient: widget.clipLinearGradient, + //LayoutBuilder is used to get the size of the container where the widget is rendered + var containerWidget = LayoutBuilder( + builder: (context, constraints) { + _containerWidth = constraints.maxWidth; + _containerHeight = constraints.maxHeight; + return Container( + width: hasSetWidth ? widget.width : double.infinity, + height: widget.lineHeight, + padding: widget.padding, + child: Stack( + clipBehavior: Clip.none, + children: [ + CustomPaint( + key: _containerKey, + painter: _LinearPainter( + isRTL: widget.isRTL, + progress: _percent, + progressColor: widget.progressColor, + linearGradient: widget.linearGradient, + backgroundColor: widget.backgroundColor, + barRadius: widget.barRadius ?? + Radius.zero, // If radius is not defined, set it to zero + linearGradientBackgroundColor: + widget.linearGradientBackgroundColor, + maskFilter: widget.maskFilter, + clipLinearGradient: widget.clipLinearGradient, + ), + child: (widget.center != null) + ? Center(child: widget.center) + : Container(), + ), + if (widget.widgetIndicator != null && _indicatorWidth == 0) + Opacity( + opacity: 0.0, + key: _keyIndicator, + child: widget.widgetIndicator, + ), + if (widget.widgetIndicator != null && + _containerWidth > 0 && + _indicatorWidth > 0) + Positioned( + right: widget.isRTL ? percentPositionedHorizontal : null, + left: !widget.isRTL ? percentPositionedHorizontal : null, + top: _containerHeight / 2 - _indicatorHeight, + child: widget.widgetIndicator!, + ), + ], ), - child: (widget.center != null) - ? Center(child: widget.center) - : Container(), - ), - if (widget.widgetIndicator != null && _indicatorWidth == 0) - Opacity( - opacity: 0.0, - key: _keyIndicator, - child: widget.widgetIndicator, - ), - if (widget.widgetIndicator != null && - _containerWidth > 0 && - _indicatorWidth > 0) - Positioned( - right: widget.isRTL ? percentPositionedHorizontal : null, - left: !widget.isRTL ? percentPositionedHorizontal : null, - top: _containerHeight / 2 - _indicatorHeight, - child: widget.widgetIndicator!, - ), - ], - ), + ); + } ); if (hasSetWidth) { From ff4155932b01d5b47b30a1af1ffa284cccad6869 Mon Sep 17 00:00:00 2001 From: Le Anh Phi <86833891+muonroi@users.noreply.github.com> Date: Mon, 18 Mar 2024 04:15:17 +0700 Subject: [PATCH 4/7] Add function return current percent value if animation is true (#206) --- lib/circular_percent_indicator.dart | 5 ++ lib/linear_percent_indicator.dart | 99 +++++++++++++++-------------- 2 files changed, 56 insertions(+), 48 deletions(-) diff --git a/lib/circular_percent_indicator.dart b/lib/circular_percent_indicator.dart index d346b7d..91206fd 100644 --- a/lib/circular_percent_indicator.dart +++ b/lib/circular_percent_indicator.dart @@ -104,6 +104,9 @@ class CircularPercentIndicator extends StatefulWidget { /// Set to true if you want to rotate linear gradient in accordance to the [startAngle]. final bool rotateLinearGradient; + /// Return current percent value if animation is true. + final Function(double value)? onPercentValue; + CircularPercentIndicator({ Key? key, this.percent = 0.0, @@ -134,6 +137,7 @@ class CircularPercentIndicator extends StatefulWidget { this.widgetIndicator, this.rotateLinearGradient = false, this.progressBorderColor, + this.onPercentValue, }) : super(key: key) { if (linearGradient != null && progressColor != null) { throw ArgumentError( @@ -184,6 +188,7 @@ class _CircularPercentIndicatorState extends State )..addListener(() { setState(() { _percent = _animation!.value; + widget.onPercentValue?.call(_percent); }); if (widget.restartAnimation && _percent == 1.0) { _animationController!.repeat(min: 0, max: 1.0); diff --git a/lib/linear_percent_indicator.dart b/lib/linear_percent_indicator.dart index 26a77f7..399583b 100644 --- a/lib/linear_percent_indicator.dart +++ b/lib/linear_percent_indicator.dart @@ -95,6 +95,9 @@ class LinearPercentIndicator extends StatefulWidget { /// Display a widget indicator at the end of the progress. It only works when `animation` is true final Widget? widgetIndicator; + /// Return current percent value if animation is true. + final Function(double value)? onPercentValue; + LinearPercentIndicator({ Key? key, this.fillColor = Colors.transparent, @@ -124,6 +127,7 @@ class LinearPercentIndicator extends StatefulWidget { this.onAnimationEnd, this.widgetIndicator, this.progressBorderColor, + this.onPercentValue, }) : super(key: key) { if (linearGradient != null && progressColor != null) { throw ArgumentError( @@ -189,6 +193,7 @@ class _LinearPercentIndicatorState extends State )..addListener(() { setState(() { _percent = _animation!.value; + widget.onPercentValue?.call(_percent); }); if (widget.restartAnimation && _percent == 1.0) { _animationController!.repeat(min: 0, max: 1.0); @@ -253,56 +258,54 @@ class _LinearPercentIndicatorState extends State final percentPositionedHorizontal = _containerWidth * _percent - _indicatorWidth / 3; //LayoutBuilder is used to get the size of the container where the widget is rendered - var containerWidget = LayoutBuilder( - builder: (context, constraints) { - _containerWidth = constraints.maxWidth; - _containerHeight = constraints.maxHeight; - return Container( - width: hasSetWidth ? widget.width : double.infinity, - height: widget.lineHeight, - padding: widget.padding, - child: Stack( - clipBehavior: Clip.none, - children: [ - CustomPaint( - key: _containerKey, - painter: _LinearPainter( - isRTL: widget.isRTL, - progress: _percent, - progressColor: widget.progressColor, - linearGradient: widget.linearGradient, - backgroundColor: widget.backgroundColor, - barRadius: widget.barRadius ?? - Radius.zero, // If radius is not defined, set it to zero - linearGradientBackgroundColor: + var containerWidget = LayoutBuilder(builder: (context, constraints) { + _containerWidth = constraints.maxWidth; + _containerHeight = constraints.maxHeight; + return Container( + width: hasSetWidth ? widget.width : double.infinity, + height: widget.lineHeight, + padding: widget.padding, + child: Stack( + clipBehavior: Clip.none, + children: [ + CustomPaint( + key: _containerKey, + painter: _LinearPainter( + isRTL: widget.isRTL, + progress: _percent, + progressColor: widget.progressColor, + linearGradient: widget.linearGradient, + backgroundColor: widget.backgroundColor, + barRadius: widget.barRadius ?? + Radius.zero, // If radius is not defined, set it to zero + linearGradientBackgroundColor: widget.linearGradientBackgroundColor, - maskFilter: widget.maskFilter, - clipLinearGradient: widget.clipLinearGradient, - ), - child: (widget.center != null) - ? Center(child: widget.center) - : Container(), - ), - if (widget.widgetIndicator != null && _indicatorWidth == 0) - Opacity( - opacity: 0.0, - key: _keyIndicator, - child: widget.widgetIndicator, - ), - if (widget.widgetIndicator != null && - _containerWidth > 0 && - _indicatorWidth > 0) - Positioned( - right: widget.isRTL ? percentPositionedHorizontal : null, - left: !widget.isRTL ? percentPositionedHorizontal : null, - top: _containerHeight / 2 - _indicatorHeight, - child: widget.widgetIndicator!, - ), - ], + maskFilter: widget.maskFilter, + clipLinearGradient: widget.clipLinearGradient, + ), + child: (widget.center != null) + ? Center(child: widget.center) + : Container(), ), - ); - } - ); + if (widget.widgetIndicator != null && _indicatorWidth == 0) + Opacity( + opacity: 0.0, + key: _keyIndicator, + child: widget.widgetIndicator, + ), + if (widget.widgetIndicator != null && + _containerWidth > 0 && + _indicatorWidth > 0) + Positioned( + right: widget.isRTL ? percentPositionedHorizontal : null, + left: !widget.isRTL ? percentPositionedHorizontal : null, + top: _containerHeight / 2 - _indicatorHeight, + child: widget.widgetIndicator!, + ), + ], + ), + ); + }); if (hasSetWidth) { items.add(containerWidget); From 29b2a6859854c79dbc32a268a2a4ec4b3e9efc8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erik=20Fahl=C3=A9n?= Date: Fri, 17 May 2024 22:16:59 +0200 Subject: [PATCH 5/7] Add an 'initialPercent' field to control the initial animation. (#209) --- lib/circular_percent_indicator.dart | 7 ++++++- lib/linear_percent_indicator.dart | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/circular_percent_indicator.dart b/lib/circular_percent_indicator.dart index 91206fd..65685d6 100644 --- a/lib/circular_percent_indicator.dart +++ b/lib/circular_percent_indicator.dart @@ -73,6 +73,9 @@ class CircularPercentIndicator extends StatefulWidget { /// set true if you want to animate the linear from the last percent value you set final bool animateFromLastPercent; + /// set to false if you do not want the default behavior of initially animating up from 0% + final bool animateToInitialPercent; + /// set false if you don't want to preserve the state of the widget final bool addAutomaticKeepAlive; @@ -129,6 +132,7 @@ class CircularPercentIndicator extends StatefulWidget { this.arcBackgroundColor, this.arcType, this.animateFromLastPercent = false, + this.animateToInitialPercent = true, this.reverse = false, this.curve = Curves.linear, this.maskFilter, @@ -179,11 +183,12 @@ class _CircularPercentIndicatorState extends State @override void initState() { if (widget.animation) { + if (!widget.animateToInitialPercent) _percent = widget.percent; _animationController = AnimationController( vsync: this, duration: Duration(milliseconds: widget.animationDuration), ); - _animation = Tween(begin: 0.0, end: widget.percent).animate( + _animation = Tween(begin: _percent, end: widget.percent).animate( CurvedAnimation(parent: _animationController!, curve: widget.curve), )..addListener(() { setState(() { diff --git a/lib/linear_percent_indicator.dart b/lib/linear_percent_indicator.dart index 399583b..6790aa5 100644 --- a/lib/linear_percent_indicator.dart +++ b/lib/linear_percent_indicator.dart @@ -64,6 +64,9 @@ class LinearPercentIndicator extends StatefulWidget { /// set true if you want to animate the linear from the last percent value you set final bool animateFromLastPercent; + /// set to false if you do not want the default behavior of initially animating up from 0% + final bool animateToInitialPercent; + /// If present, this will make the progress bar colored by this gradient. /// /// This will override [progressColor]. It is an error to provide both. @@ -111,6 +114,7 @@ class LinearPercentIndicator extends StatefulWidget { this.animation = false, this.animationDuration = 500, this.animateFromLastPercent = false, + this.animateToInitialPercent = true, this.isRTL = false, this.leading, this.trailing, @@ -185,10 +189,11 @@ class _LinearPercentIndicatorState extends State } }); if (widget.animation) { + if (!widget.animateToInitialPercent) _percent = widget.percent; _animationController = AnimationController( vsync: this, duration: Duration(milliseconds: widget.animationDuration)); - _animation = Tween(begin: 0.0, end: widget.percent).animate( + _animation = Tween(begin: _percent, end: widget.percent).animate( CurvedAnimation(parent: _animationController!, curve: widget.curve), )..addListener(() { setState(() { From 8f87ceac66733ae66d44460dd8dd26f50877fb0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20Vel=C3=A1squez?= Date: Sat, 23 Nov 2024 11:15:49 -0500 Subject: [PATCH 6/7] Update master.yml --- .github/workflows/master.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/master.yml b/.github/workflows/master.yml index 30bc375..5b19362 100644 --- a/.github/workflows/master.yml +++ b/.github/workflows/master.yml @@ -12,9 +12,9 @@ jobs: - name: 'Checkout' uses: actions/checkout@v1 - name: 'Dry-run' - uses: ilteoood/actions-flutter-pub-publisher@master + uses: Omega365/actions-flutter-pub-publisher@master with: credential: ${{secrets.CREDENTIAL_JSON}} flutter_package: true skip_test: true - dry_run: true \ No newline at end of file + dry_run: true From 11111137f5157240493584da86771ccfe2e4c714 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20Vel=C3=A1squez?= Date: Sat, 23 Nov 2024 11:21:59 -0500 Subject: [PATCH 7/7] Update release.yml --- .github/workflows/release.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index e3daf02..7a424c3 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -56,7 +56,7 @@ jobs: uses: actions/checkout@v1 - name: "Publish Package" - uses: ilteoood/actions-flutter-pub-publisher@master + uses: Omega365/actions-flutter-pub-publisher@master with: credential: "${{secrets.CREDENTIAL_JSON}}" dry_run: false