Skip to content

Commit a461dee

Browse files
committed
Fix button not interactive beyond stack
1 parent 2976e7f commit a461dee

File tree

3 files changed

+45
-44
lines changed

3 files changed

+45
-44
lines changed

lib/shadow_button/button_style.dart

+29-31
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,18 @@ class _ShadowButtonState extends State<ShadowButton> with TickerProviderStateMix
1919

2020
animationController = AnimationController(
2121
vsync: this,
22-
duration: const Duration(milliseconds: 50),
22+
duration: const Duration(milliseconds: 80),
2323
);
2424

2525
final tween = Tween<double>(begin: 8, end: 0);
2626
final curvedAnimation = CurvedAnimation(parent: animationController, curve: Curves.easeOut);
2727
animation = tween.animate(curvedAnimation);
2828

2929
animation.addListener(() {
30+
if (animation.isCompleted) {
31+
_animateRelease();
32+
}
33+
3034
setState(() {
3135
shadowOffset = animation.value;
3236
});
@@ -50,40 +54,34 @@ class _ShadowButtonState extends State<ShadowButton> with TickerProviderStateMix
5054

5155
@override
5256
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,
7972
),
80-
fixedSize: const MaterialStatePropertyAll<Size>(
81-
Size(100, 54),
73+
),
74+
shape: MaterialStatePropertyAll<OutlinedBorder>(
75+
RoundedRectangleBorder(
76+
borderRadius: BorderRadius.circular(12),
8277
),
8378
),
84-
onPressed: () {},
85-
child: const Text('Hello'),
79+
fixedSize: const MaterialStatePropertyAll<Size>(
80+
Size(100, 54),
81+
),
8682
),
83+
onPressed: _animatePress,
84+
child: const Text('Hello'),
8785
),
8886
),
8987
);

lib/shadow_button/content_card.dart

+14-11
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,21 @@ class ContentCard extends StatelessWidget {
66

77
@override
88
Widget build(BuildContext context) {
9-
return ShadowStyle(
10-
child: SizedBox(
11-
height: 200,
12-
width: 320,
13-
child: Container(
14-
decoration: BoxDecoration(
15-
border: Border.all(
16-
color: Colors.black,
17-
width: 2,
9+
return Padding(
10+
padding: const EdgeInsets.only(bottom: 40),
11+
child: ShadowStyle(
12+
child: SizedBox(
13+
height: 200,
14+
width: 320,
15+
child: Container(
16+
decoration: BoxDecoration(
17+
border: Border.all(
18+
color: Colors.black,
19+
width: 2,
20+
),
21+
color: Colors.red,
22+
borderRadius: BorderRadius.circular(20),
1823
),
19-
color: Colors.red,
20-
borderRadius: BorderRadius.circular(20),
2124
),
2225
),
2326
),

lib/shadow_button/dash_card.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ class DashCard extends StatelessWidget {
1414
ContentCard(),
1515
Positioned(
1616
right: 35,
17-
bottom: -24,
17+
bottom: 4,
1818
child: ShadowButton(),
1919
),
2020
Positioned(
21-
bottom: -24,
21+
bottom: 4,
2222
right: 170,
2323
child: ShadowButton(),
2424
),

0 commit comments

Comments
 (0)