Skip to content

Commit 7e9fe4e

Browse files
committed
button [nfc]: Move AnimatedScaleOnTap to new file lib/widgets/button.dart
1 parent e932a05 commit 7e9fe4e

File tree

2 files changed

+48
-46
lines changed

2 files changed

+48
-46
lines changed

lib/widgets/button.dart

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import 'package:flutter/widgets.dart';
2+
3+
/// Apply [Transform.scale] to the child widget when tapped, and reset its scale
4+
/// when released, while animating the transitions.
5+
class AnimatedScaleOnTap extends StatefulWidget {
6+
const AnimatedScaleOnTap({
7+
super.key,
8+
required this.scaleEnd,
9+
required this.duration,
10+
required this.child,
11+
});
12+
13+
/// The terminal scale to animate to.
14+
final double scaleEnd;
15+
16+
/// The duration over which to animate the scale change.
17+
final Duration duration;
18+
19+
final Widget child;
20+
21+
@override
22+
State<AnimatedScaleOnTap> createState() => _AnimatedScaleOnTapState();
23+
}
24+
25+
class _AnimatedScaleOnTapState extends State<AnimatedScaleOnTap> {
26+
double _scale = 1;
27+
28+
void _changeScale(double scale) {
29+
setState(() {
30+
_scale = scale;
31+
});
32+
}
33+
34+
@override
35+
Widget build(BuildContext context) {
36+
return GestureDetector(
37+
behavior: HitTestBehavior.translucent,
38+
onTapDown: (_) => _changeScale(widget.scaleEnd),
39+
onTapUp: (_) => _changeScale(1),
40+
onTapCancel: () => _changeScale(1),
41+
child: AnimatedScale(
42+
scale: _scale,
43+
duration: widget.duration,
44+
curve: Curves.easeOut,
45+
child: widget.child));
46+
}
47+
}

lib/widgets/home.dart

Lines changed: 1 addition & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import 'about_zulip.dart';
88
import 'action_sheet.dart';
99
import 'app.dart';
1010
import 'app_bar.dart';
11+
import 'button.dart';
1112
import 'color.dart';
1213
import 'content.dart';
1314
import 'icons.dart';
@@ -601,49 +602,3 @@ class _AboutZulipButton extends _MenuButton {
601602
Navigator.of(context).push(AboutZulipPage.buildRoute(context));
602603
}
603604
}
604-
605-
/// Apply [Transform.scale] to the child widget when tapped, and reset its scale
606-
/// when released, while animating the transitions.
607-
class AnimatedScaleOnTap extends StatefulWidget {
608-
const AnimatedScaleOnTap({
609-
super.key,
610-
required this.scaleEnd,
611-
required this.duration,
612-
required this.child,
613-
});
614-
615-
/// The terminal scale to animate to.
616-
final double scaleEnd;
617-
618-
/// The duration over which to animate the scale change.
619-
final Duration duration;
620-
621-
final Widget child;
622-
623-
@override
624-
State<AnimatedScaleOnTap> createState() => _AnimatedScaleOnTapState();
625-
}
626-
627-
class _AnimatedScaleOnTapState extends State<AnimatedScaleOnTap> {
628-
double _scale = 1;
629-
630-
void _changeScale(double scale) {
631-
setState(() {
632-
_scale = scale;
633-
});
634-
}
635-
636-
@override
637-
Widget build(BuildContext context) {
638-
return GestureDetector(
639-
behavior: HitTestBehavior.translucent,
640-
onTapDown: (_) => _changeScale(widget.scaleEnd),
641-
onTapUp: (_) => _changeScale(1),
642-
onTapCancel: () => _changeScale(1),
643-
child: AnimatedScale(
644-
scale: _scale,
645-
duration: widget.duration,
646-
curve: Curves.easeOut,
647-
child: widget.child));
648-
}
649-
}

0 commit comments

Comments
 (0)