I make chat screen. There is no send message button near the text field in the design. How can I send a message from a text field by pressing a button on the system’s keyboard (like this green button on screen)? I use TextFormField widget for entering the text.
To send a message from the TextFormField on the keyboard button press, you can make use of the onFieldSubmitted property in the TextFormField widget. This triggers when the user presses the keyboard action button (like the green "send" button). Here’s a basic approach:
TextFormField(
decoration: InputDecoration(
hintText: "Type a message",
),
onFieldSubmitted: (message) {
if (message.isNotEmpty) {
// Implement the logic to send the message here
print("Message sent: $message");
}
},
textInputAction: TextInputAction.send, // Sets the button to a 'send' icon
)
3
Answers
To send a message from the TextFormField on the keyboard button press, you can make use of the onFieldSubmitted property in the TextFormField widget. This triggers when the user presses the keyboard action button (like the green "send" button). Here’s a basic approach:
You can achieve the Send action by using TextInputAction.send
You can use this code below. You can change the Icon using TextInputAction.done. Use
onFieldSubmitted: (value){}
to get value