PostFrame class

Utility entry point for scheduling work after the initial frame and (optionally) after one or more end-of-frame passes and scroll metric stabilization.

This class provides a single static method postFrame which allows you to:

  • Run a callback only after the first frame has rendered.
  • Wait for multiple ScrollController instances to obtain stable metrics (e.g. maxScrollExtent, viewportDimension).
  • Wait for additional endOfFrame passes to give asynchronous layout or animations time to settle.

The returned Future completes when the action runs or completes with an error if the callback throws.

Constructors

PostFrame()

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Properties

errorHandler PostFrameErrorHandler?
Global error handler for all PostFrame operations.
getter/setter pair

Static Methods

builder<T>({required FutureOr<T> action(), required Widget builder(BuildContext, AsyncSnapshot<PostFrameResult<T>>), List<ScrollController> scrollControllers = const [], int maxWaitFrames = 5, bool waitForEndOfFrame = true, int endOfFramePasses = 2, Duration? timeout, bool runImmediately = true}) Widget
Declarative builder helper returning a widget that executes a post-frame action and rebuilds with an AsyncSnapshot of PostFrameResult.
clearQueue() → void
Clears any queued (not yet started) tasks.
debounced<T>(FutureOr<T> action(), {Object? debounceKey, List<ScrollController> scrollControllers = const [], int maxWaitFrames = 5, bool waitForEndOfFrame = true, int endOfFramePasses = 2, Duration? timeout, PostFramePredicate? predicate, void onError(Object error, StackTrace stackTrace)?}) PostFrameTask<T>
Schedule action to run after the current frame, canceling any previous pending action with the same debounceKey.
onLayout(GlobalKey<State<StatefulWidget>> key, {int maxWaitFrames = 20, int stabilityFrames = 2, bool waitForEndOfFrame = true}) Future<Size?>
Waits for the widget associated with key to obtain a non-zero size and remain stable for stabilityFrames consecutive frame checks. Returns the final Size or null if not resolved within maxWaitFrames.
postFrame(FutureOr<void> action(), {List<ScrollController> scrollControllers = const [], int maxWaitFrames = 5, bool waitForEndOfFrame = true, int endOfFramePasses = 2}) Future<void>
Schedule action to run after the current frame.
queueRun<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)?}) PostFrameTask<T>
Enqueue an advanced post-frame run ensuring sequential execution order. Tasks are processed one at a time; each waits for its own stabilization parameters. Useful when multiple callers need serialized layout-sensitive updates.
repeat(FutureOr<void> action(int iteration), {int? maxIterations, Duration? interval, bool waitForEndOfFrame = false}) PostFrameRepeater
Repeatedly schedules action to run on subsequent frames (optionally waiting for endOfFrame) until maxIterations is reached or canceled.
run<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)?}) PostFrameTask<T>
Unified advanced API returning a cancellable PostFrameTask with diagnostics encapsulated in a PostFrameResult.
simpleBuilder<T>({Key? key, required FutureOr<T> action(), List<ScrollController> scrollControllers = const [], int maxWaitFrames = 5, bool waitForEndOfFrame = true, int endOfFramePasses = 2, Duration? timeout, Widget? loading, Widget errorBuilder(PostFrameResult<T> result)?, Widget dataBuilder(PostFrameResult<T> result)?}) Widget
Convenience builder returning common loading/data/error widgets.