Skip to content

Commit 9bc927c

Browse files
committed
comments added to gf-loader
1 parent 99113ba commit 9bc927c

File tree

1 file changed

+136
-111
lines changed

1 file changed

+136
-111
lines changed

lib/components/loader/gf_loader.dart

Lines changed: 136 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import 'package:flutter/material.dart';
33
import 'package:getflutter/types/gf_loader_type.dart';
44
import 'package:getflutter/size/gf_size.dart';
55

6-
76
class GFLoader extends StatefulWidget {
87
const GFLoader(
98
{Key key,
@@ -12,39 +11,59 @@ class GFLoader extends StatefulWidget {
1211
this.loaderColorThree = Colors.blueAccent,
1312
this.duration = const Duration(milliseconds: 1000),
1413
this.type = GFLoaderType.android,
15-
this.loaderIconOne ,
16-
this.loaderIconTwo ,
17-
this.loaderIconThree ,
18-
this.androidLoaderColor,
19-
this.loaderstrokeWidth= 4.0,
20-
this.size = GFSize.medium,
21-
this.child
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})
21+
: super(key: key);
22+
23+
/// Type of [Widget] used only in custom type and it is prominent over the icon in custom type
24+
final Widget child;
2225

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;
2328

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;
2431

25-
})
26-
: super(key: key);
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;
2734

28-
final Color loaderColorOne;
29-
final Color loaderColorTwo;
30-
final Color loaderColorThree;
35+
/// Type of duration which defines the animation duration of the loader only in circle and square type
3136
final Duration duration;
37+
38+
/// Type of [GFLoaderType] ie, android, ios, circle , square and custom
3239
final GFLoaderType type;
33-
final Widget loaderIconOne ;
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
3445
final Widget loaderIconTwo;
46+
47+
/// Type of [Widget] which takes text, icons or images for third dot only in custom type of loader
3548
final Widget loaderIconThree;
49+
50+
/// type of Animation<Color> used to change the color of the android loader only
3651
final Animation<Color> androidLoaderColor;
52+
53+
/// type of [double] used to change the stroke width of the android loader only
3754
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
3858
final dynamic size;
39-
final Widget child;
4059

4160
@override
4261
_GFLoaderState createState() => _GFLoaderState();
4362
}
4463

4564
class _GFLoaderState extends State<GFLoader>
4665
with SingleTickerProviderStateMixin {
47-
Animation<double> loaderanimation1;
66+
Animation<double> loaderanimation1;
4867
Animation<double> loaderanimation2;
4968
Animation<double> loaderanimation3;
5069
AnimationController controller;
@@ -66,7 +85,6 @@ class _GFLoaderState extends State<GFLoader>
6685
),
6786
);
6887

69-
7088
loaderanimation2 = Tween<double>(begin: 0, end: 1).animate(
7189
CurvedAnimation(
7290
parent: controller,
@@ -90,94 +108,98 @@ class _GFLoaderState extends State<GFLoader>
90108
);
91109

92110
controller.addListener(() {
93-
setState(() {
94-
//print(loaderanimation1.value);
95-
});
111+
setState(() {});
96112
});
97113

98114
controller.repeat();
99115
}
100116

