optionallyResolve method

Alignment optionallyResolve(
  1. BuildContext context
)

Resolves to Alignment, skipping resolution if already resolved.

Optimizes by checking if this is already an Alignment before resolving based on text directionality. This avoids unnecessary directionality lookups when the alignment is already concrete.

Parameters:

  • context (BuildContext, required): Context for directionality.

Returns: Alignment — the resolved alignment.

Implementation

Alignment optionallyResolve(BuildContext context) {
  // Why?
  // Because this checks first if the alignment is already an Alignment
  // before resolving the alignment based on the directionality of the context.
  if (this is Alignment) {
    return this as Alignment;
  }
  // The code belows also ignores if the alignment is already resolved,
  // but the code below fetches the directionality of the context.
  return resolve(Directionality.of(context));
}