Skip to content

Commit c4f8cb5

Browse files
authored
#14 Multiple Colors support Part3 (#18)
1 parent ffc0aa7 commit c4f8cb5

File tree

10 files changed

+93
-44
lines changed

10 files changed

+93
-44
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## [3.0.0] 2021/07/18
2+
* Support color collection #15
3+
* Support customize stroke width #15
4+
* Support customize stroke background #18
5+
16
## [2.1.1] 2021/05/22
27
* Bump Dart to 2.13
38

README.md

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ A collection of out of the box loading animations written in pure dart, no extra
99

1010
Now, you can click [this site](https://tinoguo.github.io/loading_indicator/) to preview.**3D effect will be invalid in web.**
1111

12-
![](gif/demo_2021_07_18.gif)
12+
![](gif/demo_2021_07_18_02.gif)
1313

1414
## Animation types
1515

@@ -18,11 +18,12 @@ Now, you can click [this site](https://tinoguo.github.io/loading_indicator/) to
1818
|1. ballPulse | 2. ballGridPulse | 3. ballClipRotate | 4. squareSpin|
1919
|5. ballClipRotatePulse | 6. ballClipRotateMultiple | 7. ballPulseRise | 8. ballRotate|
2020
|9. cubeTransition | 10. ballZigZag | 11. ballZigZagDeflect | 12. ballTrianglePath|
21-
|13. ballScale | 14. lineScale | 15. lineScaleParty | 16. ballScaleMultiple|
22-
|17. ballPulseSync | 18. ballBeat | 19. lineScalePulseOut | 20. lineScalePulseOutRapid|
23-
|21. ballScaleRipple | 22. ballScaleRippleMultiple | 23. ballSpinFadeLoader | 24. lineSpinFadeLoader|
24-
|25. triangleSkewSpin | 26. pacman | 27. ballGridBeat | 28. semiCircleSpin|
25-
|29. ballRotateChase | 30. orbit | 31. audioEqualizer | 32. circleStrokeSpin|
21+
|13. ballTrianglePathColored | 14.ballTrianglePathColoredFilled | 15. ballScale | 16. lineScale|
22+
|17. lineScaleParty | 18. ballScaleMultiple | 19. ballPulseSync | 20. ballBeat|
23+
|21. lineScalePulseOut | 22. lineScalePulseOutRapid |23. ballScaleRipple | 24. ballScaleRippleMultiple|
24+
|25. ballSpinFadeLoader | 26. lineSpinFadeLoader | 27. triangleSkewSpin | 28. pacman|
25+
|29. ballGridBeat | 30. semiCircleSpin| 31. ballRotateChase | 32. orbit|
26+
|33. audioEqualizer | 34. circleStrokeSpin|
2627

2728
## Installing
2829
Install the latest version from [pub](https://pub.dev/packages/loading_indicator)
@@ -32,10 +33,11 @@ Simple but powerful parameters
3233

3334
```
3435
LoadingIndicator(
35-
colors: const [Colors.white], /// The color collections
36-
indicatorType: Indicator.ballPulse, /// The loading type of the widget
37-
strokeWidth: 2, /// The stroke of the line, only applicable to widget which contains line
38-
backgroundColor: Colors.black, /// Background of the widget
36+
indicatorType: Indicator.ballPulse, /// Required, The loading type of the widget
37+
colors: const [Colors.white], /// Optional, The color collections
38+
strokeWidth: 2, /// Optional, The stroke of the line, only applicable to widget which contains line
39+
backgroundColor: Colors.black, /// Optional, Background of the widget
40+
pathBackgroundColor: Colors.black /// Optional, the stroke backgroundColor
3941
)
4042
```
4143

README_CN.md

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
现在你可以点击这个[地址](https://tinoguo.github.io/loading_indicator/)来进行预览.**3D效果在web上会失效.**
1111

12-
![](gif/demo_2021_07_18.gif)
12+
![](gif/demo_2021_07_18_02.gif)
1313

1414
## 动画类型
1515

@@ -18,24 +18,26 @@
1818
|1. ballPulse | 2. ballGridPulse | 3. ballClipRotate | 4. squareSpin|
1919
|5. ballClipRotatePulse | 6. ballClipRotateMultiple | 7. ballPulseRise | 8. ballRotate|
2020
|9. cubeTransition | 10. ballZigZag | 11. ballZigZagDeflect | 12. ballTrianglePath|
21-
|13. ballScale | 14. lineScale | 15. lineScaleParty | 16. ballScaleMultiple|
22-
|17. ballPulseSync | 18. ballBeat | 19. lineScalePulseOut | 20. lineScalePulseOutRapid|
23-
|21. ballScaleRipple | 22. ballScaleRippleMultiple | 23. ballSpinFadeLoader | 24. lineSpinFadeLoader|
24-
|25. triangleSkewSpin | 26. pacman | 27. ballGridBeat | 28. semiCircleSpin|
25-
|29. ballRotateChase | 30. orbit | 31. audioEqualizer | 32. circleStrokeSpin|
21+
|13. ballTrianglePathColored | 14.ballTrianglePathColoredFilled | 15. ballScale | 16. lineScale|
22+
|17. lineScaleParty | 18. ballScaleMultiple | 19. ballPulseSync | 20. ballBeat|
23+
|21. lineScalePulseOut | 22. lineScalePulseOutRapid |23. ballScaleRipple | 24. ballScaleRippleMultiple|
24+
|25. ballSpinFadeLoader | 26. lineSpinFadeLoader | 27. triangleSkewSpin | 28. pacman|
25+
|29. ballGridBeat | 30. semiCircleSpin| 31. ballRotateChase | 32. orbit|
26+
|33. audioEqualizer | 34. circleStrokeSpin|
2627

2728
## 安装
2829
[pub](https://pub.dev/packages/loading_indicator)安装最新版本。
2930

3031
## 使用
31-
使用很简单
32+
简单且强大的API
3233

3334
```
3435
LoadingIndicator(
35-
colors: const [Colors.white], /// 颜色集合
36-
indicatorType: Indicator.ballPulse, /// loading的类型
37-
strokeWidth: 2, /// 线条宽度,只对含有线条的组件有效
38-
backgroundColor: Colors.black, /// 组件背景色
36+
colors: const [Colors.white], /// 必须, 颜色集合
37+
indicatorType: Indicator.ballPulse, /// 可选, loading的类型
38+
strokeWidth: 2, /// 可选, 线条宽度,只对含有线条的组件有效
39+
backgroundColor: Colors.black, /// 可选, 组件背景色
40+
pathBackgroundColor: Colors.black /// 可选, 线条背景色
3941
)
4042
```
4143

example/lib/main.dart

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,14 @@ class MyApp extends StatelessWidget {
2828
return MaterialApp(
2929
title: 'LoadingIndicator example',
3030
debugShowCheckedModeBanner: false,
31-
theme: ThemeData(
32-
primarySwatch: Colors.pink,
33-
primaryColor: Colors.white,
34-
),
3531
home: MainWidget(),
3632
);
3733
}
3834
}
3935

4036
class MainWidget extends StatelessWidget {
41-
_showSingleAnimationDialog(BuildContext context, Indicator indicator) {
37+
_showSingleAnimationDialog(
38+
BuildContext context, Indicator indicator, bool showPathBackground) {
4239
Navigator.push(
4340
context,
4441
MaterialPageRoute(
@@ -54,6 +51,9 @@ class MainWidget extends StatelessWidget {
5451
child: LoadingIndicator(
5552
indicatorType: indicator,
5653
colors: _kDefaultRainbowColors,
54+
strokeWidth: 4.0,
55+
pathBackgroundColor:
56+
showPathBackground ? Colors.black45 : null,
5757
),
5858
),
5959
),
@@ -80,9 +80,16 @@ class MainWidget extends StatelessWidget {
8080
body: ListView.builder(
8181
itemBuilder: (ctx, index) {
8282
return InkWell(
83-
onTap: () {
84-
_showSingleAnimationDialog(ctx, Indicator.values[index]);
85-
},
83+
onTap: () => _showSingleAnimationDialog(
84+
ctx,
85+
Indicator.values[index],
86+
false,
87+
),
88+
onLongPress: () => _showSingleAnimationDialog(
89+
ctx,
90+
Indicator.values[index],
91+
true,
92+
),
8693
child: Padding(
8794
padding: const EdgeInsets.only(left: 16, top: 16, bottom: 16),
8895
child: Text(
@@ -124,14 +131,15 @@ class GridWidget extends StatelessWidget {
124131
colors: _kDefaultRainbowColors,
125132
indicatorType: Indicator.values[index],
126133
strokeWidth: 3,
134+
// pathBackgroundColor: Colors.black45,
127135
),
128136
),
129137
Align(
130138
alignment: Alignment.bottomLeft,
131139
child: Text(
132140
'${index + 1}',
133141
style: TextStyle(
134-
color: Colors.white,
142+
color: Colors.black,
135143
fontSize: 14,
136144
),
137145
),
17 MB
Loading

lib/src/decorate/decorate.dart

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,22 @@ const double _kDefaultStrokeWidth = 2;
88
class DecorateData {
99
final Color? backgroundColor;
1010
final Indicator indicator;
11+
12+
/// It will promise at least one value in the collection.
1113
final List<Color> colors;
1214
final double? _strokeWidth;
1315

16+
/// Applicable to which has cut edge of the shape
17+
final Color? pathBackgroundColor;
18+
1419
const DecorateData({
1520
required this.indicator,
1621
required this.colors,
1722
this.backgroundColor,
1823
double? strokeWidth,
19-
}) : _strokeWidth = strokeWidth;
24+
this.pathBackgroundColor,
25+
}) : _strokeWidth = strokeWidth,
26+
assert(colors.length > 0);
2027

2128
double get strokeWidth =>
2229
_strokeWidth == null ? _kDefaultStrokeWidth : _strokeWidth!;

lib/src/indicators/circle_stroke_spin.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ class CircleStrokeSpin extends StatelessWidget {
99
return CircularProgressIndicator(
1010
strokeWidth: 2,
1111
color: color,
12+
backgroundColor:
13+
DecorateContext.of(context)!.decorateData.pathBackgroundColor,
1214
);
1315
}
1416
}

lib/src/loading.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,16 @@ class LoadingIndicator extends StatelessWidget {
8787
/// The stroke width of line.
8888
final double? strokeWidth;
8989

90+
/// Applicable to which has cut edge of the shape
91+
final Color? pathBackgroundColor;
92+
9093
LoadingIndicator({
9194
Key? key,
9295
required this.indicatorType,
9396
this.colors,
9497
this.backgroundColor,
9598
this.strokeWidth,
99+
this.pathBackgroundColor,
96100
}) : super(key: key);
97101

98102
@override
@@ -105,6 +109,7 @@ class LoadingIndicator extends StatelessWidget {
105109
indicator: indicatorType,
106110
colors: safeColors,
107111
strokeWidth: strokeWidth,
112+
pathBackgroundColor: pathBackgroundColor,
108113
),
109114
child: AspectRatio(
110115
aspectRatio: 1,

lib/src/shape/indicator_painter.dart

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ class IndicatorShapeWidget extends StatelessWidget {
4949
shape,
5050
data,
5151
decorateData.strokeWidth,
52+
pathColor: decorateData.pathBackgroundColor,
5253
),
5354
),
5455
);
@@ -61,13 +62,15 @@ class _ShapePainter extends CustomPainter {
6162
final Paint _paint;
6263
final double? data;
6364
final double strokeWidth;
65+
final Color? pathColor;
6466

6567
_ShapePainter(
6668
this.color,
6769
this.shape,
6870
this.data,
69-
this.strokeWidth,
70-
) : _paint = Paint()..isAntiAlias = true,
71+
this.strokeWidth, {
72+
this.pathColor,
73+
}) : _paint = Paint()..isAntiAlias = true,
7174
super();
7275

7376
@override
@@ -84,18 +87,31 @@ class _ShapePainter extends CustomPainter {
8487
);
8588
break;
8689
case Shape.ringThirdFour:
90+
if (pathColor != null) {
91+
_paint
92+
..color = pathColor!
93+
..strokeWidth = strokeWidth
94+
..style = PaintingStyle.stroke;
95+
canvas.drawCircle(
96+
Offset(size.width / 2, size.height / 2),
97+
size.shortestSide / 2,
98+
_paint,
99+
);
100+
}
87101
_paint
88102
..color = color
89103
..style = PaintingStyle.stroke
90104
..strokeWidth = strokeWidth;
91105
canvas.drawArc(
92-
Rect.fromCircle(
93-
center: Offset(size.width / 2, size.height / 2),
94-
radius: size.shortestSide / 2),
95-
-3 * pi / 4,
96-
3 * pi / 2,
97-
false,
98-
_paint);
106+
Rect.fromCircle(
107+
center: Offset(size.width / 2, size.height / 2),
108+
radius: size.shortestSide / 2,
109+
),
110+
-3 * pi / 4,
111+
3 * pi / 2,
112+
false,
113+
_paint,
114+
);
99115
break;
100116
case Shape.rectangle:
101117
_paint
@@ -164,5 +180,7 @@ class _ShapePainter extends CustomPainter {
164180
bool shouldRepaint(_ShapePainter oldDelegate) =>
165181
this.shape != oldDelegate.shape ||
166182
this.color != oldDelegate.color ||
167-
this.data != oldDelegate.data;
183+
this.data != oldDelegate.data ||
184+
this.strokeWidth != oldDelegate.strokeWidth ||
185+
this.pathColor != oldDelegate.pathColor;
168186
}

pubspec.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
name: loading_indicator
22
description: A collection loading animations written in pure dart. Out of the box, no extra dependency.
3-
version: 2.1.1
3+
version: 3.0.0
44
homepage: https://github.com/TinoGuo/loading_indicator
55

66
environment:
7-
sdk: '>=2.13.0 <3.0.0'
7+
sdk: ">=2.12.0 <3.0.0"
8+
flutter: ">=2.0.0"
89

910
dependencies:
1011
flutter:
1112
sdk: flutter
1213
async: ^2.6.1
1314

14-
1515
dev_dependencies:
1616
flutter_test:
1717
sdk: flutter

0 commit comments

Comments
 (0)