ChatInput class
Message composer: a growing text field and a send button.
ChatView shows it by default. You can also place it yourself, for
example inside ChatView.inputBuilder to add leading or trailing
buttons:
inputBuilder: (context, send) => ChatInput(
onSend: send,
leading: IconButton(
icon: const Icon(Icons.add),
onPressed: pickAttachment,
),
),
On desktop and web, Enter sends and Shift+Enter inserts a new line. Selected text can be formatted from the context menu or with Ctrl/Cmd+B (bold), I (italic), Shift+X (strikethrough), E (code) and K (link).
- Inheritance
-
- Object
- DiagnosticableTree
- Widget
- StatefulWidget
- ChatInput
Constructors
-
ChatInput({Key? key, required ValueChanged<
String> onSend, bool enabled = true, String? hintText, ValueChanged<bool> ? onTypingChanged, Duration typingTimeout = const Duration(seconds: 3), Widget? leading, Widget? trailing, TextEditingController? controller, FocusNode? focusNode, bool autofocus = false, int maxLines = 6, int? maxLength, bool? sendOnEnter, TextCapitalization textCapitalization = TextCapitalization.sentences, IconData sendIcon = Icons.arrow_upward_rounded, VoidCallback? onRecordStart, ChatVoiceRecordEndCallback? onRecordEnd, bool showEmojiButton = false, VoidCallback? onStop, ValueChanged<String> ? onSchedule, List<ChatStickerPack> stickerPacks = const [], ValueChanged<ChatSticker> ? onSticker, ImageProvider<Object> imageProviderBuilder(String uri)?, bool allowEmptySend = false, VoidCallback? onArrowUp, VoidCallback? onEscape, ValueChanged<KeyboardInsertedContent> ? onContentInserted, bool enableFormatting = true}) -
Creates a message composer.
const
Properties
- allowEmptySend → bool
-
Whether the send button works with an empty field, for example while
attachments wait to be sent. onSend then receives an empty string.
final
- autofocus → bool
-
Whether the text field takes focus when shown.
final
- controller → TextEditingController?
-
Controls the text. When
null, the widget manages its own.final - enabled → bool
-
Whether the user can type and send.
final
- enableFormatting → bool
-
Whether selected text can be formatted with markdown from the context
menu and keyboard shortcuts.
final
- focusNode → FocusNode?
-
Focus of the text field. When
null, the widget manages its own.final - hashCode → int
-
The hash code for this object.
no setterinherited
- hintText → String?
-
Placeholder. Defaults to ChatLocalizations.inputHint.
final
-
imageProviderBuilder
→ ImageProvider<
Object> Function(String uri)? -
Loads sticker images. Defaults to NetworkImage.
final
- key → Key?
-
Controls how one widget replaces another widget in the tree.
finalinherited
- leading → Widget?
-
Widget before the text field, such as an attachment button.
final
- maxLength → int?
-
Optional character limit.
final
- maxLines → int
-
Lines the field grows to before scrolling.
final
- onArrowUp → VoidCallback?
-
Called when the user presses the up arrow in an empty field.
ChatViewuses it to edit the last message.final -
onContentInserted
→ ValueChanged<
KeyboardInsertedContent> ? -
Called when the keyboard inserts an image or GIF, for example from
Gboard. When
null, such keyboards do not offer images.final - onEscape → VoidCallback?
-
Called when the user presses Escape, for example to cancel a reply.
final
- onRecordEnd → ChatVoiceRecordEndCallback?
-
Called when the user releases the microphone button, or slides away to
cancel. Stop your recorder and send or discard the audio.
final
- onRecordStart → VoidCallback?
-
Called when the user presses and holds the microphone button. When
set, the send button turns into a microphone while the field is empty.
final
-
onSchedule
→ ValueChanged<
String> ? -
When set, long-pressing the send button calls this with the text, so
the app can offer to schedule the message.
final
-
onSend
→ ValueChanged<
String> -
Called with the trimmed text when the user sends a non-empty message.
final
-
onSticker
→ ValueChanged<
ChatSticker> ? -
Called when the user picks a sticker.
final
- onStop → VoidCallback?
-
When set, the send button becomes a stop button that calls this, for
example while an AI answer streams.
final
-
onTypingChanged
→ ValueChanged<
bool> ? -
Called with
truewhen the user starts typing and withfalseafter typingTimeout of inactivity or when the message is sent. Use it to broadcast your own typing state.final - runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- sendIcon → IconData
-
Icon of the send button.
ChatViewswitches it to a check mark while editing a message.final - sendOnEnter → bool?
-
Whether Enter sends the message. Defaults to
trueon web and desktop andfalseon mobile, where Enter inserts a new line.final - showEmojiButton → bool
-
Whether to show a button that swaps the keyboard for
ChatEmojiPicker.
ChatViewturns it on by default.final -
stickerPacks
→ List<
ChatStickerPack> -
Sticker packs shown as extra tabs in the emoji picker.
final
- textCapitalization → TextCapitalization
-
Capitalization of the on-screen keyboard.
final
- trailing → Widget?
-
Widget between the text field and the send button.
final
- typingTimeout → Duration
-
Inactivity delay after which onTypingChanged reports
false.final
Methods
-
createElement(
) → StatefulElement -
Creates a StatefulElement to manage this widget's location in the tree.
inherited
-
createState(
) → State< ChatInput> -
Creates the mutable state for this widget at a given location in the tree.
override
-
debugDescribeChildren(
) → List< DiagnosticsNode> -
Returns a list of DiagnosticsNode objects describing this node's
children.
inherited
-
debugFillProperties(
DiagnosticPropertiesBuilder properties) → void -
Add additional properties associated with the node.
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toDiagnosticsNode(
{String? name, DiagnosticsTreeStyle? style}) → DiagnosticsNode -
Returns a debug representation of the object that is used by debugging
tools and by DiagnosticsNode.toStringDeep.
inherited
-
toString(
{DiagnosticLevel minLevel = DiagnosticLevel.info}) → String -
A string representation of this object.
inherited
-
toStringDeep(
{String prefixLineOne = '', String? prefixOtherLines, DiagnosticLevel minLevel = DiagnosticLevel.debug, int wrapWidth = 65}) → String -
Returns a string representation of this node and its descendants.
inherited
-
toStringShallow(
{String joiner = ', ', DiagnosticLevel minLevel = DiagnosticLevel.debug}) → String -
Returns a one-line detailed description of the object.
inherited
-
toStringShort(
) → String -
A short, textual description of this widget.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited