forked from md-siam/widget_of_the_day
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanimatedcontainer.dart
66 lines (59 loc) · 1.6 KB
/
animatedcontainer.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import 'package:flutter/material.dart';
class MyAnimatedContainer extends StatefulWidget {
const MyAnimatedContainer({Key? key}) : super(key: key);
@override
State<MyAnimatedContainer> createState() => _MyAnimatedContainerState();
}
class _MyAnimatedContainerState extends State<MyAnimatedContainer> {
double boxHeight = 100;
double boxWidth = 100;
var boxColor = Colors.deepPurple;
double boxX = -1;
double boxY = -1;
// change size of the AnimatedContainer
void _expandBox() {
setState(() {
boxHeight = 300;
boxWidth = 300;
});
}
// change color of the AnimatedContainer
void _changeBoxColor() {
setState(() {
boxColor = Colors.pink;
});
}
// change the alignment of the AnimationContainer
void _movedBox() {
setState(() {
boxX = 1;
boxY = 1;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.deepPurple[200],
appBar: AppBar(title: const Text("Animated Container")),
body: Center(
child: GestureDetector(
onTap: _movedBox,
child: AnimatedContainer(
duration: const Duration(seconds: 1),
// curve is for effects (defaultis Curves.linear)
curve: Curves.bounceInOut,
alignment: Alignment(boxX, boxY),
child: ClipRRect(
borderRadius: BorderRadius.circular(10),
child: Container(
height: boxHeight,
width: boxWidth,
color: boxColor,
),
),
),
),
),
);
}
}