postFrameRun<T> method
PostFrameTask<T>
postFrameRun<T>(
- FutureOr<
T> action(), { - List<
ScrollController> scrollControllers = const [], - int maxWaitFrames = 5,
- bool waitForEndOfFrame = true,
- int endOfFramePasses = 2,
- Duration? timeout,
- PostFramePredicate? predicate,
- void onError(
- Object error,
- StackTrace stackTrace
Advanced post-frame run with context-aware mounted check predicate.
Automatically includes a predicate that checks if the widget is still
mounted before executing the action. You can provide an additional
predicate that will be AND-ed with the mounted check.
Implementation
PostFrameTask<T> postFrameRun<T>(
FutureOr<T> Function() action, {
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.run<T>(
action,
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,
);
}