mirror of
https://github.com/aljazceru/Auto-GPT.git
synced 2025-12-17 22:14:28 +01:00
Refactor ChatInputField to use SharedPreferencesService
This commit is contained in:
@@ -100,7 +100,11 @@ class MyApp extends StatelessWidget {
|
||||
providers: [
|
||||
ChangeNotifierProvider(
|
||||
create: (context) => ChatViewModel(
|
||||
Provider.of<ChatService>(context, listen: false))),
|
||||
Provider.of<ChatService>(context, listen: false),
|
||||
Provider.of<SharedPreferencesService>(context,
|
||||
listen: false),
|
||||
),
|
||||
),
|
||||
ChangeNotifierProvider(
|
||||
create: (context) => TaskViewModel(
|
||||
Provider.of<TaskService>(context, listen: false),
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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);
|
||||
},
|
||||
);
|
||||
},
|
||||
|
||||
@@ -152,6 +152,7 @@ class _ChatViewState extends State<ChatView> {
|
||||
!widget.viewModel.isContinuousMode;
|
||||
},
|
||||
isContinuousMode: widget.viewModel.isContinuousMode,
|
||||
viewModel: widget.viewModel,
|
||||
),
|
||||
),
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user