Skip to content

Commit 14dabe5

Browse files
Merge pull request #25 from ionicfirebaseapp/master
master pull
2 parents 7791523 + 661545a commit 14dabe5

File tree

3 files changed

+171
-98
lines changed

3 files changed

+171
-98
lines changed
Lines changed: 163 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import 'dart:math';
1+
import 'package:flutter/cupertino.dart';
22
import 'package:flutter/material.dart';
33
import 'package:getflutter/types/gf_loader_type.dart';
4+
import 'package:getflutter/size/gf_size.dart';
45

56
class GFLoader extends StatefulWidget {
67
const GFLoader(
@@ -9,26 +10,62 @@ class GFLoader extends StatefulWidget {
910
this.loaderColorTwo = Colors.green,
1011
this.loaderColorThree = Colors.blueAccent,
1112
this.duration = const Duration(milliseconds: 1000),
12-
this.loaderType = LoaderDotType.circle,
13-
this.loaderIcon = const Icon(Icons.blur_on)})
13+
this.type = GFLoaderType.android,
14+
this.loaderIconOne,
15+
this.loaderIconTwo,
16+
this.loaderIconThree,
17+
this.androidLoaderColor,
18+
this.loaderstrokeWidth = 4.0,
19+
this.size = GFSize.medium,
20+
this.child})
1421
: super(key: key);
1522

16-
final Color loaderColorOne;
17-
final Color loaderColorTwo;
18-
final Color loaderColorThree;
23+
/// Type of [Widget] used only in custom type and it is prominent over the loaderIconOne, loaderIconTwo, loaderIconThree in custom type
24+
final Widget child;
25+
26+
/// Type of GFColor or [Color] which defines the color of the first dot in only circle or square type of loader
27+
final dynamic loaderColorOne;
28+
29+
/// Type of GFColor or [Color] which defines the color of the second dot in only circle or square type of loader
30+
final dynamic loaderColorTwo;
31+
32+
/// Type of GFColor or [Color] which defines the color of the third dot in only circle or square type of loader
33+
final dynamic loaderColorThree;
34+
35+
/// Type of duration which defines the animation duration of the loader only in circle and square type of loader
1936
final Duration duration;
20-
final LoaderDotType loaderType;
21-
final Icon loaderIcon;
37+
38+
/// Type of [GFLoaderType] ie, android, ios, circle , square and custom
39+
final GFLoaderType type;
40+
41+
/// Type of [Widget] which takes text, icons or images for first dot only in custom type of loader
42+
final Widget loaderIconOne;
43+
44+
/// Type of [Widget] which takes text, icons or images for second dot only in custom type of loader
45+
final Widget loaderIconTwo;
46+
47+
/// Type of [Widget] which takes text, icons or images for third dot only in custom type of loader
48+
final Widget loaderIconThree;
49+
50+
/// type of Animation<Color> used to change the color of the android loader only
51+
final Animation<Color> androidLoaderColor;
52+
53+
/// type of [double] used to change the stroke width of the android loader only
54+
final double loaderstrokeWidth;
55+
56+
/// type of [double] or [GFSize] ie, small , medium or large which is used
57+
/// to change the size of android, ios, circle and square loaders only
58+
final dynamic size;
2259

2360
@override
2461
_GFLoaderState createState() => _GFLoaderState();
2562
}
2663

