diff --git a/README.md b/README.md index 0aa3d21..742591d 100644 --- a/README.md +++ b/README.md @@ -14,17 +14,17 @@ Now, you can click [this site](https://tinoguo.github.io/loading_indicator/) to ## Animation types -| Type | Type | Type | Type | -|---|---|---|---| -|1. ballPulse | 2. ballGridPulse | 3. ballClipRotate | 4. squareSpin| -|5. ballClipRotatePulse | 6. ballClipRotateMultiple | 7. ballPulseRise | 8. ballRotate| -|9. cubeTransition | 10. ballZigZag | 11. ballZigZagDeflect | 12. ballTrianglePath| -|13. ballTrianglePathColored | 14.ballTrianglePathColoredFilled | 15. ballScale | 16. lineScale| -|17. lineScaleParty | 18. ballScaleMultiple | 19. ballPulseSync | 20. ballBeat| -|21. lineScalePulseOut | 22. lineScalePulseOutRapid |23. ballScaleRipple | 24. ballScaleRippleMultiple| -|25. ballSpinFadeLoader | 26. lineSpinFadeLoader | 27. triangleSkewSpin | 28. pacman| -|29. ballGridBeat | 30. semiCircleSpin| 31. ballRotateChase | 32. orbit| -|33. audioEqualizer | 34. circleStrokeSpin| +| Type | Type | Type | Type | +|-----------------------------|----------------------------------|-----------------------|-----------------------------| +| 1. ballPulse | 2. ballGridPulse | 3. ballClipRotate | 4. squareSpin | +| 5. ballClipRotatePulse | 6. ballClipRotateMultiple | 7. ballPulseRise | 8. ballRotate | +| 9. cubeTransition | 10. ballZigZag | 11. ballZigZagDeflect | 12. ballTrianglePath | +| 13. ballTrianglePathColored | 14.ballTrianglePathColoredFilled | 15. ballScale | 16. lineScale | +| 17. lineScaleParty | 18. ballScaleMultiple | 19. ballPulseSync | 20. ballBeat | +| 21. lineScalePulseOut | 22. lineScalePulseOutRapid | 23. ballScaleRipple | 24. ballScaleRippleMultiple | +| 25. ballSpinFadeLoader | 26. lineSpinFadeLoader | 27. triangleSkewSpin | 28. pacman | +| 29. ballGridBeat | 30. semiCircleSpin | 31. ballRotateChase | 32. orbit | +| 33. audioEqualizer | 34. circleStrokeSpin | ## Installing Install the latest version from [pub](https://pub.dev/packages/loading_indicator) diff --git a/README_CN.md b/README_CN.md index 184b143..91c29ec 100644 --- a/README_CN.md +++ b/README_CN.md @@ -15,17 +15,17 @@ ## 动画类型 -| Type | Type | Type | Type | -|---|---|---|---| -|1. ballPulse | 2. ballGridPulse | 3. ballClipRotate | 4. squareSpin| -|5. ballClipRotatePulse | 6. ballClipRotateMultiple | 7. ballPulseRise | 8. ballRotate| -|9. cubeTransition | 10. ballZigZag | 11. ballZigZagDeflect | 12. ballTrianglePath| -|13. ballTrianglePathColored | 14.ballTrianglePathColoredFilled | 15. ballScale | 16. lineScale| -|17. lineScaleParty | 18. ballScaleMultiple | 19. ballPulseSync | 20. ballBeat| -|21. lineScalePulseOut | 22. lineScalePulseOutRapid |23. ballScaleRipple | 24. ballScaleRippleMultiple| -|25. ballSpinFadeLoader | 26. lineSpinFadeLoader | 27. triangleSkewSpin | 28. pacman| -|29. ballGridBeat | 30. semiCircleSpin| 31. ballRotateChase | 32. orbit| -|33. audioEqualizer | 34. circleStrokeSpin| +| Type | Type | Type | Type | +|-----------------------------|----------------------------------|-----------------------|-----------------------------| +| 1. ballPulse | 2. ballGridPulse | 3. ballClipRotate | 4. squareSpin | +| 5. ballClipRotatePulse | 6. ballClipRotateMultiple | 7. ballPulseRise | 8. ballRotate | +| 9. cubeTransition | 10. ballZigZag | 11. ballZigZagDeflect | 12. ballTrianglePath | +| 13. ballTrianglePathColored | 14.ballTrianglePathColoredFilled | 15. ballScale | 16. lineScale | +| 17. lineScaleParty | 18. ballScaleMultiple | 19. ballPulseSync | 20. ballBeat | +| 21. lineScalePulseOut | 22. lineScalePulseOutRapid | 23. ballScaleRipple | 24. ballScaleRippleMultiple | +| 25. ballSpinFadeLoader | 26. lineSpinFadeLoader | 27. triangleSkewSpin | 28. pacman | +| 29. ballGridBeat | 30. semiCircleSpin | 31. ballRotateChase | 32. orbit | +| 33. audioEqualizer | 34. circleStrokeSpin | ## 安装 从[pub](https://pub.dev/packages/loading_indicator)安装最新版本。 diff --git a/example/lib/main.dart b/example/lib/main.dart index 62525a6..5303744 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -50,7 +50,7 @@ class MainWidget extends StatelessWidget { child: LoadingIndicator( indicatorType: indicator, colors: _kDefaultRainbowColors, - strokeWidth: 4.0, + strokeWidth: 40.0, pathBackgroundColor: showPathBackground ? Colors.black45 : null, ), diff --git a/example/macos/Runner.xcodeproj/project.pbxproj b/example/macos/Runner.xcodeproj/project.pbxproj index cc89c87..d9333e4 100644 --- a/example/macos/Runner.xcodeproj/project.pbxproj +++ b/example/macos/Runner.xcodeproj/project.pbxproj @@ -3,7 +3,7 @@ archiveVersion = 1; classes = { }; - objectVersion = 51; + objectVersion = 54; objects = { /* Begin PBXAggregateTarget section */ @@ -182,7 +182,7 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0920; - LastUpgradeCheck = 0930; + LastUpgradeCheck = 1300; ORGANIZATIONNAME = ""; TargetAttributes = { 33CC10EC2044A3C60003C045 = { @@ -235,6 +235,7 @@ /* Begin PBXShellScriptBuildPhase section */ 3399D490228B24CF009A79C7 /* ShellScript */ = { isa = PBXShellScriptBuildPhase; + alwaysOutOfDate = 1; buildActionMask = 2147483647; files = ( ); @@ -344,7 +345,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - MACOSX_DEPLOYMENT_TARGET = 10.11; + MACOSX_DEPLOYMENT_TARGET = 10.14; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = macosx; SWIFT_COMPILATION_MODE = wholemodule; @@ -423,7 +424,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - MACOSX_DEPLOYMENT_TARGET = 10.11; + MACOSX_DEPLOYMENT_TARGET = 10.14; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; SDKROOT = macosx; @@ -470,7 +471,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - MACOSX_DEPLOYMENT_TARGET = 10.11; + MACOSX_DEPLOYMENT_TARGET = 10.14; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = macosx; SWIFT_COMPILATION_MODE = wholemodule; diff --git a/example/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme b/example/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme index ae8ff59..7fd7126 100644 --- a/example/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme +++ b/example/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme @@ -1,6 +1,6 @@ 0); - double get strokeWidth => _strokeWidth ?? _kDefaultStrokeWidth; + double get strokeWidth => _strokeWidth ?? 0; Function get _deepEq => const DeepCollectionEquality().equals; diff --git a/lib/src/indicators/audio_equalizer.dart b/lib/src/indicators/audio_equalizer.dart index 32f0d7a..1b3c4b1 100644 --- a/lib/src/indicators/audio_equalizer.dart +++ b/lib/src/indicators/audio_equalizer.dart @@ -75,7 +75,7 @@ class _AudioEqualizerState extends State ); }, child: IndicatorShapeWidget( - shape: Shape.rectangle, + shape: const Square(), index: i ~/ 2, ), ), diff --git a/lib/src/indicators/ball_beat.dart b/lib/src/indicators/ball_beat.dart index 7ae67fe..c9af5d7 100644 --- a/lib/src/indicators/ball_beat.dart +++ b/lib/src/indicators/ball_beat.dart @@ -59,7 +59,7 @@ class _BallBeatState extends State child: ScaleTransition( scale: _scaleAnimations[i ~/ 2], child: IndicatorShapeWidget( - shape: Shape.circle, + shape: const Circle(), index: i ~/ 2, ), ), diff --git a/lib/src/indicators/ball_clip_rotate.dart b/lib/src/indicators/ball_clip_rotate.dart index 2081290..4044657 100644 --- a/lib/src/indicators/ball_clip_rotate.dart +++ b/lib/src/indicators/ball_clip_rotate.dart @@ -56,7 +56,7 @@ class _BallClipRotateState extends State child: child, ); }, - child: const IndicatorShapeWidget(shape: Shape.ringThirdFour), + child: const IndicatorShapeWidget(shape: RingThirdFour()), ); } } diff --git a/lib/src/indicators/ball_clip_rotate_multiple.dart b/lib/src/indicators/ball_clip_rotate_multiple.dart index d403779..6f89bfb 100644 --- a/lib/src/indicators/ball_clip_rotate_multiple.dart +++ b/lib/src/indicators/ball_clip_rotate_multiple.dart @@ -72,7 +72,7 @@ class _BallClipRotateMultipleState extends State ), ], ), - child: const IndicatorShapeWidget(shape: Shape.ringTwoHalfVertical), + child: const IndicatorShapeWidget(shape: RingTwoHalfVertical()), ), ); } diff --git a/lib/src/indicators/ball_clip_rotate_pulse.dart b/lib/src/indicators/ball_clip_rotate_pulse.dart index 184f204..8ee6957 100644 --- a/lib/src/indicators/ball_clip_rotate_pulse.dart +++ b/lib/src/indicators/ball_clip_rotate_pulse.dart @@ -58,14 +58,14 @@ class _BallClipRotatePulseState extends State ..scale(_outCircleScale.value) ..rotateZ(_outCircleRotate.value), child: const IndicatorShapeWidget( - shape: Shape.ringTwoHalfVertical, + shape: RingTwoHalfVertical(), index: 0, ), ), Transform.scale( scale: _innerCircle.value * 0.3, child: const IndicatorShapeWidget( - shape: Shape.circle, + shape: Circle(), index: 1, ), ), diff --git a/lib/src/indicators/ball_grid_beat.dart b/lib/src/indicators/ball_grid_beat.dart index 83cf6ea..1385b2c 100644 --- a/lib/src/indicators/ball_grid_beat.dart +++ b/lib/src/indicators/ball_grid_beat.dart @@ -72,7 +72,7 @@ class _BallGridBeatState extends State child: FadeTransition( opacity: _animations[i], child: IndicatorShapeWidget( - shape: Shape.circle, + shape: const Circle(), index: i, ), ), diff --git a/lib/src/indicators/ball_grid_pulse.dart b/lib/src/indicators/ball_grid_pulse.dart index ae9b56b..7b2f5bd 100644 --- a/lib/src/indicators/ball_grid_pulse.dart +++ b/lib/src/indicators/ball_grid_pulse.dart @@ -82,7 +82,7 @@ class _BallGridPulseState extends State child: FadeTransition( opacity: _opacityAnimations[i], child: IndicatorShapeWidget( - shape: Shape.circle, + shape: const Circle(), index: i, ), ), diff --git a/lib/src/indicators/ball_pulse.dart b/lib/src/indicators/ball_pulse.dart index 5decdd2..80f42b0 100644 --- a/lib/src/indicators/ball_pulse.dart +++ b/lib/src/indicators/ball_pulse.dart @@ -65,7 +65,7 @@ class _BallPulseState extends State child: ScaleTransition( scale: _scaleAnimations[i], child: IndicatorShapeWidget( - shape: Shape.circle, + shape: const Circle(), index: i, ), ), diff --git a/lib/src/indicators/ball_pulse_rise.dart b/lib/src/indicators/ball_pulse_rise.dart index cca1ed2..c7df192 100644 --- a/lib/src/indicators/ball_pulse_rise.dart +++ b/lib/src/indicators/ball_pulse_rise.dart @@ -102,7 +102,7 @@ class _BallPulseRiseState extends State ); }, child: IndicatorShapeWidget( - shape: Shape.circle, + shape: const Circle(), index: index, ), ); diff --git a/lib/src/indicators/ball_pulse_sync.dart b/lib/src/indicators/ball_pulse_sync.dart index 754253d..6a9eed2 100644 --- a/lib/src/indicators/ball_pulse_sync.dart +++ b/lib/src/indicators/ball_pulse_sync.dart @@ -62,7 +62,7 @@ class _BallPulseSyncState extends State ); }, child: IndicatorShapeWidget( - shape: Shape.circle, + shape: const Circle(), index: i, ), ), diff --git a/lib/src/indicators/ball_rotate.dart b/lib/src/indicators/ball_rotate.dart index a556ee2..fcf848a 100644 --- a/lib/src/indicators/ball_rotate.dart +++ b/lib/src/indicators/ball_rotate.dart @@ -63,7 +63,7 @@ class _BallRotateState extends State return Opacity( opacity: opacity, child: IndicatorShapeWidget( - shape: Shape.circle, + shape: const Circle(), index: index, ), ); diff --git a/lib/src/indicators/ball_rotate_chase.dart b/lib/src/indicators/ball_rotate_chase.dart index faaa4d4..0456392 100644 --- a/lib/src/indicators/ball_rotate_chase.dart +++ b/lib/src/indicators/ball_rotate_chase.dart @@ -75,7 +75,7 @@ class _BallRotateChaseState extends State ); }, child: IndicatorShapeWidget( - shape: Shape.circle, + shape: const Circle(), index: i, ), ), diff --git a/lib/src/indicators/ball_scale.dart b/lib/src/indicators/ball_scale.dart index 5ec0330..f6726fc 100644 --- a/lib/src/indicators/ball_scale.dart +++ b/lib/src/indicators/ball_scale.dart @@ -36,7 +36,7 @@ class _BallScaleState extends State opacity: _opacityAnimation, child: ScaleTransition( scale: _scaleAnimation, - child: const IndicatorShapeWidget(shape: Shape.circle), + child: const IndicatorShapeWidget(shape: Circle()), ), ); } diff --git a/lib/src/indicators/ball_scale_multiple.dart b/lib/src/indicators/ball_scale_multiple.dart index 731297b..c339e4e 100644 --- a/lib/src/indicators/ball_scale_multiple.dart +++ b/lib/src/indicators/ball_scale_multiple.dart @@ -54,7 +54,7 @@ class _BallScaleMultipleState extends State child: FadeTransition( opacity: _opacityAnimations[i], child: IndicatorShapeWidget( - shape: Shape.circle, + shape: const Circle(), index: i, ), ), diff --git a/lib/src/indicators/ball_scale_ripple.dart b/lib/src/indicators/ball_scale_ripple.dart index 3a08cf8..d05bdff 100644 --- a/lib/src/indicators/ball_scale_ripple.dart +++ b/lib/src/indicators/ball_scale_ripple.dart @@ -42,7 +42,7 @@ class _BallScaleRippleState extends State opacity: _opacityAnimation, child: ScaleTransition( scale: _scaleAnimation, - child: const IndicatorShapeWidget(shape: Shape.ring), + child: const IndicatorShapeWidget(shape: Ring()), ), ); } diff --git a/lib/src/indicators/ball_scale_ripple_multiple.dart b/lib/src/indicators/ball_scale_ripple_multiple.dart index 6d68c4f..170304c 100644 --- a/lib/src/indicators/ball_scale_ripple_multiple.dart +++ b/lib/src/indicators/ball_scale_ripple_multiple.dart @@ -56,7 +56,7 @@ class _BallScaleRippleMultipleState extends State child: FadeTransition( opacity: _opacityAnimations[i], child: IndicatorShapeWidget( - shape: Shape.ring, + shape: const Ring(), index: i, ), ), diff --git a/lib/src/indicators/ball_spin_fade_loader.dart b/lib/src/indicators/ball_spin_fade_loader.dart index 487883a..b5700d4 100644 --- a/lib/src/indicators/ball_spin_fade_loader.dart +++ b/lib/src/indicators/ball_spin_fade_loader.dart @@ -72,7 +72,7 @@ class _BallSpinFadeLoaderState extends State child: ScaleTransition( scale: _scaleAnimations[i], child: IndicatorShapeWidget( - shape: Shape.circle, + shape: const Circle(), index: i, ), ), diff --git a/lib/src/indicators/ball_triangle_path.dart b/lib/src/indicators/ball_triangle_path.dart index 71446e0..ba7059e 100644 --- a/lib/src/indicators/ball_triangle_path.dart +++ b/lib/src/indicators/ball_triangle_path.dart @@ -119,7 +119,7 @@ class _BallTrianglePathState extends State ); }, child: IndicatorShapeWidget( - shape: Shape.ring, + shape: const Ring(), index: index, ), ); diff --git a/lib/src/indicators/ball_triangle_path_colored.dart b/lib/src/indicators/ball_triangle_path_colored.dart index ef8505b..5ba792b 100644 --- a/lib/src/indicators/ball_triangle_path_colored.dart +++ b/lib/src/indicators/ball_triangle_path_colored.dart @@ -119,7 +119,7 @@ class _BallTrianglePathColoredState extends State ); }, child: IndicatorShapeWidget( - shape: widget.isFilled ? Shape.circle : Shape.ring, + shape: widget.isFilled ? const Circle() : const Ring(), index: index, ), ); diff --git a/lib/src/indicators/ball_zig_zag.dart b/lib/src/indicators/ball_zig_zag.dart index 526e70b..9934df5 100644 --- a/lib/src/indicators/ball_zig_zag.dart +++ b/lib/src/indicators/ball_zig_zag.dart @@ -62,7 +62,7 @@ class _BallZigZagState extends State ..translate(deltaX * _animation.value.dx, deltaY * _animation.value.dy), child: const IndicatorShapeWidget( - shape: Shape.circle, + shape: Circle(), index: 0, ), ), @@ -74,7 +74,7 @@ class _BallZigZagState extends State ..translate(deltaX * -_animation.value.dx, deltaY * -_animation.value.dy), child: const IndicatorShapeWidget( - shape: Shape.circle, + shape: Circle(), index: 1, ), ), diff --git a/lib/src/indicators/ball_zig_zag_deflect.dart b/lib/src/indicators/ball_zig_zag_deflect.dart index 6f7c445..984865b 100644 --- a/lib/src/indicators/ball_zig_zag_deflect.dart +++ b/lib/src/indicators/ball_zig_zag_deflect.dart @@ -61,7 +61,7 @@ class _BallZigZagDeflectState extends State ..translate(deltaX * _animation.value.dx, deltaY * _animation.value.dy), child: const IndicatorShapeWidget( - shape: Shape.circle, + shape: Circle(), index: 0, ), ), @@ -73,7 +73,7 @@ class _BallZigZagDeflectState extends State ..translate(deltaX * -_animation.value.dx, deltaY * -_animation.value.dy), child: const IndicatorShapeWidget( - shape: Shape.circle, + shape: Circle(), index: 1, ), ), diff --git a/lib/src/indicators/circle_stroke_spin.dart b/lib/src/indicators/circle_stroke_spin.dart index c0ecdc3..d43bdd7 100644 --- a/lib/src/indicators/circle_stroke_spin.dart +++ b/lib/src/indicators/circle_stroke_spin.dart @@ -1,6 +1,8 @@ import 'package:flutter/material.dart'; import 'package:loading_indicator/src/decorate/decorate.dart'; +const double _kDefaultStrokeWidth = 2; + /// CircleStrokeSpin. class CircleStrokeSpin extends StatelessWidget { const CircleStrokeSpin({Key? key}) : super(key: key); @@ -8,8 +10,9 @@ class CircleStrokeSpin extends StatelessWidget { @override Widget build(BuildContext context) { final color = DecorateContext.of(context)!.decorateData.colors.first; + final strokeWidth = DecorateContext.of(context)!.decorateData.strokeWidth; return CircularProgressIndicator( - strokeWidth: DecorateContext.of(context)!.decorateData.strokeWidth, + strokeWidth: strokeWidth == 0 ? _kDefaultStrokeWidth : strokeWidth, color: color, backgroundColor: DecorateContext.of(context)!.decorateData.pathBackgroundColor, diff --git a/lib/src/indicators/cube_transition.dart b/lib/src/indicators/cube_transition.dart index 5c95135..7275fd8 100644 --- a/lib/src/indicators/cube_transition.dart +++ b/lib/src/indicators/cube_transition.dart @@ -91,7 +91,7 @@ class _CubeTransitionState extends State ..rotateZ(_rotateAnimation.value) ..scale(_scaleAnimation.value), child: const IndicatorShapeWidget( - shape: Shape.rectangle, + shape: Square(), index: 0, ), ), @@ -107,7 +107,7 @@ class _CubeTransitionState extends State ..rotateZ(_rotateAnimation.value) ..scale(_scaleAnimation.value), child: const IndicatorShapeWidget( - shape: Shape.rectangle, + shape: Square(), index: 1, ), ), diff --git a/lib/src/indicators/line_scale.dart b/lib/src/indicators/line_scale.dart index efcf897..756aec2 100644 --- a/lib/src/indicators/line_scale.dart +++ b/lib/src/indicators/line_scale.dart @@ -2,6 +2,8 @@ import 'package:flutter/material.dart'; import 'package:loading_indicator/src/indicators/base/indicator_controller.dart'; import 'package:loading_indicator/src/shape/indicator_painter.dart'; +import '../decorate/decorate.dart'; + /// LineScale. class LineScale extends StatefulWidget { const LineScale({Key? key}) : super(key: key); @@ -45,6 +47,7 @@ class _LineScaleState extends State @override Widget build(BuildContext context) { + final strokeWidth = DecorateContext.of(context)!.decorateData.strokeWidth; List widgets = _animations .asMap() .entries @@ -56,7 +59,7 @@ class _LineScaleState extends State return FractionallySizedBox( heightFactor: entry.value.value, child: IndicatorShapeWidget( - shape: Shape.line, + shape: Line(strokeWidth: strokeWidth), index: entry.key, ), ); diff --git a/lib/src/indicators/line_scale_party.dart b/lib/src/indicators/line_scale_party.dart index 9615643..7c09929 100644 --- a/lib/src/indicators/line_scale_party.dart +++ b/lib/src/indicators/line_scale_party.dart @@ -2,6 +2,8 @@ import 'package:flutter/material.dart'; import 'package:loading_indicator/src/indicators/base/indicator_controller.dart'; import 'package:loading_indicator/src/shape/indicator_painter.dart'; +import '../decorate/decorate.dart'; + /// LineScaleParty. class LineScaleParty extends StatefulWidget { const LineScaleParty({Key? key}) : super(key: key); @@ -44,6 +46,7 @@ class _LineScalePartyState extends State @override Widget build(BuildContext context) { + final strokeWidth = DecorateContext.of(context)!.decorateData.strokeWidth; List widgets = _animations .asMap() .entries @@ -55,7 +58,7 @@ class _LineScalePartyState extends State return FractionallySizedBox( heightFactor: entry.value.value, child: IndicatorShapeWidget( - shape: Shape.line, + shape: Line(strokeWidth: strokeWidth), index: entry.key, ), ); diff --git a/lib/src/indicators/line_scale_pulse_out.dart b/lib/src/indicators/line_scale_pulse_out.dart index e1ac7b7..7f5b491 100644 --- a/lib/src/indicators/line_scale_pulse_out.dart +++ b/lib/src/indicators/line_scale_pulse_out.dart @@ -2,6 +2,8 @@ import 'package:flutter/material.dart'; import 'package:loading_indicator/src/indicators/base/indicator_controller.dart'; import 'package:loading_indicator/src/shape/indicator_painter.dart'; +import '../decorate/decorate.dart'; + /// LineScalePulseOut. class LineScalePulseOut extends StatefulWidget { const LineScalePulseOut({Key? key}) : super(key: key); @@ -42,6 +44,7 @@ class _LineScalePulseOutState extends State @override Widget build(BuildContext context) { + final strokeWidth = DecorateContext.of(context)!.decorateData.strokeWidth; final widgets = List.filled(9, Container()); for (int i = 0; i < widgets.length; i++) { if (i.isEven) { @@ -52,7 +55,7 @@ class _LineScalePulseOutState extends State return FractionallySizedBox( heightFactor: _animations[i ~/ 2].value, child: IndicatorShapeWidget( - shape: Shape.line, + shape: Line(strokeWidth: strokeWidth), index: i ~/ 2, ), ); diff --git a/lib/src/indicators/line_scale_pulse_out_rapid.dart b/lib/src/indicators/line_scale_pulse_out_rapid.dart index 648eb27..cf874c9 100644 --- a/lib/src/indicators/line_scale_pulse_out_rapid.dart +++ b/lib/src/indicators/line_scale_pulse_out_rapid.dart @@ -2,6 +2,8 @@ import 'package:flutter/material.dart'; import 'package:loading_indicator/src/indicators/base/indicator_controller.dart'; import 'package:loading_indicator/src/shape/indicator_painter.dart'; +import '../decorate/decorate.dart'; + /// LineScalePulseOutRapid. class LineScalePulseOutRapid extends StatefulWidget { const LineScalePulseOutRapid({Key? key}) : super(key: key); @@ -44,6 +46,7 @@ class _LineScalePulseOutRapidState extends State @override Widget build(BuildContext context) { + final strokeWidth = DecorateContext.of(context)!.decorateData.strokeWidth; final widgets = List.filled(9, Container()); for (int i = 0; i < widgets.length; i++) { if (i.isEven) { @@ -54,7 +57,7 @@ class _LineScalePulseOutRapidState extends State return FractionallySizedBox( heightFactor: _animations[i ~/ 2].value, child: IndicatorShapeWidget( - shape: Shape.line, + shape: Line(strokeWidth: strokeWidth), index: i ~/ 2, ), ); diff --git a/lib/src/indicators/line_spin_fade_loader.dart b/lib/src/indicators/line_spin_fade_loader.dart index a722054..49fdcb9 100644 --- a/lib/src/indicators/line_spin_fade_loader.dart +++ b/lib/src/indicators/line_spin_fade_loader.dart @@ -4,6 +4,8 @@ import 'package:flutter/material.dart'; import 'package:loading_indicator/src/indicators/base/indicator_controller.dart'; import 'package:loading_indicator/src/shape/indicator_painter.dart'; +import '../decorate/decorate.dart'; + /// LineSpinFadeLoader. class LineSpinFadeLoader extends StatefulWidget { const LineSpinFadeLoader({Key? key}) : super(key: key); @@ -46,6 +48,7 @@ class _LineSpinFadeLoaderState extends State @override Widget build(BuildContext context) { + final strokeWidth = DecorateContext.of(context)!.decorateData.strokeWidth; return LayoutBuilder(builder: (ctx, constraint) { final circleSize = constraint.maxWidth / 3; @@ -65,7 +68,7 @@ class _LineSpinFadeLoaderState extends State child: Transform.rotate( angle: -angle, child: IndicatorShapeWidget( - shape: Shape.line, + shape: Line(strokeWidth: strokeWidth), index: i, ), ), diff --git a/lib/src/indicators/orbit.dart b/lib/src/indicators/orbit.dart index 31017ec..86a0fcd 100644 --- a/lib/src/indicators/orbit.dart +++ b/lib/src/indicators/orbit.dart @@ -87,7 +87,7 @@ class _OrbitState extends State child: ScaleTransition( scale: _coreAnimation, child: const IndicatorShapeWidget( - shape: Shape.circle, + shape: Circle(), index: 0, ), ), @@ -99,7 +99,7 @@ class _OrbitState extends State child: ScaleTransition( scale: _ring1ScaleAnimation, child: const IndicatorShapeWidget( - shape: Shape.circle, + shape: Circle(), index: 1, ), ), @@ -112,7 +112,7 @@ class _OrbitState extends State child: ScaleTransition( scale: _ring2ScaleAnimation, child: const IndicatorShapeWidget( - shape: Shape.circle, + shape: Circle(), index: 2, ), ), @@ -128,7 +128,7 @@ class _OrbitState extends State offset: Offset(sin(_satelliteAnimation.value) * deltaX, -cos(_satelliteAnimation.value) * deltaY), child: const IndicatorShapeWidget( - shape: Shape.circle, + shape: Circle(), index: 3, ), ); diff --git a/lib/src/indicators/pacman.dart b/lib/src/indicators/pacman.dart index 5998ee0..2229ced 100644 --- a/lib/src/indicators/pacman.dart +++ b/lib/src/indicators/pacman.dart @@ -90,7 +90,7 @@ class _PacmanState extends State animation: _rotateAnimation, builder: (_, child) { return IndicatorShapeWidget( - shape: Shape.arc, + shape: const Arc(), data: _rotateAnimation.value, index: 0, ); @@ -111,14 +111,14 @@ class _PacmanState extends State opacity: _opacityAnimations[i], child: AnimatedBuilder( animation: _translateXAnimations[i], - child: const IndicatorShapeWidget(shape: Shape.circle), + child: const IndicatorShapeWidget(shape: Circle()), builder: (_, child) { return Transform.translate( offset: Offset( _translateXAnimations[i].value * constraint.maxWidth / 2, 0.0), child: IndicatorShapeWidget( - shape: Shape.circle, + shape: const Circle(), index: i + 1, ), ); diff --git a/lib/src/indicators/semi_circle_spin.dart b/lib/src/indicators/semi_circle_spin.dart index 7681a65..9c1575a 100644 --- a/lib/src/indicators/semi_circle_spin.dart +++ b/lib/src/indicators/semi_circle_spin.dart @@ -35,7 +35,7 @@ class _SemiCircleSpinState extends State Widget build(BuildContext context) { return RotationTransition( turns: _animation, - child: const IndicatorShapeWidget(shape: Shape.circleSemi), + child: const IndicatorShapeWidget(shape: SemiCircle()), ); } } diff --git a/lib/src/indicators/square_spin.dart b/lib/src/indicators/square_spin.dart index ad9041c..e53862d 100644 --- a/lib/src/indicators/square_spin.dart +++ b/lib/src/indicators/square_spin.dart @@ -50,7 +50,7 @@ class _SquareSpinState extends State Widget build(BuildContext context) { return AnimatedBuilder( animation: _animationController, - child: const IndicatorShapeWidget(shape: Shape.rectangle), + child: const IndicatorShapeWidget(shape: Square()), builder: (_, child) { late double x, y; if (_animationController.value < 0.5) { diff --git a/lib/src/indicators/triangle_skew_spin.dart b/lib/src/indicators/triangle_skew_spin.dart index 73deb8e..a623702 100644 --- a/lib/src/indicators/triangle_skew_spin.dart +++ b/lib/src/indicators/triangle_skew_spin.dart @@ -49,7 +49,7 @@ class _TriangleSkewSpinState extends State Widget build(BuildContext context) { return AnimatedBuilder( animation: _animationController, - child: const IndicatorShapeWidget(shape: Shape.triangle), + child: const IndicatorShapeWidget(shape: Square()), builder: (_, child) { return Transform( alignment: Alignment.center, diff --git a/lib/src/shape/indicator_painter.dart b/lib/src/shape/indicator_painter.dart index 98513f4..0eb4ff1 100644 --- a/lib/src/shape/indicator_painter.dart +++ b/lib/src/shape/indicator_painter.dart @@ -5,17 +5,51 @@ import 'package:loading_indicator/src/decorate/decorate.dart'; const double _kMinIndicatorSize = 36.0; -/// Basic shape. -enum Shape { - circle, - ringThirdFour, - rectangle, - ringTwoHalfVertical, - ring, - line, - triangle, - arc, - circleSemi, +sealed class Shape {} + +class Circle implements Shape { + final double radius; + const Circle({this.radius = 0}); +} + +class RingThirdFour implements Shape { + final double radius; + const RingThirdFour({this.radius = 0}); +} + +class Square implements Shape { + final double size; + const Square({this.size = 0}); +} + +class RingTwoHalfVertical implements Shape { + final double radius; + const RingTwoHalfVertical({this.radius = 0}); +} + +class Ring implements Shape { + final double radius; + const Ring({this.radius = 0}); +} + +class Line implements Shape { + final double strokeWidth; + const Line({this.strokeWidth = 0}); +} + +class Triangle implements Shape { + final double strokeWidth; + const Triangle({this.strokeWidth = 0}); +} + +class Arc implements Shape { + final double radius; + const Arc({this.radius = 0}); +} + +class SemiCircle implements Shape { + final double radius; + const SemiCircle({this.radius = 0}); } /// Wrapper class for basic shape. @@ -76,7 +110,7 @@ class _ShapePainter extends CustomPainter { @override void paint(Canvas canvas, Size size) { switch (shape) { - case Shape.circle: + case Circle _: _paint ..color = color ..style = PaintingStyle.fill; @@ -86,7 +120,7 @@ class _ShapePainter extends CustomPainter { _paint, ); break; - case Shape.ringThirdFour: + case RingThirdFour _: if (pathColor != null) { _paint ..color = pathColor! @@ -113,13 +147,13 @@ class _ShapePainter extends CustomPainter { _paint, ); break; - case Shape.rectangle: + case Square _: _paint ..color = color ..style = PaintingStyle.fill; canvas.drawRect(Offset.zero & size, _paint); break; - case Shape.ringTwoHalfVertical: + case RingTwoHalfVertical _: _paint ..color = color ..strokeWidth = strokeWidth @@ -129,7 +163,7 @@ class _ShapePainter extends CustomPainter { canvas.drawArc(rect, -3 * pi / 4, pi / 2, false, _paint); canvas.drawArc(rect, 3 * pi / 4, -pi / 2, false, _paint); break; - case Shape.ring: + case Ring _: _paint ..color = color ..strokeWidth = strokeWidth @@ -137,17 +171,29 @@ class _ShapePainter extends CustomPainter { canvas.drawCircle(Offset(size.width / 2, size.height / 2), size.shortestSide / 2, _paint); break; - case Shape.line: + case Line line: _paint ..color = color ..style = PaintingStyle.fill; - canvas.drawRRect( - RRect.fromRectAndRadius( - Rect.fromLTWH(0, 0, size.width, size.height), - Radius.circular(size.shortestSide / 2)), - _paint); + if (line.strokeWidth >= size.shortestSide || line.strokeWidth <= 0) { + canvas.drawRRect( + RRect.fromRectAndRadius( + Rect.fromLTWH(0, 0, size.width, size.height), + Radius.circular(size.shortestSide / 2)), + _paint); + } else { + canvas.drawRRect( + RRect.fromRectAndRadius( + Rect.fromCenter( + center: size.center(Offset.zero), + width: line.strokeWidth, + height: size.height), + Radius.circular( + min(line.strokeWidth, size.shortestSide) / 2)), + _paint); + } break; - case Shape.triangle: + case Triangle _: final offsetY = size.height / 4; _paint ..color = color @@ -159,7 +205,7 @@ class _ShapePainter extends CustomPainter { ..close(); canvas.drawPath(path, _paint); break; - case Shape.arc: + case Arc _: assert(data != null); _paint ..color = color @@ -167,7 +213,7 @@ class _ShapePainter extends CustomPainter { canvas.drawArc( Offset.zero & size, data!, pi * 2 - 2 * data!, true, _paint); break; - case Shape.circleSemi: + case SemiCircle _: _paint ..color = color ..style = PaintingStyle.fill; diff --git a/pubspec.yaml b/pubspec.yaml index 6f85e07..0b92c91 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -4,7 +4,7 @@ version: 3.1.0 homepage: https://github.com/TinoGuo/loading_indicator environment: - sdk: ">=2.12.0 <3.0.0" + sdk: ">=3.0.0 <4.0.0" flutter: ">=2.0.0" dependencies: