postFrameDebounced<T> method

PostFrameTask<T> postFrameDebounced<T>(
  1. FutureOr<T> action(), {
  2. Object? debounceKey,
  3. List<ScrollController> scrollControllers = const [],
  4. int maxWaitFrames = 5,
  5. bool waitForEndOfFrame = true,
  6. int endOfFramePasses = 2,
  7. Duration? timeout,
  8. PostFramePredicate? predicate,
  9. void onError(
    1. Object error,
    2. StackTrace stackTrace
    )?,
})

Debounced post-frame run with context-aware mounted check.

Similar to postFrameRun but with debouncing capability.

Implementation

PostFrameTask<T> postFrameDebounced<T>(
  FutureOr<T> Function() action, {
  Object? debounceKey,
  List<ScrollController> scrollControllers = const [],
  int maxWaitFrames = 5,
  bool waitForEndOfFrame = true,
  int endOfFramePasses = 2,
  Duration? timeout,
  PostFramePredicate? predicate,
  void Function(Object error, StackTrace stackTrace)? onError,
}) {
  // Capture the element for mounted check.
  final element = this as Element;

  return PostFrame.debounced<T>(
    action,
    debounceKey: debounceKey,
    scrollControllers: scrollControllers,
    maxWaitFrames: maxWaitFrames,
    waitForEndOfFrame: waitForEndOfFrame,
    endOfFramePasses: endOfFramePasses,
    timeout: timeout,
    predicate: () {
      // Check if widget is still mounted.
      if (!element.mounted) return false;
      // Apply additional predicate if provided.
      return predicate?.call() ?? true;
    },
    onError: onError,
  );
}