applyInjection method

bool applyInjection(
  1. RenderMetricsInjection injection
)

Applies an external RenderMetricsInjection.

Returns true when any stored value changed.

Implementation

bool applyInjection(RenderMetricsInjection injection) {
  var changed = false;

  final nextMetrics = injection.metrics;
  if (nextMetrics != null && !identical(nextMetrics, metrics)) {
    metrics = nextMetrics;
    changed = true;
  }

  if (injection.clearEntries && _customMetrics.isNotEmpty) {
    _customMetrics.clear();
    changed = true;
  }

  if (injection.removeKeys.isNotEmpty) {
    for (final key in injection.removeKeys) {
      final removed = _customMetrics.remove(key);
      if (removed != null) changed = true;
    }
  }

  if (injection.upsertEntries.isNotEmpty) {
    for (final entry in injection.upsertEntries.entries) {
      final prev = _customMetrics[entry.key];
      if (prev == entry.value) continue;
      _customMetrics[entry.key] = entry.value;
      changed = true;
    }
  }

  return changed;
}