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:
- 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);
- Get the SDK initialization result in the
onHydraSdkInitializationResult({required bool success, String? error})
callback provided by the handler. - Use the HydraCore class for user management. It includes static functions such as: signUp, signIn, updateUser, signOut, updateGeoConfig, updatePushPreferences, and reportUserEvent.
- 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.
- The HydraPushNotification class provides static functions for push notifications: requestPermission and getFCMToken. To receive push notifications, you can ask for permission using requestPermission.
- Use getFCMToken to get the FCM token. If you added an event handler in step 1, you also receive the callback in onTokenAvailable.
- Use the HydraInbox class to manage them with functions like getInboxMessages, getUnreadInboxMessagesCount, markInboxMessageAsRead, deleteInboxMessage, and deleteAllInboxMessages. The Hydra SDK saves notifications in a database.
- Use the HydraInboxUI class functions: showNotificationCenter and hideNotificationCenterIfShowing to use the built-in notification center from the Hydra plugin.
- 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.
Updated 11 minutes ago