2019-12-16 00:18:09 +00:00
|
|
|
import 'dart:math';
|
|
|
|
|
2024-12-25 05:37:16 +00:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
2019-12-16 00:18:09 +00:00
|
|
|
enum DotType { square, circle, diamond, icon }
|
|
|
|
|
|
|
|
class Loader extends StatefulWidget {
|
|
|
|
final Color dotOneColor;
|
|
|
|
final Color dotTwoColor;
|
|
|
|
final Color dotThreeColor;
|
|
|
|
final Duration duration;
|
|
|
|
final DotType dotType;
|
|
|
|
final Icon dotIcon;
|
|
|
|
|
2024-12-25 05:37:16 +00:00
|
|
|
Loader({
|
|
|
|
this.dotOneColor = Colors.redAccent,
|
|
|
|
this.dotTwoColor = Colors.green,
|
|
|
|
this.dotThreeColor = Colors.blueAccent,
|
|
|
|
this.duration = const Duration(milliseconds: 1000),
|
|
|
|
this.dotType = DotType.circle,
|
|
|
|
this.dotIcon = const Icon(Icons.blur_on),
|
|
|
|
});
|
2019-12-16 00:18:09 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
_LoaderState createState() => _LoaderState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _LoaderState extends State<Loader> with SingleTickerProviderStateMixin {
|
2024-12-25 05:37:16 +00:00
|
|
|
late Animation<double> animation_1;
|
|
|
|
late Animation<double> animation_2;
|
|
|
|
late Animation<double> animation_3;
|
|
|
|
late AnimationController controller;
|
2019-12-16 00:18:09 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
|
|
|
|
|
|
|
controller = AnimationController(duration: widget.duration, vsync: this);
|
|
|
|
|
|
|
|
animation_1 = Tween(begin: 0.0, end: 1.0).animate(
|
|
|
|
CurvedAnimation(
|
|
|
|
parent: controller,
|
|
|
|
curve: Interval(0.0, 0.80, curve: Curves.ease),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
|
|
|
animation_2 = Tween(begin: 0.0, end: 1.0).animate(
|
|
|
|
CurvedAnimation(
|
|
|
|
parent: controller,
|
|
|
|
curve: Interval(0.1, 0.9, curve: Curves.ease),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
|
|
|
animation_3 = Tween(begin: 0.0, end: 1.0).animate(
|
|
|
|
CurvedAnimation(
|
|
|
|
parent: controller,
|
|
|
|
curve: Interval(0.2, 1.0, curve: Curves.ease),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
|
|
|
controller.addListener(() {
|
|
|
|
setState(() {
|
|
|
|
//print(animation_1.value);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
controller.repeat();
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Container(
|
|
|
|
child: new Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
children: <Widget>[
|
|
|
|
new Transform.translate(
|
|
|
|
offset: Offset(
|
|
|
|
0.0,
|
|
|
|
-30 *
|
|
|
|
(animation_1.value <= 0.50
|
|
|
|
? animation_1.value
|
|
|
|
: 1.0 - animation_1.value),
|
|
|
|
),
|
|
|
|
child: new Padding(
|
|
|
|
padding: const EdgeInsets.only(right: 8.0),
|
|
|
|
child: Dot(
|
|
|
|
radius: 10.0,
|
|
|
|
color: widget.dotOneColor,
|
|
|
|
type: widget.dotType,
|
|
|
|
icon: widget.dotIcon,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Transform.translate(
|
|
|
|
offset: Offset(
|
|
|
|
0.0,
|
|
|
|
-30 *
|
|
|
|
(animation_2.value <= 0.50
|
|
|
|
? animation_2.value
|
|
|
|
: 1.0 - animation_2.value),
|
|
|
|
),
|
|
|
|
child: new Padding(
|
|
|
|
padding: const EdgeInsets.only(right: 8.0),
|
|
|
|
child: Dot(
|
|
|
|
radius: 10.0,
|
|
|
|
color: widget.dotTwoColor,
|
|
|
|
type: widget.dotType,
|
|
|
|
icon: widget.dotIcon,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Transform.translate(
|
|
|
|
offset: Offset(
|
|
|
|
0.0,
|
|
|
|
-30 *
|
|
|
|
(animation_3.value <= 0.50
|
|
|
|
? animation_3.value
|
|
|
|
: 1.0 - animation_3.value),
|
|
|
|
),
|
|
|
|
child: new Padding(
|
|
|
|
padding: const EdgeInsets.only(right: 8.0),
|
|
|
|
child: Dot(
|
|
|
|
radius: 10.0,
|
|
|
|
color: widget.dotThreeColor,
|
|
|
|
type: widget.dotType,
|
|
|
|
icon: widget.dotIcon,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
void dispose() {
|
|
|
|
controller.dispose();
|
|
|
|
super.dispose();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class Dot extends StatelessWidget {
|
|
|
|
final double radius;
|
|
|
|
final Color color;
|
|
|
|
final DotType type;
|
|
|
|
final Icon icon;
|
|
|
|
|
2024-12-25 05:37:16 +00:00
|
|
|
Dot({
|
|
|
|
required this.radius,
|
|
|
|
required this.color,
|
|
|
|
required this.type,
|
|
|
|
required this.icon,
|
|
|
|
});
|
2019-12-16 00:18:09 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2024-12-25 05:37:16 +00:00
|
|
|
return Center(
|
2019-12-16 00:18:09 +00:00
|
|
|
child: type == DotType.icon
|
|
|
|
? Icon(
|
|
|
|
icon.icon,
|
|
|
|
color: color,
|
|
|
|
size: 1.3 * radius,
|
|
|
|
)
|
2024-12-25 05:37:16 +00:00
|
|
|
: Transform.rotate(
|
2019-12-16 00:18:09 +00:00
|
|
|
angle: type == DotType.diamond ? pi / 4 : 0.0,
|
|
|
|
child: Container(
|
|
|
|
width: radius,
|
|
|
|
height: radius,
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
color: color,
|
|
|
|
shape: type == DotType.circle
|
|
|
|
? BoxShape.circle
|
|
|
|
: BoxShape.rectangle),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|