animatedDismissPopThis static method
Future<void>
animatedDismissPopThis({
- VoidCallback? onDismissExtraCallback,
- bool shouldPopBackToPreviousWidget = false,
Dismisses the PopThis overlay with an animated transition.
This method plays a dismissal animation (fade out and subtle scale down) before removing the overlay. The animation duration is 60% of the original popup animation duration for a snappier feel.
onDismissExtraCallback: Optional callback to execute after dismissal.shouldPopBackToPreviousWidget: If true, navigates to the previous widget in the pop history instead of dismissing the entire overlay. Defaults to false.
Returns a Future that completes when the animation finishes and the overlay is dismissed.
Implementation
static Future<void> animatedDismissPopThis({
VoidCallback? onDismissExtraCallback,
bool shouldPopBackToPreviousWidget = false,
}) async {
if (!isPopThisActive()) return;
// Get the current pop widget
var lastWidget =
_poppedWidgets.state.isNotEmpty ? _poppedWidgets.state.last : null;
double dismissAnimationDuration = lastWidget?.popUpAnimationDuration ?? 0.4;
// Dismiss is 60% of the original duration for a snappier feel
double actualDismissDuration = dismissAnimationDuration * 0.6;
// Trigger the dismiss animation via the ValueNotifier
_shouldAnimateOutNotifier.value = true;
// Wait for animation to complete
await Future.delayed(
Duration(milliseconds: (actualDismissDuration * 1000).toInt()));
// Then dismiss
dismissPopThis(
onDismissExtraCallback: onDismissExtraCallback,
shouldPopBackToPreviousWidget: shouldPopBackToPreviousWidget,
);
}