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:
hunteraraujo
2023-09-06 11:46:03 -07:00
parent 5cd1abab94
commit d80053e8dc

View File

@@ -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(
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: () {
// TODO: We allow empty messages?
if (_controller.text.isNotEmpty) {
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();
},
)
],
),
),
),