setProfile method

Future<void> setProfile(
  1. TrackingProfile profile, {
  2. String? reason,
})

Implementation

Future<void> setProfile(TrackingProfile profile, {String? reason}) async {
  if (_isDisposed) {
    debugPrint(
        'TrackingProfileManager: Cannot set profile, manager is disposed');
    return;
  }

  final config = _profiles[profile];
  if (config == null) {
    return;
  }
  final previousProfile = _current;
  await applyConfig(config);
  _current = profile;
  _lastSwitchAt = DateTime.now();

  // Emit profile change event (check disposed again after await)
  if (!_isDisposed) {
    _profileChangeController.add(ProfileChangeEvent(
      previousProfile: previousProfile,
      newProfile: profile,
      reason: reason,
    ));
  }
}