withMetrics<T> static method

T withMetrics<T>(
  1. DimenMetrics metrics,
  2. T body()
)

Runs body with an explicit metrics scope (save/restore), mirroring DimenCache.withMetrics.

Implementation

static T withMetrics<T>(DimenMetrics metrics, T Function() body) {
  final previous = _slot;
  final previousContext = _contextSlot;
  _slot = metrics;
  _contextSlot = null;
  try {
    return body();
  } finally {
    _slot = previous;
    _contextSlot = previousContext;
  }
}