resolvePlatformSpecificImplementation<T extends FlutterLocalNotificationsPlatform> method

T? resolvePlatformSpecificImplementation<T extends FlutterLocalNotificationsPlatform>()

Returns the underlying platform-specific implementation of given type T, which must be a concrete subclass of FlutterLocalNotificationsPlatform

Requires running on the appropriate platform that matches the specified type for a result to be returned. For example, when the specified type argument is of type AndroidFlutterLocalNotificationsPlugin, this will only return a result of that type when running on Android.

Implementation

T? resolvePlatformSpecificImplementation<
  T extends FlutterLocalNotificationsPlatform
>() {
  if (T == FlutterLocalNotificationsPlatform) {
    throw ArgumentError.value(
      T,
      'The type argument must be a concrete subclass of '
      'FlutterLocalNotificationsPlatform',
    );
  }

  final FlutterLocalNotificationsPlatform instance =
      FlutterLocalNotificationsPlatform.instance;
  if (kIsWeb && T == WebFlutterLocalNotificationsPlugin && instance is T) {
    return instance;
  } else if (defaultTargetPlatform == TargetPlatform.android &&
      T == AndroidFlutterLocalNotificationsPlugin &&
      instance is T) {
    return instance;
  } else if (defaultTargetPlatform == TargetPlatform.iOS &&
      T == IOSFlutterLocalNotificationsPlugin &&
      instance is T) {
    return instance;
  } else if (defaultTargetPlatform == TargetPlatform.macOS &&
      T == MacOSFlutterLocalNotificationsPlugin &&
      instance is T) {
    return instance;
  } else if (defaultTargetPlatform == TargetPlatform.linux &&
      T == LinuxFlutterLocalNotificationsPlugin &&
      instance is T) {
    return instance;
  } else if (defaultTargetPlatform == TargetPlatform.windows &&
      T == FlutterLocalNotificationsWindows &&
      instance is T) {
    return instance;
  }

  return null;
}