get<T> method
T?
get<T>({
- T onAndroid()?,
- T onIOS()?,
- T onAny()?,
If you want to do different actions or get different data depending on the platform, use get.
-
The
onAndroid
callback returns this instance of NearbyService, cast as NearbyAndroidService if Platform.isAndroid is true. -
The
onIOS
callback returns this instance of NearbyService, cast as NearbyIOSService if Platform.isIOS is true. -
The
onAny
callback returns this instance of NearbyService with no casting if both Platform.isAndroid and Platform.isIOS are false.
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;
}