Getting Started
The LikeMinds Flutter Chat SDK provides a wrapper layer around the built-in functionalities to provide a seamless integration experience within a single sitting without much configuration needed out of the box.
Although we do provide a high level customisation of all the widgets, screens, and flows being used to power the experience that can be tuned according to the look and feel of your existing apps.
Prerequisites
Before getting started, ensure you have:
- An API key generated from the LikeMinds dashboard
- Flutter Version: Your Flutter version should be 3.19.0 or higher.
- The
likeminds_chat_flutter_core
dependency, which can be found here
Step-by-Step Integration Guide
Follow these steps to integrate the LikeMinds Chat 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_chat_flutter_core
Step 2 - Setup LikeMinds Chat
Setup the LMChatCore package in the main function with the following code
main() async {
WidgetsFlutterBinding.ensureInitialized();
// Call setup function before the runApp() function
await LMChatCore.instance.initialize();
...
runApp(YourApp());
}
Step 3 - Initiate User Session
You provide the API Key directly to the LikeMinds Chat SDK, which will be used to initiate a user session by calling showChatWithApiKey()
method from LMChatCore
.
// initiate user session, use the response to check for any errors
LMResponse<void> response = await LMChatCore.instance.showChatWithApiKey(
apiKey : "YOUR_API_KEY",
uuid : "USER_ID",
userName : "USER_NAME",
);
For enhanced security, you can use Server Side User Authentication to initiate user sessions through your own server.
Step 4 - Navigation to Chat
On successful response of the above snippet you can simply navigate to the LMChatHomeScreen
, and start using Chat in your app
if (response.success) {
MaterialPageRoute route = MaterialPageRoute(
builder: (context) => const LMChatHomeScreen(),
);
Navigator.pushReplacement(context, route);
}
That's it! You have successfully integrated the LikeMinds Chat SDK into your Flutter application. The next step would be to explore additional customization options or configurations provided by the SDK to tailor the chat to your application's needs.
Step 5 - Add Chatbot Button to your Screen (Optional)
Add AI Assitant to LikeMinds: Follow this tutorial to add Assistant to LikeMinds Dashboard, before proceeding with this step.
Add the LMChatAIButton
to your app's UI by placing it in the desired location within your app's widget tree. Ideally, a Floating Action Button (FAB) is the best place to put it.
Pass the required props to the LMChatAIButton
widget. A more detailed guide on the props can be found here. A sample is given below:
LMChatAIButton(
props: LMChatAIButtonProps(
apiKey: 'your-api-key',
uuid: 'user-unique-id',
userName: 'John Doe',
),
);
Now, whenever the button is pressed, the entire chat experience will be initialised with the provided props. A fresh chatroom (if not already present) will be created with the user's details. And the chatbot will be ready to take the user's queries.`