Skip to content

Commit 809fd0d

Browse files
authored
#14 Part1 (#15)
1 parent 7126668 commit 809fd0d

File tree

6 files changed

+79
-86
lines changed

6 files changed

+79
-86
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Install the latest version from [pub](https://pub.dev/packages/loading_indicator
3131
## Usage
3232
very simple to use
3333

34-
`LoadingIndicator(indicatorType: Indicator.ballPulse, color: Colors.white,)`
34+
`LoadingIndicator(indicatorType: Indicator.ballPulse, color: Colors.white, backgroundColor: Colors.black)`
3535

3636
## License
3737
[Apache 2.0](LICENSE)

example/lib/main.dart

Lines changed: 40 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
// [FloatingActionButtonLocation.centerDocked]. The [FloatingActionButton] is
66
// connected to a callback that increments a counter.
77

8+
import 'package:flutter/cupertino.dart';
89
import 'package:flutter/material.dart';
910
import 'package:loading_indicator/loading_indicator.dart';
1011

@@ -43,7 +44,8 @@ class MainWidget extends StatelessWidget {
4344
padding: const EdgeInsets.all(64),
4445
child: LoadingIndicator(
4546
indicatorType: indicator,
46-
color: Colors.white,
47+
colors: const [Colors.white],
48+
backgroundColor: Colors.black38,
4749
),
4850
),
4951
);
@@ -93,35 +95,45 @@ class GridWidget extends StatelessWidget {
9395
Widget build(BuildContext context) {
9496
return Scaffold(
9597
backgroundColor: Colors.pink,
96-
body: GridView.builder(
97-
itemCount: Indicator.values.length,
98-
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
99-
crossAxisCount: 4,
100-
childAspectRatio: 1,
101-
),
102-
itemBuilder: (ctx, index) => Stack(
103-
fit: StackFit.expand,
104-
alignment: Alignment.center,
105-
children: <Widget>[
106-
Padding(
107-
padding: const EdgeInsets.all(16),
108-
child: LoadingIndicator(
109-
color: Colors.white,
110-
indicatorType: Indicator.values[index],
111-
),
98+
body: CustomScrollView(
99+
slivers: [
100+
SliverAppBar(
101+
title: Text('Grid Demo'),
102+
floating: true,
103+
),
104+
SliverGrid(
105+
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
106+
crossAxisCount: 4,
107+
childAspectRatio: 1,
112108
),
113-
Align(
114-
alignment: Alignment.bottomLeft,
115-
child: Text(
116-
'${index + 1}',
117-
style: TextStyle(
118-
color: Colors.white,
119-
fontSize: 14,
120-
),
109+
delegate: SliverChildBuilderDelegate(
110+
(ctx, index) => Stack(
111+
fit: StackFit.expand,
112+
alignment: Alignment.center,
113+
children: <Widget>[
114+
Padding(
115+
padding: const EdgeInsets.all(16),
116+
child: LoadingIndicator(
117+
colors: const [Colors.white],
118+
indicatorType: Indicator.values[index],
119+
),
120+
),
121+
Align(
122+
alignment: Alignment.bottomLeft,
123+
child: Text(
124+
'${index + 1}',
125+
style: TextStyle(
126+
color: Colors.white,
127+
fontSize: 14,
128+
),
129+
),
130+
)
131+
],
121132
),
122-
)
123-
],
124-
),
133+
childCount: Indicator.values.length,
134+
),
135+
),
136+
],
125137
),
126138
);
127139
}

lib/src/decorate/decorate.dart

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,32 @@ import 'package:loading_indicator/loading_indicator.dart';
44
/// Information about a piece of animation (e.g., color).
55
@immutable
66
class DecorateData {
7-
final Color color;
7+
final Color? backgroundColor;
88
final Indicator indicator;
9-
final List<Color>? colors;
9+
final List<Color> colors;
1010

11-
const DecorateData(
12-
{required this.indicator, this.color = Colors.white, this.colors});
11+
const DecorateData({
12+
required this.indicator,
13+
this.backgroundColor,
14+
required this.colors,
15+
});
1316

1417
@override
15-
bool operator ==(other) {
16-
if (other.runtimeType != this.runtimeType) return false;
17-
18-
return other is DecorateData &&
19-
this.color == other.color &&
20-
this.colors == other.colors &&
21-
this.indicator == other.indicator;
22-
}
18+
bool operator ==(Object other) =>
19+
identical(this, other) ||
20+
other is DecorateData &&
21+
runtimeType == other.runtimeType &&
22+
backgroundColor == other.backgroundColor &&
23+
indicator == other.indicator &&
24+
colors == other.colors;
2325

2426
@override
25-
int get hashCode => hashValues(color, indicator);
27+
int get hashCode =>
28+
backgroundColor.hashCode ^ indicator.hashCode ^ colors.hashCode;
2629

2730
@override
2831
String toString() {
29-
return 'DecorateData{color: $color, indicator: $indicator}';
32+
return 'DecorateData{backgroundColor: $backgroundColor, indicator: $indicator, colors: $colors}';
3033
}
3134
}
3235

lib/src/indicators/circle_stroke_spin.dart

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,10 @@ import 'package:loading_indicator/src/decorate/decorate.dart';
55
class CircleStrokeSpin extends StatelessWidget {
66
@override
77
Widget build(BuildContext context) {
8-
final color = DecorateContext.of(context)!.decorateData.color;
9-
return Theme(
10-
data: Theme.of(context).copyWith(accentColor: color),
11-
child: CircularProgressIndicator(
12-
strokeWidth: 2,
13-
),
8+
final color = DecorateContext.of(context)!.decorateData.colors.first;
9+
return CircularProgressIndicator(
10+
strokeWidth: 2,
11+
color: color,
1412
);
1513
}
1614
}

lib/src/loading.dart

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,24 +81,32 @@ class LoadingIndicator extends StatelessWidget {
8181
final Indicator indicatorType;
8282

8383
/// The color you draw on the shape.
84-
final Color? color;
8584
final List<Color>? colors;
85+
final Color? backgroundColor;
86+
8687
LoadingIndicator({
8788
Key? key,
8889
required this.indicatorType,
89-
this.color,
9090
this.colors,
91+
this.backgroundColor,
9192
}) : super(key: key);
9293

9394
@override
9495
Widget build(BuildContext context) {
95-
final actualColor = color ?? Theme.of(context).primaryColor;
96+
List<Color> safeColors = colors == null || colors!.isEmpty
97+
? [Theme.of(context).primaryColor]
98+
: colors!;
9699
return DecorateContext(
97100
decorateData: DecorateData(
98-
indicator: indicatorType, color: actualColor, colors: colors),
101+
indicator: indicatorType,
102+
colors: safeColors,
103+
),
99104
child: AspectRatio(
100105
aspectRatio: 1,
101-
child: _buildIndicator(),
106+
child: Container(
107+
color: backgroundColor,
108+
child: _buildIndicator(),
109+
),
102110
),
103111
);
104112
}

lib/src/shape/indicator_painter.dart

Lines changed: 4 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -34,39 +34,11 @@ class IndicatorShapeWidget extends StatelessWidget {
3434
@override
3535
Widget build(BuildContext context) {
3636
final DecorateData decorateData = DecorateContext.of(context)!.decorateData;
37-
final bool shouldUseColors = decorateData.colors != null &&
38-
colorIndex != null &&
39-
colorIndex! < decorateData.colors!.length;
37+
final bool shouldUseColors =
38+
colorIndex != null && colorIndex! < decorateData.colors.length;
4039
final color = shouldUseColors
41-
? decorateData.colors![colorIndex!]
42-
: DecorateContext.of(context)!.decorateData.color;
43-
44-
// if (shape == Shape.circle) {
45-
// return Container(
46-
// decoration: BoxDecoration(
47-
// color: color,
48-
// shape: BoxShape.circle,
49-
// ),
50-
// );
51-
// } else if (shape == Shape.line) {
52-
// return LayoutBuilder(
53-
// builder: (ctx, constraint) => Container(
54-
// decoration: ShapeDecoration(
55-
// color: color,
56-
// shape: RoundedRectangleBorder(
57-
// borderRadius: BorderRadius.circular(constraint.maxWidth / 2),
58-
// ),
59-
// ),
60-
// ),
61-
// );
62-
// } else if (shape == Shape.rectangle) {
63-
// return Container(
64-
// decoration: BoxDecoration(
65-
// color: color,
66-
// shape: BoxShape.rectangle,
67-
// ),
68-
// );
69-
// }
40+
? decorateData.colors[colorIndex!]
41+
: DecorateContext.of(context)!.decorateData.colors.first;
7042

7143
return Container(
7244
constraints: const BoxConstraints(

0 commit comments

Comments
 (0)