mirror of
https://github.com/aljazceru/Auto-GPT.git
synced 2025-12-18 14:34:23 +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 {
|
class ChatInputField extends StatefulWidget {
|
||||||
// Callback to be triggered when the send button is pressed
|
// Callback to be triggered when the send button is pressed
|
||||||
final Function(String) onSendPressed;
|
final Function(String) onSendPressed;
|
||||||
|
final Function() onContinuousModePressed;
|
||||||
|
final bool isContinuousMode;
|
||||||
|
|
||||||
const ChatInputField({
|
const ChatInputField({
|
||||||
Key? key,
|
Key? key,
|
||||||
required this.onSendPressed,
|
required this.onSendPressed,
|
||||||
|
required this.onContinuousModePressed,
|
||||||
|
this.isContinuousMode = false,
|
||||||
}) : super(key: key);
|
}) : super(key: key);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -49,6 +53,8 @@ class _ChatInputFieldState extends State<ChatInputField> {
|
|||||||
// when the content exceeds its maximum height
|
// when the content exceeds its maximum height
|
||||||
child: SingleChildScrollView(
|
child: SingleChildScrollView(
|
||||||
reverse: true,
|
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(
|
child: TextField(
|
||||||
controller: _controller,
|
controller: _controller,
|
||||||
// Allowing the TextField to expand vertically and accommodate multiple lines
|
// Allowing the TextField to expand vertically and accommodate multiple lines
|
||||||
@@ -56,16 +62,35 @@ class _ChatInputFieldState extends State<ChatInputField> {
|
|||||||
decoration: InputDecoration(
|
decoration: InputDecoration(
|
||||||
hintText: 'Type a message...',
|
hintText: 'Type a message...',
|
||||||
border: InputBorder.none,
|
border: InputBorder.none,
|
||||||
suffixIcon: IconButton(
|
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,
|
splashRadius: 0.1,
|
||||||
icon: const Icon(Icons.send),
|
icon: const Icon(Icons.send),
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
// TODO: We allow empty messages?
|
widget.onSendPressed(_controller.text);
|
||||||
if (_controller.text.isNotEmpty) {
|
_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);
|
widget.onSendPressed(_controller.text);
|
||||||
_controller.clear();
|
_controller.clear();
|
||||||
}
|
}
|
||||||
|
widget.onContinuousModePressed();
|
||||||
},
|
},
|
||||||
|
)
|
||||||
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
Reference in New Issue
Block a user