-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathadd_todo_button.dart
121 lines (108 loc) · 3.26 KB
/
add_todo_button.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
import 'package:flutter/material.dart';
class AddTodoButton extends StatefulWidget {
final Function onClick;
//screen size
final Size size;
final bool editing;
const AddTodoButton({
Key key,
this.onClick,
this.size,
this.editing,
}) : super(key: key);
@override
_AddTodoButtonState createState() => _AddTodoButtonState();
}
class _AddTodoButtonState extends State<AddTodoButton>
with SingleTickerProviderStateMixin {
ButtonState buttonState = ButtonState.Small;
AnimationController _controller;
Animation<RelativeRect> _buttonAnimation;
Animation<double> _buttonTextAnimation;
@override
void initState() {
super.initState();
_controller =
AnimationController(duration: Duration(milliseconds: 450), vsync: this);
_buttonTextAnimation = Tween<double>(begin: 0.0, end: 1.0).animate(
CurvedAnimation(curve: Interval(0.7, 1.0), parent: _controller));
}
@override
void didUpdateWidget(AddTodoButton oldWidget) {
if (widget.editing != oldWidget.editing) {
_controller.value == 1.0 ? _controller.reverse() : _controller.forward();
}
super.didUpdateWidget(oldWidget);
}
@override
void dispose() {
_controller.dispose();
super.dispose();
}
void _handleClick() {
if (buttonState == ButtonState.Small) {
_controller.forward();
buttonState = ButtonState.Enlarged;
} else {
buttonState = ButtonState.Small;
_controller.reverse();
}
widget.onClick();
}
@override
Widget build(BuildContext context) {
final Size size = widget.size;
final Size buttonSize = Size(75.0, 75.0);
final double top = size.height - buttonSize.height;
final double initialLeftRight = (size.width - buttonSize.width) / 2;
_buttonAnimation = RelativeRectTween(
begin: RelativeRect.fromLTRB(
initialLeftRight, top - 25.0, initialLeftRight, 25.0),
end: RelativeRect.fromLTRB(0.0, top, 0.0, 0.0),
).animate(CurvedAnimation(curve: Interval(0.0, 0.7), parent: _controller));
return PositionedTransition(
rect: _buttonAnimation,
child: Container(
width: double.infinity,
height: double.infinity,
decoration: BoxDecoration(
gradient: LinearGradient(
colors: <Color>[
Color.fromRGBO(111, 94, 230, 1.0),
Color.fromRGBO(127, 110, 235, 1.0),
],
),
),
child: Material(
color: Colors.transparent,
child: InkWell(
onTap: _handleClick,
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Icon(
Icons.add,
color: Colors.white,
),
SizeTransition(
sizeFactor: _buttonTextAnimation,
axis: Axis.horizontal,
axisAlignment: -1.0,
child: Center(
child: Text(
'ADD TODO',
style: TextStyle(
color: Colors.white,
),
),
),
),
],
),
),
),
),
);
}
}
enum ButtonState { Small, Enlarged }