1
+ import 'package:flutter/material.dart' ;
2
+
3
+ class DancingMan extends StatefulWidget {
4
+ const DancingMan ({ Key ? key }) : super (key: key);
5
+
6
+ @override
7
+ _DancingManState createState () => _DancingManState ();
8
+ }
9
+
10
+ class _DancingManState extends State <DancingMan > with SingleTickerProviderStateMixin {
11
+ bool _isDancing = false ;
12
+
13
+ // margin animation from bottom
14
+ late AnimationController _marginAnimationController;
15
+ Animation <double >? _marginAnimation;
16
+
17
+ @override
18
+ void initState () {
19
+ super .initState ();
20
+
21
+ _marginAnimationController = AnimationController (
22
+ duration: const Duration (seconds: 2 ),
23
+ vsync: this ,
24
+ );
25
+
26
+ _marginAnimation = Tween <double >(
27
+ begin: 20.0 ,
28
+ end: 0.0 ,
29
+ ).animate (
30
+ CurvedAnimation (
31
+ parent: _marginAnimationController,
32
+ curve: Curves .easeInOut,
33
+ ),
34
+ );
35
+
36
+ _marginAnimationController.repeat ();
37
+ }
38
+
39
+ @override
40
+ Widget build (BuildContext context) {
41
+ return Scaffold (
42
+ backgroundColor: Color (0xffF8AD19 ),
43
+ body: Container (
44
+ height: MediaQuery .of (context).size.height,
45
+ child: GestureDetector (
46
+ onPanUpdate: (details) {
47
+ if (details.delta.dy > - 5 ) {
48
+ setState (() {
49
+ _isDancing = false ;
50
+ });
51
+ } else {
52
+ setState (() {
53
+ _isDancing = true ;
54
+ });
55
+ }
56
+ },
57
+ child: Column (
58
+ mainAxisAlignment: MainAxisAlignment .center,
59
+ children: [
60
+ _isDancing ?
61
+ Image .asset ('assets/dancing-man.gif' ,
62
+ height: 500 , fit: BoxFit .cover,)
63
+ : Image .asset ('assets/stop-man.png' , height: 500 ,),
64
+
65
+ SizedBox (height: 50 ,),
66
+ // animated arrow up Icon
67
+ _isDancing ?
68
+ Column (
69
+ children: [
70
+ Text ("Swipe Down to Stop" ),
71
+ SizedBox (height: 20 ,),
72
+ Icon (Icons .keyboard_arrow_down, color: Colors .black, size: 30 ,),
73
+ ],
74
+ )
75
+ :
76
+ Column (
77
+ children: [
78
+ AnimatedBuilder (
79
+ animation: _marginAnimation! ,
80
+ builder: (context, child) {
81
+ return Transform .translate (
82
+ offset: Offset (0 , _marginAnimation! .value),
83
+ child: Icon (Icons .keyboard_arrow_up, color: Colors .black, size: 30 ,),
84
+ );
85
+ },
86
+ ),
87
+ SizedBox (height: 20 ,),
88
+ Text ("Swipe Up To Play" ),
89
+ ],
90
+ )
91
+ ],
92
+ ),
93
+ )
94
+ ),
95
+ );
96
+ }
97
+ }
0 commit comments