Back
Psychological EngineeringIntermediate5 min

Hold to Confirm

Learn how to build a custom Hold to Confirm button in Flutter using AnimationController. Replace alert dialogs with modern, tactile UX for destructive actions.

Hold to Confirm ⏱️

For decades, software has relied on the infamous “Are you sure?” dialog box to prevent users from accidentally deleting data. The problem? Users have developed muscle memory and blindly click “Yes” on pop-ups without reading them.

Modern apps (like banking apps, server dashboards, and game inventories) have replaced these pop-ups with Hold-to-Confirm buttons. It physically forces the user to pause, hold their finger down, and watch a progress bar fill up. It is impossible to do by accident.

How it works in Flutter

We don’t need any external packages. We build this using three core Flutter concepts:

  1. AnimationController: We create a controller with a duration of 1.5 seconds.
  2. Listener: We wrap our button in a Listener to detect raw touch events.
    • onPointerDown: We call _controller.forward() to start filling the bar.
    • onPointerUp: If the user lets go early, we call _controller.reverse() so the bar shrinks back down.
  3. FractionallySizedBox: We use this inside a Stack to draw the filling background color based on _controller.value.

Haptic Feedback (Physical UX)

To make it feel like a real, heavy physical button, we use HapticFeedback:

  • HapticFeedback.lightImpact() when the user starts holding.
  • HapticFeedback.heavyImpact() when the animation reaches 100% and the action is irreversibly executed.

Try letting go before the bar fills up to see the cancellation animation!