@@ -120,6 +120,18 @@ class Composer extends StatefulWidget {
120120 /// `disabled` modes still requires text to be present.
121121 final bool allowEmptyMessage;
122122
123+ /// Whether to disable the send button.
124+ ///
125+ /// If `true` , this will override [sendButtonVisibilityMode] and show a
126+ /// disabled button. Defaults to `false` .
127+ final bool sendButtonDisabled;
128+
129+ /// Whether to always hide the send button.
130+ ///
131+ /// If `true` , this will override all other send button-related properties
132+ /// and hide the button. Defaults to `false` .
133+ final bool sendButtonHidden;
134+
123135 /// Creates a message composer widget.
124136 const Composer ({
125137 super .key,
@@ -161,6 +173,8 @@ class Composer extends StatefulWidget {
161173 this .maxLines = 3 ,
162174 this .sendButtonVisibilityMode = SendButtonVisibilityMode .disabled,
163175 this .allowEmptyMessage = false ,
176+ this .sendButtonDisabled = false ,
177+ this .sendButtonHidden = false ,
164178 });
165179
166180 @override
@@ -302,41 +316,43 @@ class _ComposerState extends State<Composer> {
302316 ),
303317 ),
304318 SizedBox (width: widget.gap),
305- widget.sendIcon != null
306- ? ValueListenableBuilder <bool >(
307- valueListenable: _hasTextNotifier,
308- builder: (context, hasText, child) {
309- if (widget.sendButtonVisibilityMode ==
310- SendButtonVisibilityMode .hidden &&
311- ! hasText) {
312- return const SizedBox .shrink ();
313- }
314-
315- final isActive =
316- hasText ||
317- widget.sendButtonVisibilityMode ==
318- SendButtonVisibilityMode .always;
319-
320- return IconButton (
321- icon: widget.sendIcon! ,
322- color:
323- isActive
324- ? (widget.sendIconColor ??
325- theme.onSurface.withValues (alpha: 0.5 ))
326- : (widget.emptyFieldSendIconColor ??
327- widget.sendIconColor ??
328- theme.onSurface.withValues (alpha: 0.5 )),
329- onPressed:
330- (widget.sendButtonVisibilityMode ==
331- SendButtonVisibilityMode .disabled &&
332- ! hasText)
333- ? null
334- : () =>
335- _handleSubmitted (_textController.text),
336- );
337- },
338- )
339- : const SizedBox .shrink (),
319+ if (widget.sendIcon != null && ! widget.sendButtonHidden)
320+ ValueListenableBuilder <bool >(
321+ valueListenable: _hasTextNotifier,
322+ builder: (context, hasText, child) {
323+ if (widget.sendButtonVisibilityMode ==
324+ SendButtonVisibilityMode .hidden &&
325+ ! hasText) {
326+ return const SizedBox .shrink ();
327+ }
328+
329+ final isActive =
330+ (hasText ||
331+ widget.sendButtonVisibilityMode ==
332+ SendButtonVisibilityMode .always) &&
333+ ! widget.sendButtonDisabled;
334+
335+ return IconButton (
336+ icon: widget.sendIcon! ,
337+ color:
338+ isActive
339+ ? (widget.sendIconColor ??
340+ theme.onSurface.withValues (alpha: 0.5 ))
341+ : (widget.emptyFieldSendIconColor ??
342+ widget.sendIconColor ??
343+ theme.onSurface.withValues (alpha: 0.5 )),
344+ onPressed:
345+ (widget.sendButtonVisibilityMode ==
346+ SendButtonVisibilityMode .disabled &&
347+ ! hasText) ||
348+ widget.sendButtonDisabled
349+ ? null
350+ : () => _handleSubmitted (_textController.text),
351+ );
352+ },
353+ )
354+ else
355+ const SizedBox .shrink (),
340356 ],
341357 ),
342358 ),
0 commit comments