diff --git a/CHANGELOG.md b/CHANGELOG.md index 8c9220b..7a949f7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## [2.0.0] + +* null safety. + ## [1.0.0] - Stable * adapter: flutter version = v1.22 diff --git a/example/pubspec.lock b/example/pubspec.lock index a24ef73..94f0941 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -7,63 +7,63 @@ packages: path: ".." relative: true source: path - version: "0.2.1" + version: "2.0.0" async: dependency: transitive description: name: async - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted - version: "2.5.0-nullsafety.1" + version: "2.6.0" boolean_selector: dependency: transitive description: name: boolean_selector - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted - version: "2.1.0-nullsafety.1" + version: "2.1.0" characters: dependency: transitive description: name: characters - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted - version: "1.1.0-nullsafety.3" + version: "1.1.0" charcode: dependency: transitive description: name: charcode - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted - version: "1.2.0-nullsafety.1" + version: "1.2.0" clock: dependency: transitive description: name: clock - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted - version: "1.1.0-nullsafety.1" + version: "1.1.0" collection: dependency: transitive description: name: collection - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted - version: "1.15.0-nullsafety.3" + version: "1.15.0" cupertino_icons: dependency: "direct main" description: name: cupertino_icons - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "0.1.3" fake_async: dependency: transitive description: name: fake_async - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted - version: "1.2.0-nullsafety.1" + version: "1.2.0" flutter: dependency: "direct main" description: flutter @@ -78,23 +78,23 @@ packages: dependency: transitive description: name: matcher - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted - version: "0.12.10-nullsafety.1" + version: "0.12.10" meta: dependency: transitive description: name: meta - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted - version: "1.3.0-nullsafety.3" + version: "1.3.0" path: dependency: transitive description: name: path - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted - version: "1.8.0-nullsafety.1" + version: "1.8.0" sky_engine: dependency: transitive description: flutter @@ -104,58 +104,58 @@ packages: dependency: transitive description: name: source_span - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted - version: "1.8.0-nullsafety.2" + version: "1.8.1" stack_trace: dependency: transitive description: name: stack_trace - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted - version: "1.10.0-nullsafety.1" + version: "1.10.0" stream_channel: dependency: transitive description: name: stream_channel - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted - version: "2.1.0-nullsafety.1" + version: "2.1.0" string_scanner: dependency: transitive description: name: string_scanner - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted - version: "1.1.0-nullsafety.1" + version: "1.1.0" term_glyph: dependency: transitive description: name: term_glyph - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted - version: "1.2.0-nullsafety.1" + version: "1.2.0" test_api: dependency: transitive description: name: test_api - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted - version: "0.2.19-nullsafety.2" + version: "0.3.0" typed_data: dependency: transitive description: name: typed_data - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted - version: "1.3.0-nullsafety.3" + version: "1.3.0" vector_math: dependency: transitive description: name: vector_math - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted - version: "2.1.0-nullsafety.3" + version: "2.1.0" sdks: - dart: ">=2.10.0-110 <2.11.0" - flutter: ">=1.20.0 <2.0.0" + dart: ">=2.13.0 <3.0.0" + flutter: ">=1.20.0" diff --git a/lib/src/circular_state_progress_indicator.dart b/lib/src/circular_state_progress_indicator.dart index 044caeb..908475c 100644 --- a/lib/src/circular_state_progress_indicator.dart +++ b/lib/src/circular_state_progress_indicator.dart @@ -14,21 +14,21 @@ class AirCircularStateProgressIndicator extends StatefulWidget { /// default value static const double DEFAULT_VALUE = 10; - Size _size; - double _min; - double _max; - num _value; - Color _pathColor; - Color _valueColor; - double _pathStrokeWidth; - double _valueStrokeWidth; - bool _filled; - bool _useCenter; - bool _roundCap; + Size? _size; + double? _min; + double? _max; + num? _value; + Color? _pathColor; + Color? _valueColor; + double? _pathStrokeWidth; + double? _valueStrokeWidth; + bool? _filled; + bool? _useCenter; + bool? _roundCap; /// constructor AirCircularStateProgressIndicator({ - @required Size size, + required Size size, double min = LIMITED_MIN_VALUE, double max = LIMITED_MAX_VALUE, num value = DEFAULT_VALUE, @@ -40,18 +40,10 @@ class AirCircularStateProgressIndicator extends StatefulWidget { bool useCenter = false, bool roundCap = true, }) { - assert(size != null); assert(min >= LIMITED_MIN_VALUE); assert(max <= LIMITED_MAX_VALUE); assert(value >= min); assert(value <= max); - assert(pathColor != null); - assert(valueColor != null); - assert(pathStrokeWidth != null); - assert(valueStrokeWidth != null); - assert(filled != null); - assert(useCenter != null); - assert(roundCap != null); _size = size; //value _value = value; @@ -70,7 +62,7 @@ class AirCircularStateProgressIndicator extends StatefulWidget { _roundCap = roundCap; //The strokeWidth is zero when _filled is true, - if (_filled) { + if (_filled!) { _pathStrokeWidth = 0.0; _valueStrokeWidth = 0.0; } @@ -88,35 +80,35 @@ class _CircularStateProgressIndicatorState @override Widget build(BuildContext context) { return CustomPaint( - size: widget._size, + size: widget._size!, painter: CircularProgressPaint._( shouldRepaint: false, - min: widget._min, - max: widget._max, - value: widget._value, + min: widget._min!, + max: widget._max!, + value: widget._value!, pathPaint: _getPathPaint(), valuePaint: _getValuePaint(), - useCenter: widget._useCenter, + useCenter: widget._useCenter!, ), ); } Paint _getPathPaint() { return Paint() - ..color = widget._pathColor - ..strokeWidth = widget._pathStrokeWidth - ..strokeCap = widget._roundCap ? StrokeCap.round : StrokeCap.square - ..strokeJoin = widget._roundCap ? StrokeJoin.round : StrokeJoin.bevel - ..style = widget._filled ? PaintingStyle.fill : PaintingStyle.stroke; + ..color = widget._pathColor! + ..strokeWidth = widget._pathStrokeWidth! + ..strokeCap = widget._roundCap! ? StrokeCap.round : StrokeCap.square + ..strokeJoin = widget._roundCap! ? StrokeJoin.round : StrokeJoin.bevel + ..style = widget._filled! ? PaintingStyle.fill : PaintingStyle.stroke; } Paint _getValuePaint() { return Paint() - ..color = widget._valueColor - ..strokeWidth = widget._valueStrokeWidth - ..strokeCap = widget._roundCap ? StrokeCap.round : StrokeCap.square - ..strokeJoin = widget._roundCap ? StrokeJoin.round : StrokeJoin.bevel - ..style = widget._filled ? PaintingStyle.fill : PaintingStyle.stroke; + ..color = widget._valueColor! + ..strokeWidth = widget._valueStrokeWidth! + ..strokeCap = widget._roundCap! ? StrokeCap.round : StrokeCap.square + ..strokeJoin = widget._roundCap! ? StrokeJoin.round : StrokeJoin.bevel + ..style = widget._filled! ? PaintingStyle.fill : PaintingStyle.stroke; } } @@ -132,24 +124,24 @@ class CircularProgressPaint extends CustomPainter with ProgressMixin { /// start angle static const double DEFAULT_START_ANGLE = -1.5; - bool _shouldRepaint; - num _min; - num _max; - num _value; - Paint _pathPaint; - Paint _valuePaint; - bool _useCenter; + bool? _shouldRepaint; + num? _min; + num? _max; + num? _value; + Paint? _pathPaint; + Paint? _valuePaint; + bool? _useCenter; /// CircularProgressPaint /// CircularProgressPaint._({ - @required bool shouldRepaint, - @required num min, - @required num max, - @required num value, - @required Paint pathPaint, - @required Paint valuePaint, - @required bool useCenter, + required bool shouldRepaint, + required num min, + required num max, + required num value, + required Paint pathPaint, + required Paint valuePaint, + required bool useCenter, }) { _shouldRepaint = shouldRepaint; _min = min; @@ -162,26 +154,28 @@ class CircularProgressPaint extends CustomPainter with ProgressMixin { @override void paint(Canvas canvas, Size size) { // draw progress path - drawProgressPath(canvas: canvas, paint: _pathPaint, size: size); + drawProgressPath(canvas: canvas, paint: _pathPaint!, size: size); // draw progress value - drawProgressValue(canvas: canvas, paint: _valuePaint, size: size); + drawProgressValue(canvas: canvas, paint: _valuePaint!, size: size); } @override bool shouldRepaint(CustomPainter oldDelegate) { - return _shouldRepaint; + return _shouldRepaint!; } @override - drawProgressPath({Canvas canvas, Paint paint, Size size}) { + drawProgressPath( + {required Canvas canvas, required Paint paint, required Size size}) { Offset center = _getOffset(size: size); double radius = _getRadius(size: size); canvas.drawCircle(center, radius, paint); } @override - drawProgressValue({Canvas canvas, Paint paint, Size size}) { + drawProgressValue( + {required Canvas canvas, required Paint paint, required Size size}) { Offset center = _getOffset(size: size); double radius = _getRadius(size: size); canvas.drawArc(Rect.fromCircle(center: center, radius: radius), @@ -196,38 +190,38 @@ class CircularProgressPaint extends CustomPainter with ProgressMixin { if (_value == _min) { return 0; } - if (_value > _min && _value < maxHalf) { - return (_value * 0.0612); + if (_value! > _min! && _value! < maxHalf!) { + return (_value! * 0.0612); } if (_value == maxHalf) { - return _value * 0.0600; + return _value! * 0.0600; } - if (_value > maxHalf && _value < _max) {} - if (_value == _max) { - return maxSweepAngleIncludeCap; + if (_value! > maxHalf && _value! < _max!) {} + if (_value! == _max!) { + return maxSweepAngleIncludeCap.toDouble(); } - return (_value * 0.0615); + return (_value! * 0.0615); } /// the half of max value - get maxHalf => _max / 2; + get maxHalf => _max! / 2; /// useCenter /// whether use center point close the path. bool get useCenter { - return _useCenter; + return _useCenter!; } /// circular radius - double _getRadius({Size size}) { + double _getRadius({required Size size}) { double radius = size.width / 2 < size.height / 2 ? size.width / 2 : size.height / 2; - radius -= _valuePaint.strokeWidth / 2; + radius -= _valuePaint!.strokeWidth / 2; return radius; } /// point - Offset _getOffset({Size size}) { + Offset _getOffset({required Size size}) { return Offset(size.width / 2, size.height / 2); } } diff --git a/lib/src/dashboard_state_progress_indicator.dart b/lib/src/dashboard_state_progress_indicator.dart index e52f19b..01df6f9 100644 --- a/lib/src/dashboard_state_progress_indicator.dart +++ b/lib/src/dashboard_state_progress_indicator.dart @@ -18,23 +18,23 @@ const double DEFAULT_STROKE_WIDTH = 5; /// DashboardStateProgressIndicator // ignore: must_be_immutable class AirDashboardStateProgressIndicator extends StatefulWidget { - Size _size; - double _min; - double _max; - num _value; - Color _pathColor; - Color _valueColor; - double _pathStrokeWidth; - double _valueStrokeWidth; - bool _filled; - bool _useCenter; - bool _roundCap; - - double _gapDegree; + Size? _size; + double? _min; + double? _max; + num? _value; + Color? _pathColor; + Color? _valueColor; + double? _pathStrokeWidth; + double? _valueStrokeWidth; + bool? _filled; + bool? _useCenter; + bool? _roundCap; + + double? _gapDegree; /// constructor AirDashboardStateProgressIndicator({ - Size size, + required Size size, double min = LIMITED_MIN_VALUE, double max = LIMITED_MAX_VALUE, num value = DEFAULT_VALUE, @@ -47,20 +47,12 @@ class AirDashboardStateProgressIndicator extends StatefulWidget { bool useCenter = false, bool roundCap = true, }) { - assert(size != null); assert(min >= LIMITED_MIN_VALUE); assert(max <= LIMITED_MAX_VALUE); assert(value >= min); assert(value <= max); assert(gapDegree >= LIMITED_MIN_GAP_DEGREE); assert(gapDegree <= LIMITED_MAX_GAP_DEGREE); - assert(pathColor != null); - assert(valueColor != null); - assert(pathStrokeWidth != null); - assert(valueStrokeWidth != null); - assert(filled != null); - assert(useCenter != null); - assert(roundCap != null); _size = size; //value >= 0.00,value<=100 _value = value; @@ -81,7 +73,7 @@ class AirDashboardStateProgressIndicator extends StatefulWidget { _useCenter = useCenter; //The strokeWidth is zero when _filled is true, - if (_filled) { + if (_filled!) { _pathStrokeWidth = 0.0; _valueStrokeWidth = 0.0; } @@ -99,37 +91,37 @@ class _DashboardStateProgressIndicatorState @override Widget build(BuildContext context) { return CustomPaint( - size: widget._size, + size: widget._size!, painter: DashboardProgressPaint._( shouldRepaint: false, division: LIMITED_MAX_GAP_DEGREE ~/ UNIT_GAP_DEGREE, - min: widget._min, - max: widget._max, - value: widget._value, - gapDegree: widget._gapDegree, + min: widget._min!, + max: widget._max!, + value: widget._value!, + gapDegree: widget._gapDegree!, pathPaint: _getPathPaint(), valuePaint: _getValuePaint(), - useCenter: widget._useCenter, + useCenter: widget._useCenter!, ), ); } Paint _getPathPaint() { return Paint() - ..color = widget._pathColor - ..strokeWidth = widget._pathStrokeWidth - ..strokeCap = widget._roundCap ? StrokeCap.round : StrokeCap.square - ..strokeJoin = widget._roundCap ? StrokeJoin.round : StrokeJoin.bevel - ..style = widget._filled ? PaintingStyle.fill : PaintingStyle.stroke; + ..color = widget._pathColor! + ..strokeWidth = widget._pathStrokeWidth! + ..strokeCap = widget._roundCap! ? StrokeCap.round : StrokeCap.square + ..strokeJoin = widget._roundCap! ? StrokeJoin.round : StrokeJoin.bevel + ..style = widget._filled! ? PaintingStyle.fill : PaintingStyle.stroke; } Paint _getValuePaint() { return Paint() - ..color = widget._valueColor - ..strokeWidth = widget._valueStrokeWidth - ..strokeCap = widget._roundCap ? StrokeCap.round : StrokeCap.square - ..strokeJoin = widget._roundCap ? StrokeJoin.round : StrokeJoin.bevel - ..style = widget._filled ? PaintingStyle.fill : PaintingStyle.stroke; + ..color = widget._valueColor! + ..strokeWidth = widget._valueStrokeWidth! + ..strokeCap = widget._roundCap! ? StrokeCap.round : StrokeCap.square + ..strokeJoin = widget._roundCap! ? StrokeJoin.round : StrokeJoin.bevel + ..style = widget._filled! ? PaintingStyle.fill : PaintingStyle.stroke; } } @@ -140,28 +132,28 @@ class DashboardProgressPaint extends CustomPainter with ProgressMixin { final num maxSweepAngle = 6.5; final num circleMaxSweepAngle = 6.1275; final num minSweepAngle = 1.0; - bool _shouldRepaint; - num _min; - num _max; - num _value; - Paint _pathPaint; - Paint _valuePaint; - bool _useCenter; - double _gapDegree; - int _division; + bool? _shouldRepaint; + num? _min; + num? _max; + num? _value; + Paint? _pathPaint; + Paint? _valuePaint; + bool? _useCenter; + double? _gapDegree; + int? _division; /// CircularProgressPaint /// DashboardProgressPaint._({ - @required bool shouldRepaint, - @required int division, - @required num min, - @required num max, - @required num value, - @required double gapDegree, - @required Paint pathPaint, - @required Paint valuePaint, - @required bool useCenter, + required bool shouldRepaint, + required int division, + required num min, + required num max, + required num value, + required double gapDegree, + required Paint pathPaint, + required Paint valuePaint, + required bool useCenter, }) { _shouldRepaint = shouldRepaint; _division = division; @@ -176,19 +168,20 @@ class DashboardProgressPaint extends CustomPainter with ProgressMixin { @override void paint(Canvas canvas, Size size) { // draw progress path - drawProgressPath(canvas: canvas, paint: _pathPaint, size: size); + drawProgressPath(canvas: canvas, paint: _pathPaint!, size: size); // draw progress value - drawProgressValue(canvas: canvas, paint: _valuePaint, size: size); + drawProgressValue(canvas: canvas, paint: _valuePaint!, size: size); } @override bool shouldRepaint(CustomPainter oldDelegate) { - return _shouldRepaint; + return _shouldRepaint!; } @override - drawProgressPath({Canvas canvas, Paint paint, Size size}) { + drawProgressPath( + {required Canvas canvas, required Paint paint, required Size size}) { Offset center = _getOffset(size: size); double radius = _getRadius(size: size); @@ -197,18 +190,19 @@ class DashboardProgressPaint extends CustomPainter with ProgressMixin { } @override - drawProgressValue({Canvas canvas, Paint paint, Size size}) { + drawProgressValue( + {required Canvas canvas, required Paint paint, required Size size}) { Offset center = _getOffset(size: size); double radius = _getRadius(size: size); canvas.drawArc(Rect.fromCircle(center: center, radius: radius), _getStartAngle(), _getValueSweepAngle(), useCenter, paint); } - double get gapDegree => _gapDegree; - int get division => _division; + double get gapDegree => _gapDegree!; + int get division => _division!; double _getCircleMaxAngle() { - return circleMaxSweepAngle; + return circleMaxSweepAngle.toDouble(); } double _getStartAngle() { @@ -216,7 +210,7 @@ class DashboardProgressPaint extends CustomPainter with ProgressMixin { } double _getGapDegreeSweepAngle() { - return (maxSweepAngle / division) * _gapDegree; + return (maxSweepAngle / division) * _gapDegree!; } double _getMaxSweepAngle() { @@ -224,23 +218,23 @@ class DashboardProgressPaint extends CustomPainter with ProgressMixin { } double _getValueSweepAngle() { - return _getMaxSweepAngle() / _max * _value; + return _getMaxSweepAngle() / _max! * _value!; } /// useCenter /// whether use center point close the path. bool get useCenter { - return _useCenter; + return _useCenter!; } - double _getRadius({Size size}) { + double _getRadius({required Size size}) { double radius = size.width / 2 < size.height / 2 ? size.width / 2 : size.height / 2; - radius -= _valuePaint.strokeWidth / 2; + radius -= _valuePaint!.strokeWidth / 2; return radius; } - Offset _getOffset({Size size}) { + Offset _getOffset({required Size size}) { return Offset(size.width / 2, size.height / 2); } } diff --git a/lib/src/linear_state_progress_indicator.dart b/lib/src/linear_state_progress_indicator.dart index a9b2222..f28443e 100644 --- a/lib/src/linear_state_progress_indicator.dart +++ b/lib/src/linear_state_progress_indicator.dart @@ -10,20 +10,20 @@ const double LINEAR_DEFAULT_VALUE = 10; /// // ignore: must_be_immutable class AirLinearStateProgressIndicator extends StatefulWidget { - double _value; - double _min; - double _max; - Size _size; - bool _shouldRepaint; - bool _roundCap; - Color _pathColor; - Color _valueColor; - double _pathStrokeWidth = 5; - double _valueStrokeWidth = 5; + double? _value; + double? _min; + double? _max; + Size? _size; + bool? _shouldRepaint; + bool? _roundCap; + Color? _pathColor; + Color? _valueColor; + double? _pathStrokeWidth = 5; + double? _valueStrokeWidth = 5; /// constructor AirLinearStateProgressIndicator({ - @required Size size, + required Size size, double min = LINEAR_LIMITED_MIN_VALUE, double max = LINEAR_LIMITED_MAX_VALUE, double value = LINEAR_DEFAULT_VALUE, @@ -31,20 +31,13 @@ class AirLinearStateProgressIndicator extends StatefulWidget { Color valueColor = Colors.green, bool roundCap = true, bool shouldRepaint = false, - double pathStrokeWidth, - double valueStrokeWidth, + 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; @@ -72,17 +65,17 @@ class _LinearStateProgressIndicatorState @override Widget build(BuildContext context) { return CustomPaint( - size: widget._size, + size: widget._size!, painter: LinearProgressPainter._( - shouldRepaint: widget._shouldRepaint, - roundCap: widget._roundCap, - min: widget._min, - max: widget._max, - value: widget._value, - pathColor: widget._pathColor, - valueColor: widget._valueColor, - pathStrokeWidth: widget._pathStrokeWidth, - valueStrokeWidth: widget._valueStrokeWidth, + shouldRepaint: widget._shouldRepaint!, + roundCap: widget._roundCap!, + min: widget._min!, + max: widget._max!, + value: widget._value!, + pathColor: widget._pathColor!, + valueColor: widget._valueColor!, + pathStrokeWidth: widget._pathStrokeWidth!, + valueStrokeWidth: widget._valueStrokeWidth!, ), ); } @@ -90,29 +83,29 @@ class _LinearStateProgressIndicatorState /// LinearProgressPainter class LinearProgressPainter extends CustomPainter with ProgressMixin { - bool _shouldRepaint; - bool _roundCap; - double _min; - double _max; - double _value; + bool? _shouldRepaint; + bool? _roundCap; + double? _min; + double? _max; + double? _value; - Color _pathColor; - Color _valueColor; + Color? _pathColor; + Color? _valueColor; - double _pathStrokeWidth; - double _valueStrokeWidth; + double? _pathStrokeWidth; + double? _valueStrokeWidth; /// constructor LinearProgressPainter._({ - @required bool shouldRepaint, - @required bool roundCap, - @required double min, - @required double max, - @required double value, - @required Color pathColor, - @required Color valueColor, - @required double pathStrokeWidth, - @required double valueStrokeWidth, + required bool shouldRepaint, + required bool roundCap, + required double min, + required double max, + required double value, + required Color pathColor, + required Color valueColor, + required double pathStrokeWidth, + required double valueStrokeWidth, }) { //should repaint _shouldRepaint = shouldRepaint; @@ -138,11 +131,12 @@ class LinearProgressPainter extends CustomPainter with ProgressMixin { @override bool shouldRepaint(CustomPainter oldDelegate) { - return _shouldRepaint; + return _shouldRepaint!; } @override - drawProgressPath({Canvas canvas, Paint paint, Size size}) { + drawProgressPath( + {required Canvas canvas, required Paint paint, required Size size}) { double heightCenter = size.height / 2; double width = size.width; @@ -153,7 +147,8 @@ class LinearProgressPainter extends CustomPainter with ProgressMixin { } @override - drawProgressValue({Canvas canvas, Paint paint, Size size}) { + drawProgressValue( + {required Canvas canvas, required Paint paint, required Size size}) { double heightCenter = size.height / 2; Offset startPoint = Offset(0, heightCenter); @@ -164,20 +159,20 @@ class LinearProgressPainter extends CustomPainter with ProgressMixin { Paint _getDrawPathPaint() { return Paint() - ..color = _pathColor - ..strokeWidth = _pathStrokeWidth - ..strokeCap = _roundCap ? StrokeCap.round : StrokeCap.square; + ..color = _pathColor! + ..strokeWidth = _pathStrokeWidth! + ..strokeCap = _roundCap! ? StrokeCap.round : StrokeCap.square; } Paint _getDrawValuePaint() { return Paint() - ..color = _valueColor - ..strokeWidth = _valueStrokeWidth - ..strokeCap = _roundCap ? StrokeCap.round : StrokeCap.square; + ..color = _valueColor! + ..strokeWidth = _valueStrokeWidth! + ..strokeCap = _roundCap! ? StrokeCap.round : StrokeCap.square; } - double _getDrawWidthValue({@required Size size}) { - double drawWidthValue = size.width * ((_value - _min) / (_max - _min)); + double _getDrawWidthValue({required Size size}) { + double drawWidthValue = size.width * ((_value! - _min!) / (_max! - _min!)); //range size drawWidthValue = drawWidthValue < 0 ? 0 : drawWidthValue; diff --git a/lib/src/progress_mixin.dart b/lib/src/progress_mixin.dart index 7d552ed..524d569 100644 --- a/lib/src/progress_mixin.dart +++ b/lib/src/progress_mixin.dart @@ -3,8 +3,10 @@ import 'dart:ui'; /// ProgressMixin mixin ProgressMixin { /// draw progress path - drawProgressPath({Canvas canvas, Paint paint, Size size}); + drawProgressPath( + {required Canvas canvas, required Paint paint, required Size size}); /// draw progress value - drawProgressValue({Canvas canvas, Paint paint, Size size}); + drawProgressValue( + {required Canvas canvas, required Paint paint, required Size size}); } diff --git a/lib/src/step_state_progress_indicator.dart b/lib/src/step_state_progress_indicator.dart index 857503e..c2a5a2f 100644 --- a/lib/src/step_state_progress_indicator.dart +++ b/lib/src/step_state_progress_indicator.dart @@ -17,16 +17,16 @@ class AirStepStateProgressIndicator extends StatefulWidget { final int stepCount; final int stepValue; - double _pathStrokeWidth; - double _valueStrokeWidth; - double _spaceWidth; + double? _pathStrokeWidth; + double? _valueStrokeWidth; + double? _spaceWidth; - Color _pathColor; - Color _valueColor; + Color? _pathColor; + Color? _valueColor; /// constructor AirStepStateProgressIndicator({ - this.size, + required this.size, this.stepCount = DEFAULT_STEP_COUNT, this.stepValue = DEFAULT_STEP_VALUE, double pathStrokeWidth = DEFAULT_STROKE_WIDTH, @@ -35,17 +35,9 @@ class AirStepStateProgressIndicator extends StatefulWidget { Color pathColor = Colors.grey, Color valueColor = Colors.green, }) { - 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); //stroke width _pathStrokeWidth = pathStrokeWidth; @@ -87,31 +79,31 @@ class _StepStateProgressIndicator extends State { /// StepProgressPainter class StepProgressPainter extends CustomPainter with ProgressMixin { - bool _shouldRepaint; - int _stepCount; - int _stepValue; + bool? _shouldRepaint; + int? _stepCount; + int? _stepValue; - double _pathStrokeWidth; - double _valueStrokeWidth; + double? _pathStrokeWidth; + double? _valueStrokeWidth; - double _spaceWidth; + double? _spaceWidth; - Color _valueColor; - Color _pathColor; + Color? _valueColor; + Color? _pathColor; - bool _roundCap; + bool? _roundCap; /// constructor StepProgressPainter._({ - @required bool shouldRepaint, - @required int stepCount, - @required int stepValue, - double pathStrokeWidth, - double valueStrokeWidth, - double spaceWidth, - Color pathColor, - Color valueColor, - bool roundCap, + required bool shouldRepaint, + required int stepCount, + required int stepValue, + double? pathStrokeWidth, + double? valueStrokeWidth, + double? spaceWidth, + Color? pathColor, + Color? valueColor, + bool? roundCap, }) { //should repaint _shouldRepaint = shouldRepaint; @@ -145,29 +137,35 @@ class StepProgressPainter extends CustomPainter with ProgressMixin { @override bool shouldRepaint(CustomPainter oldDelegate) { - return _shouldRepaint; + return _shouldRepaint!; } @override - drawProgressPath({Canvas canvas, Paint paint, Size size}) { + drawProgressPath( + {required Canvas canvas, required Paint paint, required Size size}) { //draw step progress path _drawStep(canvas: canvas, paint: paint, size: size, loopCount: stepCount); } @override - drawProgressValue({Canvas canvas, Paint paint, Size size}) { + drawProgressValue( + {required Canvas canvas, required Paint paint, required Size size}) { //draw step progress value _drawStep(canvas: canvas, paint: paint, size: size, loopCount: stepValue); } - _drawStep({Canvas canvas, Paint paint, Size size, int loopCount}) { + _drawStep( + {required Canvas canvas, + required Paint paint, + required Size size, + required int loopCount}) { double y = size.height / 2; double startY = y; double endY = y; for (int i = 0; i < loopCount; i++) { - double startX = i * - (_getSingleStepWidth(size: size) + _getSingleSpaceWidth(size: size)); + double startX = + i * (_getSingleStepWidth(size: size) + _getSingleSpaceWidth()); double endX = startX + _getSingleStepWidth(size: size); Offset startPoint = Offset(startX, startY); @@ -181,8 +179,8 @@ class StepProgressPainter extends CustomPainter with ProgressMixin { return Paint() ..color = pathColor ..style = PaintingStyle.stroke - ..strokeCap = _roundCap ? StrokeCap.butt : StrokeCap.butt - ..strokeJoin = _roundCap ? StrokeJoin.miter : StrokeJoin.miter + ..strokeCap = _roundCap! ? StrokeCap.butt : StrokeCap.butt + ..strokeJoin = _roundCap! ? StrokeJoin.miter : StrokeJoin.miter ..strokeWidth = pathStrokeWidth; } @@ -190,27 +188,27 @@ class StepProgressPainter extends CustomPainter with ProgressMixin { return Paint() ..color = valueColor ..style = PaintingStyle.stroke - ..strokeCap = _roundCap ? StrokeCap.butt : StrokeCap.butt - ..strokeJoin = _roundCap ? StrokeJoin.miter : StrokeJoin.miter + ..strokeCap = _roundCap! ? StrokeCap.butt : StrokeCap.butt + ..strokeJoin = _roundCap! ? StrokeJoin.miter : StrokeJoin.miter ..strokeWidth = valueStrokeWidth; } - int get stepCount => _stepCount; + int get stepCount => _stepCount!; - int get stepValue => _stepValue; + int get stepValue => _stepValue!; - Color get valueColor => _valueColor; - Color get pathColor => _pathColor; + Color get valueColor => _valueColor!; + Color get pathColor => _pathColor!; - double get pathStrokeWidth => _pathStrokeWidth; - double get valueStrokeWidth => _valueStrokeWidth; + double get pathStrokeWidth => _pathStrokeWidth!; + double get valueStrokeWidth => _valueStrokeWidth!; - double _getSingleStepWidth({Size size}) { + double _getSingleStepWidth({required Size size}) { return (size.width - ((stepCount - 1) * _getSingleSpaceWidth())) / stepCount; } - double _getSingleSpaceWidth({Size size}) { - return _spaceWidth; + double _getSingleSpaceWidth() { + return _spaceWidth!; } } diff --git a/pubspec.lock b/pubspec.lock index 3107c6e..4079a91 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -1,62 +1,55 @@ # Generated by pub # See https://dart.dev/tools/pub/glossary#lockfile packages: - archive: - dependency: transitive - description: - name: archive - url: "https://pub.dartlang.org" - source: hosted - version: "2.0.13" - args: - dependency: transitive - description: - name: args - url: "https://pub.dartlang.org" - source: hosted - version: "1.6.0" async: dependency: transitive description: name: async - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted - version: "2.4.1" + version: "2.6.0" boolean_selector: dependency: transitive description: name: boolean_selector - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted - version: "2.0.0" + version: "2.1.0" + characters: + dependency: transitive + description: + name: characters + url: "https://pub.flutter-io.cn" + source: hosted + version: "1.1.0" charcode: dependency: transitive description: name: charcode - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted - version: "1.1.3" - collection: + version: "1.2.0" + clock: dependency: transitive description: - name: collection - url: "https://pub.dartlang.org" + name: clock + url: "https://pub.flutter-io.cn" source: hosted - version: "1.14.12" - convert: + version: "1.1.0" + collection: dependency: transitive description: - name: convert - url: "https://pub.dartlang.org" + name: collection + url: "https://pub.flutter-io.cn" source: hosted - version: "2.1.1" - crypto: + version: "1.15.0" + fake_async: dependency: transitive description: - name: crypto - url: "https://pub.dartlang.org" + name: fake_async + url: "https://pub.flutter-io.cn" source: hosted - version: "2.1.4" + version: "1.2.0" flutter: dependency: "direct main" description: flutter @@ -67,48 +60,27 @@ packages: description: flutter source: sdk version: "0.0.0" - image: - dependency: transitive - description: - name: image - url: "https://pub.dartlang.org" - source: hosted - version: "2.1.12" matcher: dependency: transitive description: name: matcher - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted - version: "0.12.6" + version: "0.12.10" meta: dependency: transitive description: name: meta - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted - version: "1.1.8" + version: "1.3.0" path: dependency: transitive description: name: path - url: "https://pub.dartlang.org" - source: hosted - version: "1.6.4" - petitparser: - dependency: transitive - description: - name: petitparser - url: "https://pub.dartlang.org" - source: hosted - version: "2.4.0" - quiver: - dependency: transitive - description: - name: quiver - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted - version: "2.1.3" + version: "1.8.0" sky_engine: dependency: transitive description: flutter @@ -118,64 +90,58 @@ packages: dependency: transitive description: name: source_span - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted - version: "1.7.0" + version: "1.8.1" stack_trace: dependency: transitive description: name: stack_trace - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted - version: "1.9.3" + version: "1.10.0" stream_channel: dependency: transitive description: name: stream_channel - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted - version: "2.0.0" + version: "2.1.0" string_scanner: dependency: transitive description: name: string_scanner - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted - version: "1.0.5" + version: "1.1.0" term_glyph: dependency: transitive description: name: term_glyph - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted - version: "1.1.0" + version: "1.2.0" test_api: dependency: transitive description: name: test_api - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted - version: "0.2.15" + version: "0.3.0" typed_data: dependency: transitive description: name: typed_data - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted - version: "1.1.6" + version: "1.3.0" vector_math: dependency: transitive description: name: vector_math - url: "https://pub.dartlang.org" - source: hosted - version: "2.0.8" - xml: - dependency: transitive - description: - name: xml - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted - version: "3.6.1" + version: "2.1.0" sdks: - dart: ">=2.7.0 <3.0.0" + dart: ">=2.13.0 <3.0.0" + flutter: ">=1.20.0" diff --git a/pubspec.yaml b/pubspec.yaml index b347f49..7676cd6 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,12 +1,12 @@ name: ai_progress description: A new multiple style progress include of circular、linear and step style progress indicator. -version: 1.0.0 +version: 2.0.0 homepage: https://pdliuw.github.io/ repository: https://github.com/pdliuw/ai_progress environment: - sdk: ">=2.7.0 <3.0.0" - flutter: ">=1.20.0 <2.0.0" + sdk: ">=2.13.0 <3.0.0" + flutter: ">=1.20.0" dependencies: flutter: diff --git a/test/aiprogress_test.dart b/test/aiprogress_test.dart index 1a49198..2904e9a 100644 --- a/test/aiprogress_test.dart +++ b/test/aiprogress_test.dart @@ -1,9 +1,12 @@ +import 'package:flutter/cupertino.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:ai_progress/ai_progress.dart'; void main() { test('adds one to input values', () { - AirCircularStateProgressIndicator(); + AirCircularStateProgressIndicator( + size: Size(20, 20), + ); }); }