Skip to content

Commit ffc0aa7

Browse files
authored
#14 Multiple Colors support (#17)
1 parent 809fd0d commit ffc0aa7

33 files changed

+240
-91
lines changed

README.md

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# LoadingIndicator
22
![](https://github.com/TinoGuo/loading_indicator/workflows/Flutter%20Build%20Test%20CI/badge.svg?branch=master)
33
[![pub package](https://img.shields.io/pub/v/loading_indicator.svg)](https://pub.dev/packages/loading_indicator)
4-
[中文版](README_CN.md)
54

65
A collection of out of the box loading animations written in pure dart, no extra dependency, inspired by [loaders.css](https://github.com/ConnorAtherton/loaders.css) and [NVActivityIndicatorView](https://github.com/ninjaprox/NVActivityIndicatorView).
76

@@ -10,7 +9,7 @@ A collection of out of the box loading animations written in pure dart, no extra
109

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

13-
![](gif/demo_2019_05_24.gif)
12+
![](gif/demo_2021_07_18.gif)
1413

1514
## Animation types
1615

@@ -29,9 +28,18 @@ Now, you can click [this site](https://tinoguo.github.io/loading_indicator/) to
2928
Install the latest version from [pub](https://pub.dev/packages/loading_indicator)
3029

3130
## Usage
32-
very simple to use
31+
Simple but powerful parameters
32+
33+
```
34+
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
39+
)
40+
```
3341

34-
`LoadingIndicator(indicatorType: Indicator.ballPulse, color: Colors.white, backgroundColor: Colors.black)`
42+
[中文版](README_CN.md)
3543

3644
## License
3745
[Apache 2.0](LICENSE)

README_CN.md

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
![](https://github.com/TinoGuo/loading_indicator/workflows/Flutter%20Build%20Test%20CI/badge.svg?branch=master)
33
[![pub package](https://img.shields.io/pub/v/loading_indicator.svg)](https://pub.dev/packages/loading_indicator)
44

5-
一个开箱即用的loading加载库,包含32个不同类型动画,灵感来源于[loaders.css](https://github.com/ConnorAtherton/loaders.css)[NVActivityIndicatorView](https://github.com/ninjaprox/NVActivityIndicatorView)
5+
一个开箱即用的loading加载库,包含34个不同类型动画,灵感来源于[loaders.css](https://github.com/ConnorAtherton/loaders.css)[NVActivityIndicatorView](https://github.com/ninjaprox/NVActivityIndicatorView)
66

77

88
## Demo
99

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

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

1414
## 动画类型
1515

@@ -30,7 +30,14 @@
3030
## 使用
3131
使用很简单。
3232

33-
`LoadingIndicator(indicatorType: Indicator.ballPulse, color: Colors.white,)`
33+
```
34+
LoadingIndicator(
35+
colors: const [Colors.white], /// 颜色集合
36+
indicatorType: Indicator.ballPulse, /// loading的类型
37+
strokeWidth: 2, /// 线条宽度,只对含有线条的组件有效
38+
backgroundColor: Colors.black, /// 组件背景色
39+
)
40+
```
3441

3542
## 开源协议
3643
[Apache 2.0](LICENSE)

example/lib/main.dart

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,16 @@ import 'package:flutter/cupertino.dart';
99
import 'package:flutter/material.dart';
1010
import 'package:loading_indicator/loading_indicator.dart';
1111

12+
const List<Color> _kDefaultRainbowColors = const [
13+
Colors.red,
14+
Colors.orange,
15+
Colors.yellow,
16+
Colors.green,
17+
Colors.blue,
18+
Colors.indigo,
19+
Colors.purple,
20+
];
21+
1222
void main() => runApp(MyApp());
1323

1424
class MyApp extends StatelessWidget {
@@ -37,15 +47,14 @@ class MainWidget extends StatelessWidget {
3747
return Scaffold(
3848
appBar: AppBar(
3949
title: Text(indicator.toString().split('.').last),
40-
backgroundColor: Colors.pink,
4150
),
42-
backgroundColor: Colors.teal,
4351
body: Padding(
4452
padding: const EdgeInsets.all(64),
45-
child: LoadingIndicator(
46-
indicatorType: indicator,
47-
colors: const [Colors.white],
48-
backgroundColor: Colors.black38,
53+
child: Center(
54+
child: LoadingIndicator(
55+
indicatorType: indicator,
56+
colors: _kDefaultRainbowColors,
57+
),
4958
),
5059
),
5160
);
@@ -58,7 +67,6 @@ class MainWidget extends StatelessWidget {
5867
Widget build(BuildContext context) => Scaffold(
5968
appBar: AppBar(
6069
title: Text('Demo'),
61-
backgroundColor: Colors.pink,
6270
),
6371
floatingActionButton: FloatingActionButton(
6472
child: Icon(Icons.grid_on),
@@ -94,7 +102,6 @@ class MainWidget extends StatelessWidget {
94102
class GridWidget extends StatelessWidget {
95103
Widget build(BuildContext context) {
96104
return Scaffold(
97-
backgroundColor: Colors.pink,
98105
body: CustomScrollView(
99106
slivers: [
100107
SliverAppBar(
@@ -103,7 +110,7 @@ class GridWidget extends StatelessWidget {
103110
),
104111
SliverGrid(
105112
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
106-
crossAxisCount: 4,
113+
crossAxisCount: 6,
107114
childAspectRatio: 1,
108115
),
109116
delegate: SliverChildBuilderDelegate(
@@ -114,8 +121,9 @@ class GridWidget extends StatelessWidget {
114121
Padding(
115122
padding: const EdgeInsets.all(16),
116123
child: LoadingIndicator(
117-
colors: const [Colors.white],
124+
colors: _kDefaultRainbowColors,
118125
indicatorType: Indicator.values[index],
126+
strokeWidth: 3,
119127
),
120128
),
121129
Align(

gif/demo_2019_05_24.gif

-2.36 MB
Binary file not shown.

gif/demo_2021_07_18.gif

17 MB
Loading

lib/src/decorate/decorate.dart

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,25 @@
11
import 'package:flutter/material.dart';
22
import 'package:loading_indicator/loading_indicator.dart';
33

4+
const double _kDefaultStrokeWidth = 2;
5+
46
/// Information about a piece of animation (e.g., color).
57
@immutable
68
class DecorateData {
79
final Color? backgroundColor;
810
final Indicator indicator;
911
final List<Color> colors;
12+
final double? _strokeWidth;
1013

1114
const DecorateData({
1215
required this.indicator,
13-
this.backgroundColor,
1416
required this.colors,
15-
});
17+
this.backgroundColor,
18+
double? strokeWidth,
19+
}) : _strokeWidth = strokeWidth;
20+
21+
double get strokeWidth =>
22+
_strokeWidth == null ? _kDefaultStrokeWidth : _strokeWidth!;
1623

1724
@override
1825
bool operator ==(Object other) =>
@@ -21,15 +28,19 @@ class DecorateData {
2128
runtimeType == other.runtimeType &&
2229
backgroundColor == other.backgroundColor &&
2330
indicator == other.indicator &&
24-
colors == other.colors;
31+
colors == other.colors &&
32+
strokeWidth == other.strokeWidth;
2533

2634
@override
2735
int get hashCode =>
28-
backgroundColor.hashCode ^ indicator.hashCode ^ colors.hashCode;
36+
backgroundColor.hashCode ^
37+
indicator.hashCode ^
38+
colors.hashCode ^
39+
strokeWidth.hashCode;
2940

3041
@override
3142
String toString() {
32-
return 'DecorateData{backgroundColor: $backgroundColor, indicator: $indicator, colors: $colors}';
43+
return 'DecorateData{backgroundColor: $backgroundColor, indicator: $indicator, colors: $colors, strokeWidth: $strokeWidth}';
3344
}
3445
}
3546

lib/src/indicators/audio_equalizer.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,10 @@ class _AudioEqualizerState extends State<AudioEqualizer>
7272
alignment: Alignment.bottomCenter,
7373
);
7474
},
75-
child: IndicatorShapeWidget(shape: Shape.rectangle),
75+
child: IndicatorShapeWidget(
76+
shape: Shape.rectangle,
77+
index: i ~/ 2,
78+
),
7679
),
7780
);
7881
} else {

lib/src/indicators/ball_beat.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ class _BallBeatState extends State<BallBeat> with TickerProviderStateMixin {
6161
scale: _scaleAnimations[i ~/ 2],
6262
child: IndicatorShapeWidget(
6363
shape: Shape.circle,
64+
index: i ~/ 2,
6465
),
6566
),
6667
),

lib/src/indicators/ball_clip_rotate_pulse.dart

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,17 @@ class _BallClipRotatePulseState extends State<BallClipRotatePulse>
5757
transform: Matrix4.identity()
5858
..scale(_outCircleScale.value)
5959
..rotateZ(_outCircleRotate.value),
60-
child: IndicatorShapeWidget(shape: Shape.ringTwoHalfVertical),
60+
child: IndicatorShapeWidget(
61+
shape: Shape.ringTwoHalfVertical,
62+
index: 0,
63+
),
6164
),
6265
Transform.scale(
6366
scale: _innerCircle.value * 0.3,
64-
child: IndicatorShapeWidget(shape: Shape.circle),
67+
child: IndicatorShapeWidget(
68+
shape: Shape.circle,
69+
index: 1,
70+
),
6571
),
6672
],
6773
),

lib/src/indicators/ball_grid_beat.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,10 @@ class _BallGridBeatState extends State<BallGridBeat>
6767
scale: _animations[i],
6868
child: FadeTransition(
6969
opacity: _animations[i],
70-
child: IndicatorShapeWidget(shape: Shape.circle),
70+
child: IndicatorShapeWidget(
71+
shape: Shape.circle,
72+
index: i,
73+
),
7174
),
7275
);
7376
}

0 commit comments

Comments
 (0)