AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.
Refactor ChatInputField to use SharedPreferencesService
hunteraraujodbec110bac04
diff --git a/frontend/lib/main.dart b/frontend/lib/main.dartindex 452aacb344..0b50cce4a1 100644--- a/frontend/lib/main.dart+++ b/frontend/lib/main.dart@@ -99,8 +99,12 @@ class MyApp extends StatelessWidget {return MultiProvider(providers: [ChangeNotifierProvider(- create: (context) => ChatViewModel(- Provider.of<ChatService>(context, listen: false))),+ create: (context) => ChatViewModel(+ Provider.of<ChatService>(context, listen: false),+ Provider.of<SharedPreferencesService>(context,+ listen: false),+ ),+ ),ChangeNotifierProvider(create: (context) => TaskViewModel(Provider.of<TaskService>(context, listen: false),diff --git a/frontend/lib/viewmodels/chat_viewmodel.dart b/frontend/lib/viewmodels/chat_viewmodel.dartindex 3dfec1dee5..2056c8743a 100644--- a/frontend/lib/viewmodels/chat_viewmodel.dart+++ b/frontend/lib/viewmodels/chat_viewmodel.dart@@ -1,5 +1,6 @@import 'package:auto_gpt_flutter_client/models/step.dart';import 'package:auto_gpt_flutter_client/models/step_request_body.dart';+import 'package:auto_gpt_flutter_client/services/shared_preferences_service.dart';import 'package:flutter/foundation.dart';import 'package:auto_gpt_flutter_client/services/chat_service.dart';import 'package:auto_gpt_flutter_client/models/chat.dart';@@ -9,10 +10,12 @@ class ChatViewModel with ChangeNotifier {final ChatService _chatService;List<Chat> _chats = [];String? _currentTaskId;+ final SharedPreferencesService _prefsService;bool _isWaitingForAgentResponse = false;bool get isWaitingForAgentResponse => _isWaitingForAgentResponse;+ SharedPreferencesService get prefsService => _prefsService;bool _isContinuousMode = false;@@ -22,7 +25,7 @@ class ChatViewModel with ChangeNotifier {notifyListeners();}- ChatViewModel(this._chatService);+ ChatViewModel(this._chatService, this._prefsService);/// Returns the current list of chats.List<Chat> get chats => _chats;diff --git a/frontend/lib/viewmodels/task_viewmodel.dart b/frontend/lib/viewmodels/task_viewmodel.dartindex 94d8bf94d7..eca6554e79 100644--- a/frontend/lib/viewmodels/task_viewmodel.dart+++ b/frontend/lib/viewmodels/task_viewmodel.dart@@ -6,7 +6,6 @@ import 'package:flutter/foundation.dart';import 'package:collection/collection.dart';import 'package:auto_gpt_flutter_client/services/task_service.dart';import 'package:auto_gpt_flutter_client/models/task_request_body.dart';-import 'package:shared_preferences/shared_preferences.dart';// TODO: How will all these functions work with test suites?class TaskViewModel with ChangeNotifier {diff --git a/frontend/lib/views/chat/chat_input_field.dart b/frontend/lib/views/chat/chat_input_field.dartindex c3dc4601ef..b46badd618 100644--- a/frontend/lib/views/chat/chat_input_field.dart+++ b/frontend/lib/views/chat/chat_input_field.dart@@ -1,3 +1,4 @@+import 'package:auto_gpt_flutter_client/viewmodels/chat_viewmodel.dart';import 'package:auto_gpt_flutter_client/views/chat/continuous_mode_dialog.dart';import 'package:flutter/material.dart';import 'package:shared_preferences/shared_preferences.dart';@@ -7,12 +8,15 @@ class ChatInputField extends StatefulWidget {final Function(String) onSendPressed;final Function() onContinuousModePressed;final bool isContinuousMode;+ // TODO: Create a view model for this class and remove the ChatViewModel+ final ChatViewModel viewModel;const ChatInputField({Key? key,required this.onSendPressed,required this.onContinuousModePressed,this.isContinuousMode = false,+ required this.viewModel,}) : super(key: key);@override@@ -42,9 +46,10 @@ class _ChatInputFieldState extends State<ChatInputField> {}Future<void> _presentContinuousModeDialogIfNeeded() async {- final prefs = await SharedPreferences.getInstance();- final showContinuousModeDialog =- prefs.getBool('showContinuousModeDialog') ?? true;+ final showContinuousModeDialog = await widget.viewModel.prefsService+ .getBool('showContinuousModeDialog') ??+ true;+FocusScope.of(context).requestFocus(_throwawayFocusNode);if (showContinuousModeDialog) {showDialog(@@ -56,7 +61,8 @@ class _ChatInputFieldState extends State<ChatInputField> {_executeContinuousMode();},onCheckboxChanged: (bool value) async {- await prefs.setBool('showContinuousModeDialog', !value);+ await widget.viewModel.prefsService+ .setBool('showContinuousModeDialog', !value);},);},diff --git a/frontend/lib/views/chat/chat_view.dart b/frontend/lib/views/chat/chat_view.dartindex 5f2b35c25c..40117d9b02 100644--- a/frontend/lib/views/chat/chat_view.dart+++ b/frontend/lib/views/chat/chat_view.dart@@ -152,6 +152,7 @@ class _ChatViewState extends State<ChatView> {!widget.viewModel.isContinuousMode;},isContinuousMode: widget.viewModel.isContinuousMode,+ viewModel: widget.viewModel,),),],