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:
- 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
- Add
likeminds_feed_flutter_core
dependency to your project’spubspec.yaml
by adding these lines underdependencies
section
likeminds_feed_flutter_core: ^latest #fetches automatically from pub.dev
Step 2 - Setup LikeMinds Feed
Setup the LMFeedCore package in the main function with the following code
- Social Feed
- QnA Feed
main(){
// Call setup function before the runApp() function
await LMFeedCore.instance.initialize(
// configure social feed theme
config: LMFeedConfig(
feedThemeType: LMFeedThemeType.social,
),
);
...
runApp(YourApp());
}
main(){
// Call setup function before the runApp() function
await LMFeedCore.instance.initialize(
// configure qna feed theme
config: LMFeedConfig(
feedThemeType: LMFeedThemeType.qna,
),
);
...
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.
- Create a function to get accessToken and refreshToken from your backend using initiate API
Future<(String, String)> getTokens() async {
...
// implementation
...
return (accessToken, refreshToken);
}
- While setting up the LMFeedCore in the main function pass
LMFeedCoreCallback
, which will be invoked when theaccessToken
andrefreshToken
expire.
LMFeedCoreCallback
has two callbacks:
onAccessTokenExpiredAndRefreshed: This callback is triggered when the provided
accessToken
expires and is refreshed internally using therefreshToken
.onRefreshTokenExpired: This callback is triggered when the provided
refreshToken
expires. In this case, you need to provide a newaccessToken
andrefreshToken
from your backend function using our initiate API.
- Social Feed
- QnA Feed
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());
}
main(){
// Call setup function before the runApp() function
await LMFeedCore.instance.initialize(
// configure qna feed theme
config: LMFeedConfig(
feedThemeType: LMFeedThemeType.qna,
),
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());
}
- Use the
getTokens()
function, to fetch the tokens to login without API Key. Upon receiving theaccessToken
andrefreshToken
, callLMFeedCore.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
- Social Feed
- QnA Feed
if (response.success) {
// create route with LMFeedSocialScreen
MaterialPageRoute route = MaterialPageRoute(
builder: (context) => const LMFeedSocialScreen(),
);
// navigate to LMFeedSocialScreen
Navigator.pushReplacement(context, route);
}
if (response.success) {
// create route with LMFeedQnAScreen
MaterialPageRoute route = MaterialPageRoute(
builder: (context) => const LMFeedQnAScreen(),
);
// navigate to LMFeedQnAScreen
Navigator.pushReplacement(context, route);
}
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.
3. Extra steps for features
Some features are optional and require extra configuration, you can find it here
- To start uploading media to feed (release mode) - Add Proguard rules using the guide below
Proguard setup
This is required only for Android, when you are building for release mode.
To enable uploading of media in the release build of Android, add these lines in your app/build.gradle
minifyEnabled true
useProguard true
proguardFiles getDefaultProguardFile('proguard-android.txt'),
'proguard-aws-2.1.5.pro'
//EXAMPLE
buildTypes {
release {
signingConfig signingConfigs.release
minifyEnabled true
useProguard true
proguardFiles getDefaultProguardFile('proguard-android.txt'),
'proguard-aws-2.1.5.pro'
}
}
Now create a new file with name "proguard-aws-2.1.5.pro" at the same location as app/build.gradle and paste the copied contents into this file. Paste the content below into this file.
# These options are the minimal options for a functioning application
# using Proguard and the AWS SDK 2.1.5 for Android
-keep class io.flutter.app.** { *; }
-keep class io.flutter.plugin.** { *; }
-keep class io.flutter.util.** { *; }
-keep class io.flutter.view.** { *; }
-keep class io.flutter.** { *; }
-keep class io.flutter.plugins.** { *; }
-keep class org.apache.commons.logging.** { *; }
-keep class com.amazonaws.org.apache.commons.logging.** { *; }
-keep class com.amazonaws.services.sqs.QueueUrlHandler { *; }
-keep class com.amazonaws.javax.xml.transform.sax.* { public *; }
-keep class com.amazonaws.javax.xml.stream.** { *; }
-keep class com.amazonaws.services.**.model.*Exception* { *; }
-keep class com.amazonaws.internal.** { *; }
-keep class org.codehaus.** { *; }
-keep class org.joda.time.tz.Provider { *; }
-keep class org.joda.time.tz.NameProvider { *; }
-keepattributes Signature,*Annotation*,EnclosingMethod
-keepnames class com.fasterxml.jackson.** { *; }
-keepnames class com.amazonaws.** { *; }
-dontwarn com.fasterxml.jackson.databind.**
-dontwarn javax.xml.stream.events.**
-dontwarn org.codehaus.jackson.**
-dontwarn org.apache.commons.logging.impl.**
-dontwarn org.apache.http.conn.scheme.**
-dontwarn org.apache.http.annotation.**
-dontwarn org.ietf.jgss.**
-dontwarn org.joda.convert.**
-dontwarn com.amazonaws.org.joda.convert.**
-dontwarn org.w3c.dom.bootstrap.**
#SDK split into multiple jars so certain classes may be referenced but not used
-dontwarn com.amazonaws.services.s3.**
-dontwarn com.amazonaws.services.sqs.**
-dontnote com.amazonaws.services.sqs.QueueUrlHandler
Your release mode APK should work now.