livelike_flutter_sdk 0.2.0
livelike_flutter_sdk: ^0.2.0 copied to clipboard
To use the services and features of LiveLike SDK
livelike_flutter_sdk #
The Official Flutter LiveLike SDK #
Create Engagement SDK instance
final sdk = EngagementSDK("<client-id>");
copied to clipboard
Create Engagement SDK instance with access token support
final sdk = EngagementSDK.accessToken("<client-id>","<saved-access-token>",(accessToken){
//fetched access token
});
copied to clipboard
Error Delegate Support
sdk.errorStream.listen((error) {
print("Error: $error");
//Getting error from any where from the sdk
});
copied to clipboard
ChatView
ChatView(key: Key("${chatSession.chatRoomId}"),
session:chatSession!);
copied to clipboard
WidgetView
WidgetView(session: session!,
key: Key(session!.programId!));
copied to clipboard
Leaderboard API's
Getting Leaderboard associated with a Program
final List<LeaderBoard> list = await sdk.getLeaderBoards("<program-id>");
copied to clipboard
Getting leaderboard details
final LeaderBoard detail=await sdk.getLeaderBoardDetails("<leaderBoardId>");
copied to clipboard
Getting leaderboard entries
final List<LeaderBoardEntry> result = await sdk.getEntriesForLeaderBoard(
"<leaderboard-id>", "<LiveLikePagination>");
copied to clipboard
Getting leaderboard entry for a given profile
final LeaderBoardEntry result = await sdk.getLeaderBoardEntryForProfile(
"<leaderboard-id>", "<profile-id>");
copied to clipboard
Getting a leaderboard entry for the current user profile
final LeaderBoardEntry result = await sdk.getLeaderBoardEntryForCurrentUserProfile("<leaderboard-id>");
copied to clipboard
Sponsor APi
final sposnors =await sdk.sponsor.fetchByProgramId("<program-id>")
copied to clipboard
widgetListener Api
WidgetView(
session: session,
widgetListener: (widgetId, widgetKind) {
print("object>> $widgetId => $widgetKind");
},
)
copied to clipboard
Display Widget in WidgetView using LiveLikeWidget,Enable/Disable Widget Transition, Update State of widget inside WidgetView
final widgetKey = GlobalKey<WidgetViewState>();
WidgetView(
key:widgetKey
)
//To display call the method
widgetKey.currentState?.displayWidget(widget);
widgetKey.currentState?.enableDefaultWidgetTransition(false);
widgetKey.currentState?.setWidgetState(WidgetState.Result);
copied to clipboard
widgets have 4 states to ready,interacting,results,finished
Fetch User Interaction Data based on widgetId and WidgetKind
final interactionData = await session.fetchUserInteractionDataForWidget(widgetId!, widgetKind!);
copied to clipboard
Note #
If you are facing extra padding when keyboard appears in IOS, then add
resizeToAvoidBottomInset: !Platform.IOS,
copied to clipboard
attribute to your Scaffold to avoid this issue, and make sure it is true for android platform
Widget View with support in ListView #
Now widgetView can be used with listview, you need to create an instance of widgetview and assign a key to it and then call the methods to perform the actions , below is the example of how to do this.
final key = GlobalKey<WidgetViewState>();
final widgetView = WidgetView(
key: key,
widgetListener: (id, kind) {
// print("WidgetView>> $id >> $index");
},
showWidgetViewWithDefaultHeight: true,
onWidgetViewInit: () {
if (key.currentState != null) {
await key.currentState!.enableDefaultWidgetTransition(false);
await key.currentState!.showDismissButton(false);
await key.currentState!.displayWidget(widget);
await Future.delayed(const Duration(seconds: 2));
await key.currentState!.setWidgetState(WidgetState.results);
}
},
);
copied to clipboard
after calling display widget , if you need to change the state of the widget ,make sure to do the task with some delay in time,
we will be adding support for this future.
To fetch List of Posted Widgets for a given Program #
In order to fetch the posted widgets associated to a program , you need to call the getPostedWidget api of session class
final list = await session?.getPublishedWidgets(LiveLikePagination.first);
copied to clipboard
the LiveLikePagination enum is used for lazy loading, right now by default widgets loaded a limit of 20, in order
to start the call the api with LiveLikePagination.first which will return you first page data and call api with LiveLikePagination.next which will get next page data and similarly LiveLikePagination.previous will get previous page data, in next once you get the empty array you have reached the last page.
Fetch Widget Details #
In order to fetch details of a particular widget
await sdk.fetchWidgetDetails(widgetId!, widgetKind!);
copied to clipboard
The api requried widgetid and widgetKind , and the result will be LiveLikeWidget model class
To fetch WidgetModel using LiveLikeWidget #
final widgetModel = await session.fetchWidgetModel(<LiveLikeWidget class instance>);
copied to clipboard
WidgetModel #
Components of WidgetModel:
LiveLikeWidget #
The instance of the livelikeWidget class which is used to create the widget model, contains the data of the widgets
Vote Api #
In Order to vote on a particular option, the voting method is used, it contains optionId and magnitude , magnitude is used for sending vote for Image Slider Widget, and for the rest of the widget the optionId is sent.
widgetModel.vote(magnitude: <value>);
widgetModel.vote(optionId: <value>)
copied to clipboard
Vote Result Stream #
In Order to receive the vote count for options associated with a widget, the voteResultStream is used. It returns the instance of VoteCountResult class, which contains the option id,vote count,magnitude values
widgetModel?.voteCountResultStream.listen((event) {
//VoteCountResult
}))
copied to clipboard
Dispose #
The dispose method is used to clear and release the instances associated to widgetModel. #
widgetModel.dispose()
copied to clipboard
TimeLineView #
In order to use the native timelineView
TimeLineView(
session: _controller.session.value!,
sepratorHeight: 100,
onInit: () {} )
copied to clipboard
Json Theming #
added api in widgetView to support json theming #
try {
await widgetKey.currentState?.setJsonTheme(jsonString);
} on PlatformException catch (e) {
if (e.message != null) showErrorMessage(e.message!);
}
copied to clipboard