Skip to content

Commit

Permalink
fix: show full scale animation
Browse files Browse the repository at this point in the history
  • Loading branch information
vaetas committed Apr 26, 2022
1 parent 1219c76 commit 14cc122
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
3 changes: 3 additions & 0 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ class HomeScreen extends StatelessWidget {
onPressed: () {
print('[HomeScreen.build] Scale pressed');
},
// onLongPressed: () {
// print('[HomeScreen.build] Scale long-pressed');
// },
child: const ExampleButton(title: 'Scale'),
),
Pressable.opacity(
Expand Down
22 changes: 20 additions & 2 deletions lib/src/scale.dart
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,34 @@ class _PressableScaleState extends PressableBaseState<PressableScale>
_controller.animateTo(theme.scaleFactor);
}

void _revertAnimation() {
_controller.animateTo(1.0);
}

/// Wait for animation end before animating back to the default state.
///
/// Used when press is too short to make the animation still visible.
void _animationFinishedListener() {
if (_controller.isCompleted) {
_revertAnimation();
_controller.removeListener(_animationFinishedListener);
}
}

@override
void onPressEnded(TapUpDetails details) {
super.onPressEnded(details);
_controller.animateTo(1.0);
if (_controller.isAnimating) {
_controller.addListener(_animationFinishedListener);
} else {
_revertAnimation();
}
}

@override
void onPressCanceled() {
super.onPressCanceled();
_controller.animateTo(1.0);
_revertAnimation();
}

@override
Expand Down

0 comments on commit 14cc122

Please sign in to comment.