Skip to main content

Getting Started

The LikeMinds Flutter Feed SDK provides a robust solution to seamlessly integrate dynamic and engaging feed experiences into your Flutter application. This guide walks you through setting up the LikeMinds Flutter Feed SDK, empowering you to deliver personalized content efficiently. Obtain the necessary API key from the LikeMinds dashboard.

Prerequisites

Before getting started, ensure you have:

  1. Flutter Version: Your Flutter version should be 3.19.0 or higher.

Step-by-Step Integration Guide

Follow these steps to integrate the LikeMinds Feed SDK into your Flutter application:

Step 1 - Installation

Open the terminal, and run the following command in your Flutter project's directory.

flutter pub add likeminds_feed_flutter_core

Step 2 - Setup LikeMinds Feed

Setup the LMFeedCore package in the main function with the following code

main(){
// Call setup function before the runApp() function
await LMFeedCore.instance.initialize(
// configure social feed theme
config: LMFeedConfig(
feedThemeType: LMFeedThemeType.social,
),
);
...
runApp(YourApp());
}

Step 3 - Initiate User Session

You have successfully initiated the LMFeedCore. Now, you have to initiate a user session. You can initiate the user session using one of the following two approaches:

1. With API Key (Client Side Authentication)

This approach should be used when you want to manage LikeMinds authentication tokens on frontend. In this case you provide API Key directly to LikeMinds Feed SDK, which will be used to initiate a user session by calling LMFeedCore.showFeedWithApiKey().

// initiate user session, use the response to check for any errors
LMResponse<void> response = await LMFeedCore.instance.showFeedWithApiKey(
apiKey : "YOUR_API_KEY",
uuid : "USER_ID",
userName : "USER_NAME",
);

2. Without API Key (Server Side Authentication)

This approach should be used when you want to manage LikeMinds authentication tokens on your backend server. In this case you eliminate the need to expose your API Key in your client app and your backend server is responsible for calling the Initiate API to obtain the accessToken and refreshToken which is passed to LMFeedCore.showFeed() to validate the user session.

  1. Create a function to get accessToken and refreshToken from your backend using initiate API
Future<(String, String)> getTokens() async {
...
// implementation
...
return (accessToken, refreshToken);
}
  1. While setting up the LMFeedCore in the main function pass LMFeedCoreCallback, which will be invoked when the accessToken and refreshToken expire.
info

LMFeedCoreCallback has two callbacks:

  1. onAccessTokenExpiredAndRefreshed: This callback is triggered when the provided accessToken expires and is refreshed internally using the refreshToken.

  2. onRefreshTokenExpired: This callback is triggered when the provided refreshToken expires. In this case, you need to provide a new accessToken and refreshToken from your backend function using our initiate API.

main(){
// Call setup function before the runApp() function
await LMFeedCore.instance.initialize(
// configure social feed theme
config: LMFeedConfig(
feedThemeType: LMFeedThemeType.social,
),
lmFeedCallback: LMFeedCoreCallback(
onAccessTokenExpiredAndRefreshed: (accessToken, refreshToken) {
debugPrint("Access token expired and refreshed");
},
onRefreshTokenExpired: () async {
// get accessToken, refreshToken from your backend
final (accessToken, refreshToken) = await getTokens();
// return `LMAuthToken` with `accessToken` and `refreshToken` received from your backend
return (LMAuthTokenBuilder()
..accessToken(accessToken!)
..refreshToken(refreshToken!))
.build();
},
),
);
...
runApp(YourApp());
}
  1. Use the getTokens() function, to fetch the tokens to login without API Key. Upon receiving the accessToken and refreshToken, call LMFeedCore.instance.showFeedWithoutApiKey() function with these tokens.
// get accessToken, refreshToken from your backend
final (accessToken, refreshToken) = await getTokens();
LMResponse response =
await LMFeedCore.instance.showFeedWithoutApiKey(
accessToken : "YOUR_ACCESS_TOKEN",
refreshToken : "YOUR_REFRESH_TOKEN",
);

Step 4 - Navigation to the feed

On successful response of the above snippet you can simply navigate to the Feed Screen, and start using Feed in your app


if (response.success) {
// create route with LMFeedSocialScreen
MaterialPageRoute route = MaterialPageRoute(
builder: (context) => const LMFeedSocialScreen(),
);
// navigate to LMFeedSocialScreen
Navigator.pushReplacement(context, route);
}

tip

By choosing the appropriate method based on your backend infrastructure and security preferences, you can seamlessly integrate the Feed SDK into your application while ensuring secure and efficient session management.

Congratulations! Your integration is now complete.

Welcome to the future of digital communities and social networks.


LMFeedAppbar