Initialise Flutter

Before you can use APIs from the flutter-hydra-lib plugin, ensure the Hydra SDK is initialized successfully.

To initiaize Hydra SDK for Flutter, follow these steps:

  1. Set up a [HydraNativeEventHandler](https://docs.capillarytech.com/docs/flutter-sdk-api-reference#hydranativeeventhandler-class) and add it using the following code:
    HydraNativeEvents.addEventHandler(handler);
    
  2. Get the SDK initialization result in theonHydraSdkInitializationResult({required bool success, String? error}) callback provided by the handler.
  3. Use the HydraCore class for user management. It includes static functions such as: signUp, signIn, updateUser, signOut, updateGeoConfig, updatePushPreferences, and reportUserEvent.
  4. These functions accept a HydraUserDetails instance, which requires a customerId that must match the configuration on the Capillary CRM dashboard. Use the signUp function to register the user. For subsequent launches, use signIn.
  5. The HydraPushNotification class provides static functions for push notifications: requestPermission and getFCMToken. To receive push notifications, you can ask for permission using requestPermission.
  6. Use getFCMToken to get the FCM token. If you added an event handler in step 1, you also receive the callback in onTokenAvailable.
  7. Use the HydraInbox class to manage them with functions like getInboxMessages, getUnreadInboxMessagesCount, markInboxMessageAsRead, deleteInboxMessage, and deleteAllInboxMessages. The Hydra SDK saves notifications in a database.
  8. Use the HydraInboxUI class functions: showNotificationCenter and hideNotificationCenterIfShowing to use the built-in notification center from the Hydra plugin.
  9. Set the console log level in hydra-config.json. It should be an integer from 0 to 5, where 0 represents off, 1 for error, 2 for warning, 3 for info, 4 for debug, and 5 for verbose. You can also set one of these log levels for remote logging using hydra_remote_log_level in Firebase Remote Configuration.

The HydraNativeEventHandler also includes callbacks for onHydraNotificationReceived, onHydraNotificationClicked, onHydraNotificationDismissed, onHydraNotificationShown, and onNotificationCenterDismissed.