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');
  }
  if (kIsWeb) {
    return null;
  }

  if (defaultTargetPlatform == TargetPlatform.android &&
      T == AndroidFlutterLocalNotificationsPlugin &&
      FlutterLocalNotificationsPlatform.instance
          is AndroidFlutterLocalNotificationsPlugin) {
    return FlutterLocalNotificationsPlatform.instance as T?;
  } else if (defaultTargetPlatform == TargetPlatform.iOS &&
      T == IOSFlutterLocalNotificationsPlugin &&
      FlutterLocalNotificationsPlatform.instance
          is IOSFlutterLocalNotificationsPlugin) {
    return FlutterLocalNotificationsPlatform.instance as T?;
  } else if (defaultTargetPlatform == TargetPlatform.macOS &&
      T == MacOSFlutterLocalNotificationsPlugin &&
      FlutterLocalNotificationsPlatform.instance
          is MacOSFlutterLocalNotificationsPlugin) {
    return FlutterLocalNotificationsPlatform.instance as T?;
  } else if (defaultTargetPlatform == TargetPlatform.linux &&
      T == LinuxFlutterLocalNotificationsPlugin &&
      FlutterLocalNotificationsPlatform.instance
          is LinuxFlutterLocalNotificationsPlugin) {
    return FlutterLocalNotificationsPlatform.instance as T?;
  }

  return null;
}