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:
AnimationController: We create a controller with a duration of 1.5 seconds.Listener: We wrap our button in aListenerto 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.
FractionallySizedBox: We use this inside aStackto 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!