101117
@override
102118
Widget build(BuildContext context) => Container(
103-
child: widget.child !=null? Loader(
104-
radius:GFSizesClass.getGFSize(widget.size)*0.3,
105-
type: widget.type,
106-
child: widget.child,
107-
108-
):widget.type==GFLoaderType.android? Center(
109-
child:Container(
110-
height: GFSizesClass.getGFSize(widget.size)* 0.7,
111-
width: GFSizesClass.getGFSize(widget.size)* 0.7,
112-
child: CircularProgressIndicator(
113-
valueColor: widget.androidLoaderColor,
114-
strokeWidth: widget.loaderstrokeWidth,
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,
115133
// value: 20,
116-
),
117-
)
118-
):widget.type==GFLoaderType.ios?Center(
119-
child: CupertinoActivityIndicator(
120-
radius: GFSizesClass.getGFSize(widget.size)* 0.4
121-
122-
),
123-
):Row(
124-
mainAxisAlignment: MainAxisAlignment.center,
125-
children: <Widget>[
126-
Opacity(
127-
opacity: loaderanimation1.value <= 0.3
128-
? 2.5 * loaderanimation1.value
129-
: (loaderanimation1.value > 0.30 && loaderanimation1.value <= 0.70)
130-
? 1.0
131-
: 2.5 - (2.5 * loaderanimation1.value),
132-
// opacity: (loaderanimation1.value <= 0.4 ? 2.5 * loaderanimation1.value : (loaderanimation1.value > 0.40 && loaderanimation1.value <= 0.60) ? 1.0 : 2.5 - (2.5 * loaderanimation1.value)),
133-
child: Padding(
134-
padding: const EdgeInsets.only(right: 8),
135-
child: Loader(
136-
radius:GFSizesClass.getGFSize(widget.size)*0.3,
137-
color: widget.loaderColorOne,
138-
type: widget.type,
139-
icon: widget.loaderIconOne,
140-
child: widget.child,
141-
),
142-
),
143-
),
144-
Opacity(
145-
opacity: loaderanimation2.value <= 0.3
146-
? 2.5 * loaderanimation2.value
147-
: (loaderanimation2.value > 0.30 && loaderanimation2.value <= 0.70)
148-
? 1.0
149-
: 2.5 - (2.5 * loaderanimation2.value),
150-
child: Padding(
151-
padding: const EdgeInsets.only(right: 8),
152-
child: Loader(
153-
radius: GFSizesClass.getGFSize(widget.size)*0.44,
154-
color: widget.loaderColorTwo,
155-
type: widget.type,
156-
icon: widget.loaderIconTwo,
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,
157178
//
158-
),
159-
),
160-
),
161-
Opacity(
162-
opacity: loaderanimation3.value <= 0.3
163-
? 2.5 * loaderanimation3.value
164-
: (loaderanimation3.value > 0.30 && loaderanimation3.value <= 0.70)
165-
? 1.0
166-
: 2.5 - (2.5 * loaderanimation3.value),
167-
child: Padding(
168-
padding: const EdgeInsets.only(right: 8),
169-
child: Loader(
170-
radius: GFSizesClass.getGFSize(widget.size)*0.3,
171-
color: widget.loaderColorThree,
172-
type: widget.type,
173-
icon: widget.loaderIconThree,
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,
174197
//
175-
176-
),
177-
),
178-
),
179-
],
180-
),
198+
),
199+
),
200+
),
201+
],
202+
),
181203
);
182204

183205
@override
@@ -188,7 +210,14 @@ class _GFLoaderState extends State<GFLoader>
188210
}
189211

190212
class Loader extends StatelessWidget {
191-
const Loader({Key key, this.radius, this.color, this.type, this.icon, this.size, this.child})
213+
const Loader(
214+
{Key key,
215+
this.radius,
216+
this.color,
217+
this.type,
218+
this.icon,
219+
this.size,
220+
this.child})
192221
: super(key: key);
193222

194223
final double radius;
@@ -198,21 +227,17 @@ class Loader extends StatelessWidget {
198227
final dynamic size;
199228
final Widget child;
200229

201-
202230
@override
203231
Widget build(BuildContext context) => Center(
204-
child:type== GFLoaderType.custom? Container(
205-
child: child!=null ?child:icon??Container())
206-
:Container(
207-
width: radius,
208-
height: radius,
209-
decoration: BoxDecoration(
210-
color: color,
211-
shape: type == GFLoaderType.circle
212-
? BoxShape.circle
213-
: BoxShape.rectangle),
214-
)
215-
216-
);
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+
));
217243
}
218-

0 commit comments

Comments
 (0)