get<T> method

T? get<T>({
  1. T onAndroid(
    1. NearbyAndroidService
    )?,
  2. T onIOS(
    1. NearbyIOSService
    )?,
  3. T onAny(
    1. NearbyService
    )?,
})

If you want to do different actions or get different data depending on the platform, use get.

Note: any of the callbacks must not be null!

Implementation

T? get<T>({
  T Function(NearbyAndroidService)? onAndroid,
  T Function(NearbyIOSService)? onIOS,
  T Function(NearbyService)? onAny,
}) {
  assert(
    onAndroid != null || onIOS != null || onAny != null,
    'You should provide at least one of (onAndroid, onIOS, onAny)',
  );
  if (this is NearbyAndroidService && onAndroid != null) {
    return onAndroid(this as NearbyAndroidService);
  }
  if (this is NearbyIOSService && onIOS != null) {
    return onIOS(this as NearbyIOSService);
  }
  if (onAny != null) {
    return onAny(this);
  }
  return null;
}