setServiceExtensionState method

Future<void> setServiceExtensionState(
  1. String name, {
  2. required bool enabled,
  3. required Object? value,
  4. bool callExtension = true,
})

Sets the state for a service extension and makes the call to the VMService.

Implementation

Future<void> setServiceExtensionState(
  String name, {
  required bool enabled,
  required Object? value,
  bool callExtension = true,
}) async {
  if (callExtension && _serviceExtensions.contains(name)) {
    await _callServiceExtension(name, value);
  } else if (callExtension) {
    _log.info(
      'Attempted to call extension \'$name\', but no service with that name exists',
    );
  }

  final state = ServiceExtensionState(enabled: enabled, value: value);
  _serviceExtensionState(name).value = state;

  // Add or remove service extension from [enabledServiceExtensions].
  if (enabled) {
    _enabledServiceExtensions[name] = state;
  } else {
    _enabledServiceExtensions.remove(name);
  }
}