livehive_sdk_flutter 0.0.1
livehive_sdk_flutter: ^0.0.1 copied to clipboard
The LiveHive Flutter SDK.
LiveHive SDK #
The official LiveHive product offering real-time multi-touchpoint consumer data to 10X your decisions with automated insights. One powerful tool, offering millions of data points.
Requirements #
environment:
sdk: ^3.10.1
flutter: ">=3.3.0"
Download #
Setup #
Usage #
First, get an instance of the sdk in your widget as follows:
final _liveHiveSdk = LivehiveSdkFlutter();
After that, use the instance above to initialise the SDK in your main entry point of the application using _liveHiveSdk.initialise("api key here", isDailyPoints: Boolean). Once you have
provided a valid API key, you can then launch the SDK by calling _liveHiveSdk.start("unique_user_id"). From this point, the SDK will start requesting for the
necessary permissions and privileges from the user until done.
Once all the permissions are granted, the app will run in the background silently as it collects necessary usage data.
NOTE: If you do not supply the api key, the app will throw an exception and fail to work.
If, during initialisation, you set the isDailyPoints flag to false (the flag is true by default), your users will not be accumulating daily points as others. In that case, you will have to ignore the totalPoints field in the response above.
All the necessary daily points calculation UI will also be hidden from the user if isDailyPoints is false.
When working with rewards, the following APIs are available:
-
getRewards({required String userId}): Fetches the current reward status for a user.- Response:
{ "totalPoints": int, "isActive": bool }
- Response:
-
redeemRewards({required String userId, required int points}): Redeems a specified number of points for a user.- Response:
{ "message": string, "newTotalPoints": int, "redemptionId": string, "refundExpiresAt": string }
- Response:
-
refundRewards({required String userId, required String redemptionId}): Refunds a previously redeemed reward using its redemption ID.- Response:
{ "message": string, "newTotalPoints": int }
- Response:
-
awardRewards({required String userId, required int points, required String source, required String awardKey}): Awards points to a user from a specific source and award key.- Response:
{ "message": string, "newTotalPoints": int }
- Response:
During cleanup, eg when the user logs out, do remember to call _liveHiveSdk.close(context) to ensure all cached data is cleaned up.
On Customisation #
For the purposes of customising and truly owning the SDK to present an experience that is unique to your app, you should override the following strings in your strings.xml of the android directory file to use your app name
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">YOUR_APP_NAME</string>
<string name="livehive_accessibility_service_description">Accessibility service for YOUR_APP_NAME</string>
<string name="livehive_accessibility_service_label">YOUR_APP_NAME Accessibility Service</string>
</resources>
If you do not customise these values, then the default name LiveHive will be used by default for sections where customisation makes sense e.g Accessibility
On Theming #
You have two options to handle theming in your themes.xml file in the android directory:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- OPTION 1: Use your own parent theme. Make sure it is a material theme -->
<style name="Theme.LiveHiveApp" parent="Theme.Material3.DayNight.NoActionBar">
<!-- Customise other attributes here as you wish -->
<!-- If the calling app does not utilise the parent theme from LiveHive as shown below, the following MUST be declared explicitly -->
<item name="live_hive_instructions_background_color">@color/black</item>
<item name="live_hive_instructions_title_color">@color/white</item>
<item name="live_hive_instructions_card_border_color">@color/white</item>
<item name="live_hive_instructions_card_subtitle_background_color">@color/grey_light</item>
<item name="live_hive_instructions_card_subtitle_text_color">@color/white</item>
<item name="live_hive_instructions_card_background_color">@color/black</item>
<item name="live_hive_instructions_card_title_color">@color/white</item>
<item name="live_hive_instructions_card_text_color">@color/white</item>
<!-- The color of the link is set to #ff33b5e5. At present, this is not customisable. -->
<item name="live_hive_instructions_legal_text_color">@color/white</item>
<item name="live_hive_instructions_button_color">@color/blue</item>
<!--Make sure the theme you provide here is a material theme-->
<item name="live_hive_instructions_done_button_style">@style/InstructionsButton</item>
<item name="live_hive_check_mark_color">@color/white</item>
</style>
<!-- OPTION 2: Use the parent theme from LiveHive. -->
<style name="Theme.LiveHiveApp" parent="LiveHive.Theme">
<!-- Customise other attributes here as you wish -->
<!-- OPTIONAL: Customise LiveHive specific attributes as needed or don't and use the default colors provided by the SDK -->
</style>
</resources>
The default theme for the live_hive_instructions_done_button_style is completely in the developer's hands so you need to specify all the attributes you want, including the width and height. The default is as follows:
<style name="InstructionsButton" parent="Widget.MaterialComponents.Button">
<item name="android:layout_width">54dp</item>
<item name="android:layout_height">54dp</item>
<item name="android:insetTop">0dp</item>
<item name="android:insetBottom">0dp</item>
<item name="android:insetLeft">0dp</item>
<item name="android:insetRight">0dp</item>
<item name="iconPadding">0dp</item>
<item name="iconGravity">textStart</item>
<item name="iconSize">40dp</item>
<item name="icon">@drawable/ic_chevron_right</item>
<item name="iconTint">@color/white</item>
<item name="backgroundTint">@color/blue</item>
<item name="cornerRadius">27dp</item>
</style>