如何在 Flutter 中获取 OneSignal playerId (userId)?

How to get OneSignal playerId (userId) in Flutter?

如何在flutter应用程序中获取用户的playerId?。 Player Id 可以在 One signal 网站上找到,但我希望它在 flutter 应用程序中并希望存储它以将通知发送给特定用户。

这是我用于启动一个信号的转到函数

  Future<void> initOneSignal(BuildContext context) async {
    /// Set App Id.
    await OneSignal.shared.setAppId(SahityaOneSignalCollection.appID);

    /// Get the Onesignal userId and update that into the firebase.
    /// So, that it can be used to send Notifications to users later.̥
    final status = await OneSignal.shared.getDeviceState();
    final String? osUserID = status?.userId;
    // We will update this once he logged in and goes to dashboard.
    ////updateUserProfile(osUserID);
    // Store it into shared prefs, So that later we can use it.
    Preferences.setOnesignalUserId(osUserID);

    // The promptForPushNotificationsWithUserResponse function will show the iOS push notification prompt. We recommend removing the following code and instead using an In-App Message to prompt for notification permission
    await OneSignal.shared.promptUserForPushNotificationPermission(
      fallbackToSettings: true,
    );

    /// Calls when foreground notification arrives.
    OneSignal.shared.setNotificationWillShowInForegroundHandler(
      handleForegroundNotifications,
    );

    /// Calls when the notification opens the app.
    OneSignal.shared.setNotificationOpenedHandler(handleBackgroundNotification);
  }