2764
class _GFLoaderState extends State<GFLoader>
2865
with SingleTickerProviderStateMixin {
29-
Animation<double> animation_1;
30-
Animation<double> animation_2;
31-
Animation<double> animation_3;
66+
Animation<double> loaderanimation1;
67+
Animation<double> loaderanimation2;
68+
Animation<double> loaderanimation3;
3269
AnimationController controller;
3370

3471
@override
@@ -37,104 +74,132 @@ class _GFLoaderState extends State<GFLoader>
3774

3875
controller = AnimationController(duration: widget.duration, vsync: this);
3976

40-
animation_1 = Tween(begin: 0, end: 1.0).animate(
77+
loaderanimation1 = Tween<double>(begin: 0, end: 1).animate(
4178
CurvedAnimation(
4279
parent: controller,
4380
curve: const Interval(
4481
0,
45-
0.70,
82+
0.71,
4683
curve: Curves.linear,
4784
),
4885
),
4986
);
5087

51-
animation_2 = Tween(begin: 0, end: 1.0).animate(
88+
loaderanimation2 = Tween<double>(begin: 0, end: 1).animate(
5289
CurvedAnimation(
5390
parent: controller,
5491
curve: const Interval(
5592
0.1,
56-
0.80,
93+
0.81,
5794
curve: Curves.linear,
5895
),
5996
),
6097
);
6198

62-
animation_3 = Tween(begin: 0, end: 1.0).animate(
99+
loaderanimation3 = Tween<double>(begin: 0, end: 1).animate(
63100
CurvedAnimation(
64101
parent: controller,
65102
curve: const Interval(
66103
0.2,
67-
0.90,
104+
0.91,
68105
curve: Curves.linear,
69106
),
70107
),
71108
);
72109

73110
controller.addListener(() {
74-
setState(() {
75-
//print(animation_1.value);
76-
});
111+
setState(() {});
77112
});
78113

79114
controller.repeat();
80115
}
81116

82117
@override
83118
Widget build(BuildContext context) => Container(
84-
child: Row(
85-
mainAxisAlignment: MainAxisAlignment.center,
86-
children: <Widget>[
87-
Opacity(
88-
opacity: animation_1.value <= 0.4
89-
? 2.5 * animation_1.value
90-
: (animation_1.value > 0.40 && animation_1.value <= 0.60)
91-
? 1.0
92-
: 2.5 - (2.5 * animation_1.value),
93-
// opacity: (animation_1.value <= 0.4 ? 2.5 * animation_1.value : (animation_1.value > 0.40 && animation_1.value <= 0.60) ? 1.0 : 2.5 - (2.5 * animation_1.value)),
94-
child: Padding(
95-
padding: const EdgeInsets.only(right: 8),
96-
child: Dot(
97-
radius: 10,
98-
color: widget.loaderColorOne,
99-
type: widget.loaderType,
100-
icon: widget.loaderIcon,
101-
),
102-
),
103-
),
104-
Opacity(
105-
opacity: animation_2.value <= 0.4
106-
? 2.5 * animation_2.value
107-
: (animation_2.value > 0.40 && animation_2.value <= 0.60)
108-
? 1.0
109-
: 2.5 - (2.5 * animation_2.value),
110-
child: Padding(
111-
padding: const EdgeInsets.only(right: 8),
112-
child: Dot(
113-
radius: 10,
114-
color: widget.loaderColorTwo,
115-
type: widget.loaderType,
116-
icon: widget.loaderIcon,
117-
),
118-
),
119-
),
120-
Opacity(
121-
opacity: animation_3.value <= 0.4
122-
? 2.5 * animation_3.value
123-
: (animation_3.value > 0.40 && animation_3.value <= 0.60)
124-
? 1.0
125-
: 2.5 - (2.5 * animation_3.value),
126-
child: Padding(
127-
padding: const EdgeInsets.only(right: 8),
128-
child: Dot(
129-
radius: 10,
130-
color: widget.loaderColorThree,
131-
type: widget.loaderType,
132-
icon: widget.loaderIcon,
133-
),
134-
),
135-
),
136-
],
137-
),
119+
child: widget.child != null
120+
? Loader(
121+
radius: GFSizesClass.getGFSize(widget.size) * 0.3,
122+
type: widget.type,
123+
child: widget.child,
124+
)
125+
: widget.type == GFLoaderType.android
126+
? Center(
127+
child: Container(
128+
height: GFSizesClass.getGFSize(widget.size) * 0.7,
129+
width: GFSizesClass.getGFSize(widget.size) * 0.7,
130+
child: CircularProgressIndicator(
131+
valueColor: widget.androidLoaderColor,
132+
strokeWidth: widget.loaderstrokeWidth,
133+
// value: 20,
134+
),
135+
))
136+
: widget.type == GFLoaderType.ios
137+
? Center(
138+
child: CupertinoActivityIndicator(
139+
radius: GFSizesClass.getGFSize(widget.size) * 0.4),
140+
)
141+
: Row(
142+
mainAxisAlignment: MainAxisAlignment.center,
143+
children: <Widget>[
144+
Opacity(
145+
opacity: loaderanimation1.value <= 0.3
146+
? 2.5 * loaderanimation1.value
147+
: (loaderanimation1.value > 0.30 &&
148+
loaderanimation1.value <= 0.70)
149+
? 1.0
150+
: 2.5 - (2.5 * loaderanimation1.value),
151+
child: Padding(
152+
padding: const EdgeInsets.only(right: 8),
153+
child: Loader(
154+
radius:
155+
GFSizesClass.getGFSize(widget.size) * 0.3,
156+
color: widget.loaderColorOne,
157+
type: widget.type,
158+
icon: widget.loaderIconOne,
159+
child: widget.child,
160+
),
161+
),
162+
),
163+
Opacity(
164+
opacity: loaderanimation2.value <= 0.3
165+
? 2.5 * loaderanimation2.value
166+
: (loaderanimation2.value > 0.30 &&
167+
loaderanimation2.value <= 0.70)
168+
? 1.0
169+
: 2.5 - (2.5 * loaderanimation2.value),
170+
child: Padding(
171+
padding: const EdgeInsets.only(right: 8),
172+
child: Loader(
173+
radius:
174+
GFSizesClass.getGFSize(widget.size) * 0.44,
175+
color: widget.loaderColorTwo,
176+
type: widget.type,
177+
icon: widget.loaderIconTwo,
178+
//
179+
),
180+
),
181+
),
182+
Opacity(
183+
opacity: loaderanimation3.value <= 0.3
184+
? 2.5 * loaderanimation3.value
185+
: (loaderanimation3.value > 0.30 &&
186+
loaderanimation3.value <= 0.70)
187+
? 1.0
188+
: 2.5 - (2.5 * loaderanimation3.value),
189+
child: Padding(
190+
padding: const EdgeInsets.only(right: 8),
191+
child: Loader(
192+
radius:
193+
GFSizesClass.getGFSize(widget.size) * 0.3,
194+
color: widget.loaderColorThree,
195+
type: widget.type,
196+
icon: widget.loaderIconThree,
197+
//
198+
),
199+
),
200+
),
201+
],
202+
),
138203
);
139204

140205
@override
@@ -144,34 +209,35 @@ class _GFLoaderState extends State<GFLoader>
144209
}
145210
}
146211

147-
class Dot extends StatelessWidget {
148-
const Dot({Key key, this.radius, this.color, this.type, this.icon})
212+
class Loader extends StatelessWidget {
213+
const Loader(
214+
{Key key,
215+
this.radius,
216+
this.color,
217+
this.type,
218+
this.icon,
219+
this.size,
220+
this.child})
149221
: super(key: key);
150222

151223
final double radius;
152224
final Color color;
153-
final LoaderDotType type;
154-
final Icon icon;
225+
final GFLoaderType type;
226+
final Widget icon;
227+
final dynamic size;
228+
final Widget child;
155229

156230
@override
157231
Widget build(BuildContext context) => Center(
158-
child: type == LoaderDotType.icon
159-
? Icon(
160-
icon.icon,
161-
color: color,
162-
size: 1.3 * radius,
163-
)
164-
: Transform.rotate(
165-
angle: type == LoaderDotType.diamond ? pi / 4 : 0.0,
166-
child: Container(
167-
width: radius,
168-
height: radius,
169-
decoration: BoxDecoration(
170-
color: color,
171-
shape: type == LoaderDotType.circle
172-
? BoxShape.circle
173-
: BoxShape.rectangle),
174-
),
175-
),
176-
);
232+
child: type == GFLoaderType.custom
233+
? Container(child: child != null ? child : icon ?? Container())
234+
: Container(
235+
width: radius,
236+
height: radius,
237+
decoration: BoxDecoration(
238+
color: color,
239+
shape: type == GFLoaderType.circle
240+
? BoxShape.circle
241+
: BoxShape.rectangle),
242+
));
177243
}

lib/components/toast/gf_toast.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ class _GFToastState extends State<GFToast> with TickerProviderStateMixin {
7373
parent: animationController,
7474
curve: Curves.easeIn,
7575
);
76+
7677
animationController.forward();
7778
fadeanimationController = AnimationController(
7879
vsync: this,

lib/types/gf_loader_type.dart

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,7 @@
1-
enum LoaderDotType { square, circle, diamond, icon }
1+
enum GFLoaderType {
2+
android,
3+
ios,
4+
square,
5+
circle,
6+
custom,
7+
}

0 commit comments

Comments
 (0)