Chatbot Screen
Introduction
The AI Chatbot Initiation Screen serves as an intermediate loading screen while setting up and navigating to an AI chatbot conversation. It displays an animation and status text while performing the necessary initialization steps in the background.
LMChatAIBotInitiationScreen
Widget
File Location:
init_chatbot.dart
Class Declaration
class LMChatAIBotInitiationScreen extends StatefulWidget {
final String? animationToShow;
final LMChatTextBuilder? previewText;
const LMChatAIBotInitiationScreen({
Key? key,
this.animationToShow,
this.previewText,
}) : super(key: key);
}
Properties
Property | Type | Description |
---|---|---|
animationToShow | String? | Custom Lottie animation JSON asset path to display during initialization |
previewText | LMChatTextBuilder? | Custom text builder to display loading status |
Functionality
The screen performs the following steps:
Fetches Available Chatbots
- Retrieves the list of AI chatbots using
LMChatClient.getAIChatbots()
- Selects the first available chatbot
- Retrieves the list of AI chatbots using
Checks DM Status
- Verifies if a conversation already exists with the chatbot
- Extracts existing chatroom ID if present
Chatroom Setup
- If an existing chatroom is found, navigates to it
- Otherwise, creates a new DM chatroom with the chatbot
Navigation
- Stores the chatroom ID locally
- Redirects to
LMChatroomScreen
with the appropriate chatroom ID
Usage Example
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => LMChatAIBotInitiationScreen(
// Optional: Custom animation asset
animationToShow: 'assets/custom_loading.json',
// Optional: Custom loading text
previewText: (context, defaultText) => Text('Custom loading message'),
),
),
);
Summary
The AI Chatbot Initiation Screen provides a seamless transition when setting up or accessing an AI chatbot conversation. It handles all the necessary initialization steps while displaying a visually appealing loading interface to the user. The screen can be customized with different animations and text displays to match the app's design requirements.