runBridged<R> static method

R runBridged<R>(
  1. BuildContext context,
  2. R builder()
)

Executes builder within the Zone of the nearest LScope.

This bridges the gap between Widget-tree scoping (InheritedWidget) and static scoping (Zone), allowing Levit.find to work correctly.

Implementation

static R runBridged<R>(BuildContext context, R Function() builder) {
  final scope = _ScopeProvider.of(context);
  // Bridge widget-tree scope into Zone scope for `Levit.find` consistency.
  if (scope != null && scope != Ls.currentScope) {
    return scope.run(builder);
  }
  return builder();
}