Skip to main content

LMChatAIButton

File location
chatbot_ai_button.dart

LMChatAIButton is a customizable button widget used within the chat interface to allow for direct initialization of the AI chatbot. It can be used as a FloatingActionButton or as a regular button. It supports icons, text, and state management for active and inactive modes.

Properties

PropertyTypeRequiredDescription
textLMChatText?NoThe text widget to be displayed on the button
iconLMChatIcon?NoThe icon widget to be displayed on the button
styleLMChatAIButtonStyle?NoStyle configuration for customizing the button's appearance
propsLMChatAIButtonProps?NoConfiguration properties for AI chatbot initialization, including authentication and user information
onTapVoidCallback?NoCallback function triggered when the button is tapped

Styling

LMChatButtonStyle

File location
chatbot_ai_button.dart

LMChatAIButtonStyle defines the visual appearance of the button, including text, colors, size, and icon placement.

PropertyTypeRequiredDefaultDescription
textString?No'AI Bot'The text to be displayed on the button
textSizedouble?No14The size of the button text in logical pixels
textColorColor?NoColor(0xFFFFFFFF)The color of the button text
backgroundColorColor?NoColor(0xFF020D42)The background color of the button
borderRadiusdouble?No28The border radius of the button in logical pixels
iconIconData?NonullThe icon to be displayed on the button
iconPlacementLMChatIconButtonPlacementNoLMChatIconButtonPlacement.startThe placement of the icon relative to the text

You can use the LMChatAIButtonStyle.basic() method to create a basic style with default values.

Note: These properties are only a subset. More can be found inside the style class.


Props

The LMChatAIButton accepts the following properties through the LMChatAIButtonProps class:

PropTypeRequiredDescription
apiKeyStringRequired*The API key used for authentication when not using token-based security. Required when using the non-token based authentication method.
uuidStringRequired*The unique identifier for the user. Required when using the non-token based authentication method.
userNameStringRequired*The display name of the user. Required when using the non-token based authentication method.
imageUrlStringOptionalThe URL of the user's profile image. Used for user profile customization.
isGuestboolOptionalIndicates whether the user is a guest user. Defaults to false if not provided.
accessTokenStringRequired**The access token for token-based security authentication. Required when using the token-based authentication method.
refreshTokenStringRequired**The refresh token for token-based security authentication. Required when using the token-based authentication method.

* Required for client-side authentication ** Required for server-side authentication

Authentication Methods

The LMChatAIButton supports two authentication methods:

  1. Client-Side Authentication

    • Requires: apiKey, uuid, and userName
    • Optional: imageUrl, isGuest
  2. Server-Side Authentication

    • Requires: accessToken and refreshToken

Example Usage

// Example with server-side authentication
final chatButton = LMChatAIButton(
text: LMChatText('Chat with AI'),
icon: LMChatIcon(Icons.chat),
style: LMChatAIButtonStyle.basic(),
props: LMChatAIButtonProps(
accessToken: 'your-access-token',
refreshToken: 'your-refresh-token',
),
);

// Example with client-side authentication
final apiKeyChatButton = LMChatAIButton(
text: LMChatText('Chat with AI'),
icon: LMChatIcon(Icons.chat),
style: LMChatAIButtonStyle.basic(),
props: LMChatAIButtonProps(
apiKey: 'your-api-key',
uuid: 'user-unique-id',
userName: 'John Doe',
),
onTap: () => print('Button tapped'),
);