From c909b2e00a5fddbd16c41eb742d3dbc7f79163fd Mon Sep 17 00:00:00 2001 From: singularity <12184989+singularity-s0@users.noreply.github.com> Date: Fri, 17 May 2024 18:46:04 +0800 Subject: [PATCH] feat: textfield expand button --- .../chat_ui/widgets/input/input.dart | 26 +++++++++++---- .../chat_ui/widgets/input/send_button.dart | 32 +++++++++++++++++++ 2 files changed, 52 insertions(+), 6 deletions(-) diff --git a/lib/views/components/chat_ui/widgets/input/input.dart b/lib/views/components/chat_ui/widgets/input/input.dart index 394f9e6..eb1c63d 100644 --- a/lib/views/components/chat_ui/widgets/input/input.dart +++ b/lib/views/components/chat_ui/widgets/input/input.dart @@ -54,7 +54,8 @@ class _InputState extends State { PhysicalKeyboardKey.shiftLeft, PhysicalKeyboardKey.shiftRight, }.contains(el), - )) { + ) && + !expanded) { if (event is KeyDownEvent && !_textController.value.composing.isValid) { _handleSendPressed(); } @@ -65,6 +66,7 @@ class _InputState extends State { }, ); + bool expanded = false; bool _sendButtonVisible = false; late TextEditingController _textController; @@ -123,6 +125,9 @@ class _InputState extends State { _textController.clear(); } } + setState(() { + expanded = false; + }); } void _handleTextControllerChange() { @@ -196,8 +201,8 @@ class _InputState extends State { ), focusNode: _inputFocusNode, keyboardType: TextInputType.multiline, - maxLines: 5, - minLines: 2, + maxLines: expanded ? 10 : 1, + minLines: expanded ? 10 : 1, onChanged: widget.options.onTextChanged, onTap: widget.options.onTextFieldTap, style: InheritedChatTheme.of(context) @@ -218,9 +223,18 @@ class _InputState extends State { ), child: Visibility( visible: _sendButtonVisible, - child: SendButton( - onPressed: _handleSendPressed, - padding: buttonPadding, + child: Row( + children: [ + ExpandButton(onPressed: () { + setState(() { + expanded = !expanded; + }); + }), + SendButton( + onPressed: _handleSendPressed, + padding: buttonPadding, + ), + ], ), ), ), diff --git a/lib/views/components/chat_ui/widgets/input/send_button.dart b/lib/views/components/chat_ui/widgets/input/send_button.dart index 3ab3cec..88ac653 100644 --- a/lib/views/components/chat_ui/widgets/input/send_button.dart +++ b/lib/views/components/chat_ui/widgets/input/send_button.dart @@ -37,3 +37,35 @@ class SendButton extends StatelessWidget { ), ); } + +class ExpandButton extends StatelessWidget { + /// Creates send button widget. + const ExpandButton({ + super.key, + required this.onPressed, + this.padding = EdgeInsets.zero, + }); + + /// Callback for send button tap event. + final VoidCallback onPressed; + + /// Padding around the button. + final EdgeInsets padding; + + @override + Widget build(BuildContext context) => Container( + margin: InheritedChatTheme.of(context).theme.sendButtonMargin ?? + const EdgeInsetsDirectional.fromSTEB(0, 0, 8, 0), + child: IconButton( + constraints: const BoxConstraints( + minHeight: 24, + minWidth: 24, + ), + icon: Icon(Icons.fullscreen, + color: InheritedChatTheme.of(context).theme.inputTextColor), + onPressed: onPressed, + padding: padding, + splashRadius: 24, + ), + ); +}