mirror of
https://github.com/aljazceru/Auto-GPT.git
synced 2025-12-18 06:24:20 +01:00
Refactor ChatInputField to Support Continuous Mode
- Added a new boolean state `isContinuousMode` to the `ChatInputField` widget to handle the continuous mode feature. - Introduced a new callback function `onContinuousModePressed` to manage the state of the continuous mode from an external source. - Conditionally rendered the send button based on the `isContinuousMode` state. - Enhanced the UI by adding a button to toggle between continuous mode and single message mode, which triggers the `onContinuousModePressed` callback.
This commit is contained in:
@@ -3,10 +3,14 @@ import 'package:flutter/material.dart';
|
||||
class ChatInputField extends StatefulWidget {
|
||||
// Callback to be triggered when the send button is pressed
|
||||
final Function(String) onSendPressed;
|
||||
final Function() onContinuousModePressed;
|
||||
final bool isContinuousMode;
|
||||
|
||||
const ChatInputField({
|
||||
Key? key,
|
||||
required this.onSendPressed,
|
||||
required this.onContinuousModePressed,
|
||||
this.isContinuousMode = false,
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
@@ -49,6 +53,8 @@ class _ChatInputFieldState extends State<ChatInputField> {
|
||||
// when the content exceeds its maximum height
|
||||
child: SingleChildScrollView(
|
||||
reverse: true,
|
||||
// TODO: Deselect text field after user goes into continous mode
|
||||
// TODO: Include tool tip to explain clicking text field will end continuous mode
|
||||
child: TextField(
|
||||
controller: _controller,
|
||||
// Allowing the TextField to expand vertically and accommodate multiple lines
|
||||
@@ -56,16 +62,35 @@ class _ChatInputFieldState extends State<ChatInputField> {
|
||||
decoration: InputDecoration(
|
||||
hintText: 'Type a message...',
|
||||
border: InputBorder.none,
|
||||
suffixIcon: IconButton(
|
||||
splashRadius: 0.1,
|
||||
icon: const Icon(Icons.send),
|
||||
onPressed: () {
|
||||
// TODO: We allow empty messages?
|
||||
if (_controller.text.isNotEmpty) {
|
||||
widget.onSendPressed(_controller.text);
|
||||
_controller.clear();
|
||||
}
|
||||
},
|
||||
suffixIcon: Row(
|
||||
mainAxisSize: MainAxisSize.min, // Set to minimum space
|
||||
children: [
|
||||
if (!widget.isContinuousMode)
|
||||
// TODO: Include tool tip to explain single message sending
|
||||
IconButton(
|
||||
splashRadius: 0.1,
|
||||
icon: const Icon(Icons.send),
|
||||
onPressed: () {
|
||||
widget.onSendPressed(_controller.text);
|
||||
_controller.clear();
|
||||
},
|
||||
),
|
||||
// TODO: Include tool tip to explain continuous mode
|
||||
// TODO: Include pop up to explain continuous mode reprecussions
|
||||
IconButton(
|
||||
splashRadius: 0.1,
|
||||
icon: Icon(widget.isContinuousMode
|
||||
? Icons.pause
|
||||
: Icons.fast_forward),
|
||||
onPressed: () {
|
||||
if (!widget.isContinuousMode) {
|
||||
widget.onSendPressed(_controller.text);
|
||||
_controller.clear();
|
||||
}
|
||||
widget.onContinuousModePressed();
|
||||
},
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user