diff --git a/example/lib/main.dart b/example/lib/main.dart index 9004ce8..173e113 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -170,6 +170,7 @@ class _MyHomePageState extends State pathStrokeWidth: 10, valueStrokeWidth: 10, gapDegree: 60, + roundCap: true, ), ), Text("${_segmentValue / 10 * 100}%"), @@ -200,6 +201,7 @@ class _MyHomePageState extends State valueStrokeWidth: 10.0, useCenter: false, filled: false, + roundCap: true, ), ), Text("${_segmentValue / 10 * 100}%"), @@ -224,6 +226,7 @@ class _MyHomePageState extends State valueStrokeWidth: 10.0, useCenter: true, filled: true, + roundCap: true, ), ), Text("${_segmentValue / 10 * 100}%"), diff --git a/lib/src/circular_state_progress_indicator.dart b/lib/src/circular_state_progress_indicator.dart index 2fab24b..044caeb 100644 --- a/lib/src/circular_state_progress_indicator.dart +++ b/lib/src/circular_state_progress_indicator.dart @@ -24,6 +24,7 @@ class AirCircularStateProgressIndicator extends StatefulWidget { double _valueStrokeWidth; bool _filled; bool _useCenter; + bool _roundCap; /// constructor AirCircularStateProgressIndicator({ @@ -37,6 +38,7 @@ class AirCircularStateProgressIndicator extends StatefulWidget { double valueStrokeWidth = 5, bool filled = false, bool useCenter = false, + bool roundCap = true, }) { assert(size != null); assert(min >= LIMITED_MIN_VALUE); @@ -49,6 +51,7 @@ class AirCircularStateProgressIndicator extends StatefulWidget { assert(valueStrokeWidth != null); assert(filled != null); assert(useCenter != null); + assert(roundCap != null); _size = size; //value _value = value; @@ -64,6 +67,7 @@ class AirCircularStateProgressIndicator extends StatefulWidget { // _filled = filled; _useCenter = useCenter; + _roundCap = roundCap; //The strokeWidth is zero when _filled is true, if (_filled) { @@ -101,8 +105,8 @@ class _CircularStateProgressIndicatorState return Paint() ..color = widget._pathColor ..strokeWidth = widget._pathStrokeWidth - ..strokeCap = StrokeCap.round - ..strokeJoin = StrokeJoin.round + ..strokeCap = widget._roundCap ? StrokeCap.round : StrokeCap.square + ..strokeJoin = widget._roundCap ? StrokeJoin.round : StrokeJoin.bevel ..style = widget._filled ? PaintingStyle.fill : PaintingStyle.stroke; } @@ -110,8 +114,8 @@ class _CircularStateProgressIndicatorState return Paint() ..color = widget._valueColor ..strokeWidth = widget._valueStrokeWidth - ..strokeCap = StrokeCap.round - ..strokeJoin = StrokeJoin.bevel + ..strokeCap = widget._roundCap ? StrokeCap.round : StrokeCap.square + ..strokeJoin = widget._roundCap ? StrokeJoin.round : StrokeJoin.bevel ..style = widget._filled ? PaintingStyle.fill : PaintingStyle.stroke; } } diff --git a/lib/src/linear_state_progress_indicator.dart b/lib/src/linear_state_progress_indicator.dart index 387e8fd..a9b2222 100644 --- a/lib/src/linear_state_progress_indicator.dart +++ b/lib/src/linear_state_progress_indicator.dart @@ -1,6 +1,11 @@ import 'package:ai_progress/src/progress_mixin.dart'; import 'package:flutter/material.dart'; +/// +const double LINEAR_LIMITED_MIN_VALUE = 0; +const double LINEAR_LIMITED_MAX_VALUE = 100; +const double LINEAR_DEFAULT_VALUE = 10; + /// LinearStateProgressIndicator /// // ignore: must_be_immutable @@ -19,9 +24,9 @@ class AirLinearStateProgressIndicator extends StatefulWidget { /// constructor AirLinearStateProgressIndicator({ @required Size size, - double min = 0.0, - double max = 100.0, - double value = 10, + double min = LINEAR_LIMITED_MIN_VALUE, + double max = LINEAR_LIMITED_MAX_VALUE, + double value = LINEAR_DEFAULT_VALUE, Color pathColor = Colors.white, Color valueColor = Colors.green, bool roundCap = true, @@ -29,6 +34,17 @@ class AirLinearStateProgressIndicator extends StatefulWidget { double pathStrokeWidth, double valueStrokeWidth, }) { + assert(size != null); + assert(min >= LINEAR_LIMITED_MIN_VALUE); + assert(max <= LINEAR_LIMITED_MAX_VALUE); + assert(value >= min); + assert(value <= max); + assert(pathColor != null); + assert(valueColor != null); + assert(roundCap != null); + assert(shouldRepaint != null); + assert(pathStrokeWidth != null); + assert(valueStrokeWidth != null); _size = size; _min = min; _max = max; @@ -128,7 +144,6 @@ class LinearProgressPainter extends CustomPainter with ProgressMixin { @override drawProgressPath({Canvas canvas, Paint paint, Size size}) { double heightCenter = size.height / 2; - double widthCenter = size.width / 2; double width = size.width; Offset startPoint = Offset(0, heightCenter); @@ -140,8 +155,6 @@ class LinearProgressPainter extends CustomPainter with ProgressMixin { @override drawProgressValue({Canvas canvas, Paint paint, Size size}) { double heightCenter = size.height / 2; - double widthCenter = size.width / 2; - double width = size.width; Offset startPoint = Offset(0, heightCenter); Offset endPoint = Offset(_getDrawWidthValue(size: size), heightCenter); @@ -164,7 +177,7 @@ class LinearProgressPainter extends CustomPainter with ProgressMixin { } double _getDrawWidthValue({@required Size size}) { - double drawWidthValue = size.width * (_value / _max); + double drawWidthValue = size.width * ((_value - _min) / (_max - _min)); //range size drawWidthValue = drawWidthValue < 0 ? 0 : drawWidthValue; diff --git a/lib/src/step_state_progress_indicator.dart b/lib/src/step_state_progress_indicator.dart index 02c2c7c..8511dfb 100644 --- a/lib/src/step_state_progress_indicator.dart +++ b/lib/src/step_state_progress_indicator.dart @@ -4,6 +4,15 @@ import 'package:flutter/material.dart'; /// AirStepStateProgressIndicator // ignore: must_be_immutable class AirStepStateProgressIndicator extends StatefulWidget { + /// Limited + static const int LIMITED_STEP_MIN_VALUE = 0; + + /// Default values + static const int DEFAULT_STEP_COUNT = 10; + static const int DEFAULT_STEP_VALUE = 1; + static const double DEFAULT_STROKE_WIDTH = 5.0; + static const double DEFAULT_SPACE_WIDTH = 2.0; + final Size size; final int stepCount; final int stepValue; @@ -15,18 +24,32 @@ class AirStepStateProgressIndicator extends StatefulWidget { Color _pathColor; Color _valueColor; + bool _roundCap; + /// constructor AirStepStateProgressIndicator({ this.size, - this.stepCount, - this.stepValue, - double pathStrokeWidth = 5.0, - double valueStrokeWidth = 5.0, - double spaceWidth = 2.0, + this.stepCount = DEFAULT_STEP_COUNT, + this.stepValue = DEFAULT_STEP_VALUE, + double pathStrokeWidth = DEFAULT_STROKE_WIDTH, + double valueStrokeWidth = DEFAULT_STROKE_WIDTH, + double spaceWidth = DEFAULT_SPACE_WIDTH, Color pathColor = Colors.grey, Color valueColor = Colors.green, + bool roundCap = false, }) { - if (stepCount <= 0) {} + assert(size != null); + assert(stepCount != null); + assert(stepCount > LIMITED_STEP_MIN_VALUE); + assert(stepValue != null); + assert(stepValue >= LIMITED_STEP_MIN_VALUE); + assert(stepValue <= stepCount); + assert(pathStrokeWidth != null); + assert(valueStrokeWidth != null); + assert(spaceWidth != null); + assert(pathColor != null); + assert(valueColor != null); + assert(roundCap != null); //stroke width _pathStrokeWidth = pathStrokeWidth; @@ -38,6 +61,9 @@ class AirStepStateProgressIndicator extends StatefulWidget { //color _pathColor = pathColor; _valueColor = valueColor; + + //cap style + _roundCap = roundCap; } @override State createState() { @@ -60,6 +86,7 @@ class _StepStateProgressIndicator extends State { spaceWidth: widget._spaceWidth, pathColor: widget._pathColor, valueColor: widget._valueColor, + roundCap: widget._roundCap, ), ); } @@ -79,6 +106,8 @@ class StepProgressPainter extends CustomPainter with ProgressMixin { Color _valueColor; Color _pathColor; + bool _roundCap; + /// constructor StepProgressPainter._({ @required bool shouldRepaint, @@ -89,6 +118,7 @@ class StepProgressPainter extends CustomPainter with ProgressMixin { double spaceWidth, Color pathColor, Color valueColor, + bool roundCap, }) { //should repaint _shouldRepaint = shouldRepaint; @@ -102,6 +132,7 @@ class StepProgressPainter extends CustomPainter with ProgressMixin { //stroke _pathStrokeWidth = pathStrokeWidth; _valueStrokeWidth = valueStrokeWidth; + _roundCap = roundCap; // _spaceWidth = spaceWidth; @@ -155,8 +186,10 @@ class StepProgressPainter extends CustomPainter with ProgressMixin { Paint _getDrawPathPaint() { return Paint() - ..color = Colors.grey + ..color = pathColor ..style = PaintingStyle.stroke + ..strokeCap = _roundCap ? StrokeCap.round : StrokeCap.butt + ..strokeJoin = _roundCap ? StrokeJoin.round : StrokeJoin.miter ..strokeWidth = pathStrokeWidth; } @@ -164,6 +197,8 @@ class StepProgressPainter extends CustomPainter with ProgressMixin { return Paint() ..color = valueColor ..style = PaintingStyle.stroke + ..strokeCap = _roundCap ? StrokeCap.round : StrokeCap.butt + ..strokeJoin = _roundCap ? StrokeJoin.round : StrokeJoin.miter ..strokeWidth = valueStrokeWidth; }