actionButton property

ChatActionButton? actionButton
final

Represents a send button.

The SfChat widget does not include an action button by default. To add, create a new instance of ChatActionButton.

If the ChatActionButton.onPressed callback is null, the button remains disabled.

If the default composer's text is empty or if the composer is disabled, the button remains disabled.

If the composer is null, the button always stays enabled.

Pressing the action button invokes the ChatActionButton.onPressed callback with the text entered in the default composer. By default, SfChat will not update its state until the parent widget rebuilds the chat with new messages.

If ChatComposer.builder is used, the button always stays enabled.

List<ChatMessage> _messages = <ChatMessage>[
  ChatMessage(
    text: 'Hello, how can I help you today?',
    time: DateTime.now(),
    author: const ChatAuthor(
      id: 'a2c4-56h8-9x01-2a3d',
      name: 'Incoming user name',
    ),
  ),
];

@override
Widget build(BuildContext context) {
  return SfChat(
    messages: _messages,
    outgoingUser: '8ob3-b720-g9s6-25s8',
    actionButton: ChatActionButton(
      onPressed: (String newMessage) {
        setState(() {
          _messages.add(
            ChatMessage(
              text: newMessage,
              time: DateTime.now(),
              author: const ChatAuthor(
                id: '8ob3-b720-g9s6-25s8',
                name: 'Outgoing user name',
              ),
            ),
          );
        });
      },
    ),
  );
}

See also:

Implementation

final ChatActionButton? actionButton;