diff --git a/.gitignore b/.gitignore index cd58b92..41bbaca 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ .packages .pub/ +.idea/ build/ ios/.generated/ diff --git a/.idea/libraries/Dart_SDK.xml b/.idea/libraries/Dart_SDK.xml deleted file mode 100644 index 85ed2e2..0000000 --- a/.idea/libraries/Dart_SDK.xml +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml deleted file mode 100644 index d2ddcba..0000000 --- a/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - diff --git a/.idea/workspace.xml b/.idea/workspace.xml deleted file mode 100644 index 5b3388c..0000000 --- a/.idea/workspace.xml +++ /dev/null @@ -1,36 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/example/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/example/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata index 1d526a1..919434a 100644 --- a/example/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata +++ b/example/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -2,6 +2,6 @@ + location = "self:"> diff --git a/example/lib/sample_linear_page.dart b/example/lib/sample_linear_page.dart index 45182a6..a613d9c 100644 --- a/example/lib/sample_linear_page.dart +++ b/example/lib/sample_linear_page.dart @@ -47,6 +47,24 @@ class _SampleLinearPageState extends State { child: Icon(Icons.airplanemode_active, size: 50)), ), ), + Padding( + padding: EdgeInsets.all(15.0), + child: LinearPercentIndicator( + width: MediaQuery.of(context).size.width - 50, + lineHeight: 20.0, + animationDuration: 3000, + percent: 0.5, + animateFromLastPercent: true, + center: Text("50.0%"), + linearStrokeCap: LinearStrokeCap.butt, + linearGradient: LinearGradient( + colors: [Color(0xffB07BE6), Color(0xff5BA2E0)], + ), + linearGradientBackgroundColor: LinearGradient( + colors: [Color(0xffe5d6fa), Color(0xffc8dff8)], + ), + ), + ), Padding( padding: EdgeInsets.all(15.0), child: FittedBox( diff --git a/example/pubspec.lock b/example/pubspec.lock index a8ea284..fd75cb7 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -33,7 +33,7 @@ packages: path: ".." relative: true source: path - version: "3.3.0" + version: "3.0.0" sky_engine: dependency: transitive description: flutter diff --git a/lib/linear_percent_indicator.dart b/lib/linear_percent_indicator.dart index df68e30..e3bd350 100644 --- a/lib/linear_percent_indicator.dart +++ b/lib/linear_percent_indicator.dart @@ -15,7 +15,11 @@ class LinearPercentIndicator extends StatefulWidget { final Color fillColor; ///First color applied to the complete line - final Color backgroundColor; + Color get backgroundColor => _backgroundColor; + late Color _backgroundColor; + + ///First color applied to the complete line + final LinearGradient? linearGradientBackgroundColor; Color get progressColor => _progressColor; @@ -85,7 +89,8 @@ class LinearPercentIndicator extends StatefulWidget { this.percent = 0.0, this.lineHeight = 5.0, this.width, - this.backgroundColor = const Color(0xFFB8C7CB), + Color? backgroundColor, + this.linearGradientBackgroundColor, this.linearGradient, Color? progressColor, this.animation = false, @@ -112,6 +117,12 @@ class LinearPercentIndicator extends StatefulWidget { } _progressColor = progressColor ?? Colors.red; + if (linearGradientBackgroundColor != null && backgroundColor != null) { + throw ArgumentError( + 'Cannot provide both linearGradientBackgroundColor and backgroundColor'); + } + _backgroundColor = backgroundColor ?? Color(0xFFB8C7CB); + if (percent < 0.0 || percent > 1.0) { throw new Exception("Percent value must be a double between 0.0 and 1.0"); } @@ -241,6 +252,8 @@ class _LinearPercentIndicatorState extends State progressColor: widget.progressColor, linearGradient: widget.linearGradient, backgroundColor: widget.backgroundColor, + linearGradientBackgroundColor: + widget.linearGradientBackgroundColor, linearStrokeCap: widget.linearStrokeCap, lineWidth: widget.lineHeight, maskFilter: widget.maskFilter, @@ -307,6 +320,7 @@ class LinearPainter extends CustomPainter { final Color backgroundColor; final LinearStrokeCap? linearStrokeCap; final LinearGradient? linearGradient; + final LinearGradient? linearGradientBackgroundColor; final MaskFilter? maskFilter; final bool clipLinearGradient; @@ -320,6 +334,7 @@ class LinearPainter extends CustomPainter { this.linearGradient, this.maskFilter, required this.clipLinearGradient, + this.linearGradientBackgroundColor, }) { _paintBackground.color = backgroundColor; _paintBackground.style = PaintingStyle.stroke; @@ -350,6 +365,12 @@ class LinearPainter extends CustomPainter { if (maskFilter != null) { _paintLine.maskFilter = maskFilter; } + if (linearGradientBackgroundColor != null) { + Offset shaderEndPoint = + clipLinearGradient ? Offset.zero : Offset(size.width, size.height); + _paintBackground.shader = linearGradientBackgroundColor + ?.createShader(Rect.fromPoints(Offset.zero, shaderEndPoint)); + } if (isRTL) { final xProgress = size.width - size.width * progress; diff --git a/percent_indicator.iml b/percent_indicator.iml index 8d48a06..0def12d 100644 --- a/percent_indicator.iml +++ b/percent_indicator.iml @@ -1,19 +1,28 @@ + + + + + + + + + - + - + \ No newline at end of file