mirror of
https://github.com/aljazceru/Auto-GPT.git
synced 2026-01-28 18:34:23 +01:00
Refactor ChatInputField to Use Callback for Sending Messages
This commit brings a key update to the ChatInputField widget, making it more flexible and decoupled: - The onSendPressed callback now takes a string parameter. This string represents the message that the user wishes to send. - The onPressed of the send button (IconButton) is now implemented within the ChatInputField widget. It checks if the TextField has any text before calling onSendPressed. - Added a TextEditingController to manage the TextField's content.
This commit is contained in:
@@ -2,7 +2,7 @@ import 'package:flutter/material.dart';
|
||||
|
||||
class ChatInputField extends StatefulWidget {
|
||||
// Callback to be triggered when the send button is pressed
|
||||
final VoidCallback onSendPressed;
|
||||
final Function(String) onSendPressed;
|
||||
|
||||
const ChatInputField({
|
||||
Key? key,
|
||||
@@ -59,7 +59,13 @@ class _ChatInputFieldState extends State<ChatInputField> {
|
||||
suffixIcon: IconButton(
|
||||
splashRadius: 0.1,
|
||||
icon: const Icon(Icons.send),
|
||||
onPressed: widget.onSendPressed,
|
||||
onPressed: () {
|
||||
// TODO: We allow empty messages?
|
||||
if (_controller.text.isNotEmpty) {
|
||||
widget.onSendPressed(_controller.text);
|
||||
_controller.clear();
|
||||
}
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user