@@ -19,14 +19,18 @@ class _ShadowButtonState extends State<ShadowButton> with TickerProviderStateMix
19
19
20
20
animationController = AnimationController (
21
21
vsync: this ,
22
- duration: const Duration (milliseconds: 50 ),
22
+ duration: const Duration (milliseconds: 80 ),
23
23
);
24
24
25
25
final tween = Tween <double >(begin: 8 , end: 0 );
26
26
final curvedAnimation = CurvedAnimation (parent: animationController, curve: Curves .easeOut);
27
27
animation = tween.animate (curvedAnimation);
28
28
29
29
animation.addListener (() {
30
+ if (animation.isCompleted) {
31
+ _animateRelease ();
32
+ }
33
+
30
34
setState (() {
31
35
shadowOffset = animation.value;
32
36
});
@@ -50,40 +54,34 @@ class _ShadowButtonState extends State<ShadowButton> with TickerProviderStateMix
50
54
51
55
@override
52
56
Widget build (BuildContext context) {
53
- return GestureDetector (
54
- behavior: HitTestBehavior .translucent,
55
- onTap: _animatePress,
56
- onTapDown: (_) => _animatePress (),
57
- onTapUp: (_) => _animateRelease (),
58
- onTapCancel: _animateRelease,
59
- child: Padding (
60
- padding: EdgeInsets .only (
61
- bottom: shadowOffset,
62
- right: shadowOffset,
63
- ),
64
- child: ShadowStyle (
65
- borderRadius: 12 ,
66
- offset: Offset (shadowOffset, shadowOffset),
67
- child: ElevatedButton (
68
- style: ButtonStyle (
69
- side: const MaterialStatePropertyAll (
70
- BorderSide (
71
- color: Colors .black,
72
- width: 2 ,
73
- ),
74
- ),
75
- shape: MaterialStatePropertyAll <OutlinedBorder >(
76
- RoundedRectangleBorder (
77
- borderRadius: BorderRadius .circular (12 ),
78
- ),
57
+ return Padding (
58
+ padding: EdgeInsets .only (
59
+ bottom: shadowOffset,
60
+ right: shadowOffset,
61
+ ),
62
+ child: ShadowStyle (
63
+ borderRadius: 12 ,
64
+ offset: Offset (shadowOffset, shadowOffset),
65
+ child: ElevatedButton (
66
+ style: ButtonStyle (
67
+ elevation: const MaterialStatePropertyAll (0 ),
68
+ side: const MaterialStatePropertyAll (
69
+ BorderSide (
70
+ color: Colors .black,
71
+ width: 2 ,
79
72
),
80
- fixedSize: const MaterialStatePropertyAll <Size >(
81
- Size (100 , 54 ),
73
+ ),
74
+ shape: MaterialStatePropertyAll <OutlinedBorder >(
75
+ RoundedRectangleBorder (
76
+ borderRadius: BorderRadius .circular (12 ),
82
77
),
83
78
),
84
- onPressed: () {},
85
- child: const Text ('Hello' ),
79
+ fixedSize: const MaterialStatePropertyAll <Size >(
80
+ Size (100 , 54 ),
81
+ ),
86
82
),
83
+ onPressed: _animatePress,
84
+ child: const Text ('Hello' ),
87
85
),
88
86
),
89
87
);
0 commit comments