switchOwner method

  1. @override
Future<OwnerSwitchResult> switchOwner(
  1. TrackingOwner next, {
  2. OwnerSwitchPolicy policy = OwnerSwitchPolicy.rejectIfResumable,
})
override

Implementation

@override
Future<OwnerSwitchResult> switchOwner(
  TrackingOwner next, {
  OwnerSwitchPolicy policy = OwnerSwitchPolicy.rejectIfResumable,
}) async {
  final previous = _owner;
  if (_currentTrack?.status == TrackStatus.active) {
    if (policy != OwnerSwitchPolicy.pauseAndPreserveCurrent) {
      throw const TrackingConflictException(
        code: 'active_track_conflict',
        message: 'Pause the fake route before switching owner.',
      );
    }
    await pauseCurrentTrack(reason: 'owner_switched');
  }
  _owner = next;
  _publish();
  return OwnerSwitchResult(previous: previous, current: next);
}