Skip to main content

How to enable Sharing of a Post?

For the purposes of this guide, we are assuming you have followed the pre-requisite step of getting started. If not, please refer to this doc.

Enabling post sharing is a necessary step to allow content sharing ourside of the community to drive more engagement, here's how you can do it using the LikeMinds Feed Flutter SDK.

Follow the steps mentioned below.

Step 1

Pass the domain key while calling the initialize() function of the LMFeedCore class.

await LMFeedCore.instance.initialize(
apiKey: "YOUR_API_KEY", // Your community's API key
domain: "YOUR_DOMAIN", // Your domain
);

Below is the description of keys you have used in the above snippet.

NameTypeDescriptionOptional
apiKeyStringAPI key of the community
domainStringThis is the domain, and scheme of your link used to build shareable link inside Feed✔️

Step 2

We directly open the default share options, based on the platform (iOS or Android), on the click of our LMFeedButton implemented as the share button inside a post.

Our format of shared links for a post is - https://YOUR-DOMAIN/post?post_id=POST-ID

Otherwise, you can use the snippet below to call the function used in that button to trigger the share post flow on your end, if you are extending the existing Share button with customisations.

Step 3

Implement a link parsing function within you app, to capture the links sent (to the app) while clicking on shared links.

This can be done using the following official docs, for each stack

Android - Setup App links

iOS - Setup universal links

Some common steps you will have to follow to do this -

  • Adding appropriate entries in AndroidManifest.xml file and info.plist file for Android and iOS respectively.
  • Building a server side link verification system for iOS.
  • Using a package to intercept the link on app opens

Once you have verified your app is opening using your link, move to the next step.

Step 4

Check if the link is coming from LikeMinds.

Our format of shared links for a post is - YOUR-DOMAIN/post?post_id=POST-ID

To do this you can use the following snippet -

// Get the initial link with which the app was opened
final initialLink = "YOUR-PARSED-LINK";

//parse it using Uri.parse()
final uri = Uri.parse(initialLink);

//check if URI is absolute
if (uri.isAbsolute) {
//Check for LM post detail link schema
if (uri.path == '/post') {
List secondPath = initialLink.split('post_id=');
if (secondPath.length > 1 && secondPath[1] != null) {
//post_id is the secondSegment here
String postId = secondPathSegment[1];
navigateToPostDetailScreen(postId); // implemented below
}
}
}

Step 5

Once you have pared the link, and have the postId, use this snippet to navigate to LMPostDetailScreen

void navigateToPostDetailScreen(String postId){
// Build a material route using your preferred way
MaterialPageRoute route = MaterialPageRoute(
builder: (context) => LMFeedPostDetailScreen(
postId: postId, //required variable
),
);
//Navigate using your preferred
Navigator.of(context).push(route);
}

That's it. This will enable you to start accepting links, and navigating to the appropriate screens provided to you through our SDK.