1+ import 'package:flutter/material.dart' ;
2+ import 'dart:math' ;
3+ import 'package:getflutter/types/gf_loader_type.dart' ;
4+
5+
6+ class GFLoader extends StatefulWidget {
7+
8+ final Color dotOneColor;
9+ final Color dotTwoColor;
10+ final Color dotThreeColor;
11+ final Duration duration;
12+ final LoaderDotType dotType;
13+ final Icon dotIcon;
14+
15+ GFLoader ({
16+ this .dotOneColor = Colors .redAccent,
17+ this .dotTwoColor = Colors .green,
18+ this .dotThreeColor = Colors .blueAccent,
19+ this .duration = const Duration (milliseconds: 1000 ),
20+ this .dotType = LoaderDotType .circle,
21+ this .dotIcon = const Icon (Icons .blur_on)
22+ });
23+
24+ @override
25+ _GFLoaderState createState () => _GFLoaderState ();
26+ }
27+
28+ class _GFLoaderState extends State <GFLoader >
29+ with SingleTickerProviderStateMixin {
30+ Animation <double > animation_1;
31+ Animation <double > animation_2;
32+ Animation <double > animation_3;
33+ AnimationController controller;
34+
35+ @override
36+ void initState () {
37+ super .initState ();
38+
39+ controller = AnimationController (
40+ duration: widget.duration, vsync: this );
41+
42+ animation_1 = Tween (begin: 0.0 , end: 1.0 ).animate (
43+ CurvedAnimation (
44+ parent: controller,
45+ curve: Interval (0.0 , 0.70 , curve: Curves .linear),
46+ ),
47+ );
48+
49+ animation_2 = Tween (begin: 0.0 , end: 1.0 ).animate (
50+ CurvedAnimation (
51+ parent: controller,
52+ curve: Interval (0.1 , 0.80 , curve: Curves .linear),
53+ ),
54+ );
55+
56+ animation_3 = Tween (begin: 0.0 , end: 1.0 ).animate (
57+ CurvedAnimation (
58+ parent: controller,
59+ curve: Interval (0.2 , 0.90 , curve: Curves .linear),
60+ ),
61+ );
62+
63+ controller.addListener (() {
64+ setState (() {
65+ //print(animation_1.value);
66+ });
67+ });
68+
69+ controller.repeat ();
70+ }
71+
72+ @override
73+ Widget build (BuildContext context) {
74+ //print(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));
75+ return Container (
76+ child: new Row (
77+ mainAxisAlignment: MainAxisAlignment .center,
78+ children: < Widget > [
79+ Opacity (
80+ 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)),
81+ child: new Padding (
82+ padding: const EdgeInsets .only (right: 8.0 ),
83+ child: Dot (
84+ radius: 10.0 ,
85+ color: widget.dotOneColor,
86+ type: widget.dotType,
87+ icon: widget.dotIcon,
88+ ),
89+ ),
90+ ),
91+ Opacity (
92+ opacity: (animation_2.value <= 0.4 ? 2.5 * animation_2.value : (animation_2.value > 0.40 && animation_2.value <= 0.60 )? 1.0 : 2.5 - (2.5 * animation_2.value)),
93+ child: new Padding (
94+ padding: const EdgeInsets .only (right: 8.0 ),
95+ child: Dot (
96+ radius: 10.0 ,
97+ color: widget.dotTwoColor,
98+ type: widget.dotType,
99+ icon: widget.dotIcon,
100+ ),
101+ ),
102+ ),
103+ Opacity (
104+ opacity: (animation_3.value <= 0.4 ? 2.5 * animation_3.value : (animation_3.value > 0.40 && animation_3.value <= 0.60 ) ? 1.0 : 2.5 - (2.5 * animation_3.value)),
105+ child: new Padding (
106+ padding: const EdgeInsets .only (right: 8.0 ),
107+ child: Dot (
108+ radius: 10.0 ,
109+ color: widget.dotThreeColor,
110+ type: widget.dotType,
111+ icon: widget.dotIcon,
112+ ),
113+ ),
114+ ),
115+ ],
116+ ),
117+ );
118+ }
119+
120+ @override
121+ void dispose () {
122+
123+ controller.dispose ();
124+ super .dispose ();
125+ }
126+ }
127+
128+ class Dot extends StatelessWidget {
129+ final double radius;
130+ final Color color;
131+ final LoaderDotType type;
132+ final Icon icon;
133+
134+ Dot ({this .radius, this .color, this .type, this .icon});
135+
136+ @override
137+ Widget build (BuildContext context) {
138+ return new Center (
139+ child: type == LoaderDotType .icon ?
140+ Icon (icon.icon, color: color, size: 1.3 * radius,)
141+ : new Transform .rotate (
142+ angle: type == LoaderDotType .diamond ? pi/ 4 : 0.0 ,
143+ child: Container (
144+ width: radius,
145+ height: radius,
146+ decoration: BoxDecoration (color: color, shape: type == LoaderDotType .circle? BoxShape .circle : BoxShape .rectangle),
147+ ),
148+ ),
149+ );
150+ }
151+ }
0 commit comments