Add ContinuousModeDialog and integrate with ChatInputField

- Introduced a new dialog, ContinuousModeDialog, to inform users about the repercussions of the continuous mode.
- Integrated ContinuousModeDialog with ChatInputField. The dialog is shown when the fast-forward icon is clicked, based on the user's shared preferences.
- Leveraged shared preferences to remember if the user has chosen not to see the dialog again.
- Enhanced the ChatInputField to handle different states and user interactions related to continuous mode.
This commit is contained in:
hunteraraujo
2023-09-26 14:25:20 -07:00
parent cf630e4f2c
commit 389131f2ab
2 changed files with 208 additions and 5 deletions

View File

@@ -1,4 +1,6 @@
import 'package:auto_gpt_flutter_client/views/chat/continuous_mode_dialog.dart';
import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';
class ChatInputField extends StatefulWidget {
// Callback to be triggered when the send button is pressed
@@ -38,6 +40,40 @@ class _ChatInputFieldState extends State<ChatInputField> {
super.dispose();
}
Future<void> _presentContinuousModeDialogIfNeeded() async {
final prefs = await SharedPreferences.getInstance();
final showContinuousModeDialog =
prefs.getBool('showContinuousModeDialog') ?? true;
if (showContinuousModeDialog) {
showDialog(
context: context,
builder: (BuildContext context) {
return ContinuousModeDialog(
onProceed: () {
Navigator.of(context).pop();
_executeContinuousMode();
},
onCheckboxChanged: (bool value) async {
await prefs.setBool('showContinuousModeDialog', !value);
},
);
},
);
} else {
_executeContinuousMode();
}
}
void _executeContinuousMode() {
if (!widget.isContinuousMode) {
widget.onSendPressed(_controller.text);
_controller.clear();
_focusNode.unfocus();
}
widget.onContinuousModePressed();
}
@override
Widget build(BuildContext context) {
// Using LayoutBuilder to provide the current constraints of the widget,
@@ -93,7 +129,6 @@ class _ChatInputFieldState extends State<ChatInputField> {
},
),
),
// TODO: Include pop up to explain continuous mode reprecussions
Tooltip(
message: widget.isContinuousMode
? ''
@@ -104,12 +139,12 @@ class _ChatInputFieldState extends State<ChatInputField> {
? Icons.pause
: Icons.fast_forward),
onPressed: () {
// TODO: All of this logic should be handled at a higher level in the widget tree. Temporary
if (!widget.isContinuousMode) {
widget.onSendPressed(_controller.text);
_controller.clear();
_focusNode.unfocus();
_presentContinuousModeDialogIfNeeded();
} else {
widget.onContinuousModePressed();
}
widget.onContinuousModePressed();
},
),
)