Refactor Settings and Task Views for API Base URL Management

- Deprecated `ApiSettingsViewModel` in favor of enhancing `SettingsViewModel`.
- Moved the API Base URL field from `TaskView` to `SettingsView` to centralize configuration.
- Integrated `RestApiUtility` dependency into `SettingsViewModel` to ensure consistent URL management across the app.
This commit is contained in:
hunteraraujo
2023-09-24 21:41:12 -07:00
parent ffa76c3a19
commit da8b9d58ac
6 changed files with 24 additions and 70 deletions

View File

@@ -1,16 +1,16 @@
import 'package:auto_gpt_flutter_client/viewmodels/settings_viewmodel.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:auto_gpt_flutter_client/viewmodels/api_settings_viewmodel.dart';
class ApiBaseUrlField extends StatelessWidget {
final TextEditingController controller;
const ApiBaseUrlField({required this.controller});
final TextEditingController controller = TextEditingController();
@override
Widget build(BuildContext context) {
return Consumer<ApiSettingsViewModel>(
builder: (context, apiSettingsViewModel, child) {
return Consumer<SettingsViewModel>(
builder: (context, settingsViewModel, child) {
// TODO: This view shouldn't know about the settings view model. It should use a delegate
controller.text = settingsViewModel.baseURL;
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 16),
child: Column(
@@ -39,8 +39,8 @@ class ApiBaseUrlField extends StatelessWidget {
children: [
ElevatedButton(
onPressed: () {
controller.text = 'http://127.0.0.1:8000/api/v1';
apiSettingsViewModel.updateBaseURL(controller.text);
controller.text = 'http://127.0.0.1:8000/ap/v1';
settingsViewModel.updateBaseURL(controller.text);
},
style: ElevatedButton.styleFrom(
backgroundColor: Colors.white,
@@ -53,7 +53,7 @@ class ApiBaseUrlField extends StatelessWidget {
),
ElevatedButton(
onPressed: () {
apiSettingsViewModel.updateBaseURL(controller.text);
settingsViewModel.updateBaseURL(controller.text);
},
style: ElevatedButton.styleFrom(
backgroundColor: Colors.white,

View File

@@ -1,4 +1,5 @@
import 'package:auto_gpt_flutter_client/viewmodels/settings_viewmodel.dart';
import 'package:auto_gpt_flutter_client/views/settings/api_base_url_field.dart';
import 'package:flutter/material.dart';
/// [SettingsView] displays a list of settings that the user can configure.
@@ -32,16 +33,7 @@ class SettingsView extends StatelessWidget {
onChanged: viewModel.toggleDeveloperMode,
),
// Base URL Configuration
ListTile(
title: const Text('Base URL'),
subtitle: TextFormField(
initialValue: viewModel.baseURL,
onChanged: viewModel.updateBaseURL,
decoration: const InputDecoration(
hintText: 'Enter Base URL',
),
),
),
ApiBaseUrlField(),
// Continuous Mode Steps Configuration
ListTile(
title: const Text('Continuous Mode Steps'),

View File

@@ -1,7 +1,5 @@
import 'package:auto_gpt_flutter_client/models/task.dart';
import 'package:auto_gpt_flutter_client/models/test_suite.dart';
import 'package:auto_gpt_flutter_client/viewmodels/api_settings_viewmodel.dart';
import 'package:auto_gpt_flutter_client/views/task/api_base_url_field.dart';
import 'package:auto_gpt_flutter_client/views/task/test_suite_detail_view.dart';
import 'package:auto_gpt_flutter_client/views/task/test_suite_list_tile.dart';
import 'package:flutter/material.dart';
@@ -21,8 +19,6 @@ class TaskView extends StatefulWidget {
}
class _TaskViewState extends State<TaskView> {
final TextEditingController _baseUrlController = TextEditingController();
@override
void initState() {
super.initState();
@@ -30,8 +26,6 @@ class _TaskViewState extends State<TaskView> {
// Schedule the fetchTasks call for after the initial build
WidgetsBinding.instance.addPostFrameCallback((_) {
widget.viewModel.fetchAndCombineData();
_baseUrlController.text =
Provider.of<ApiSettingsViewModel>(context, listen: false).baseURL;
});
}
@@ -116,9 +110,6 @@ class _TaskViewState extends State<TaskView> {
},
),
),
const SizedBox(height: 16),
ApiBaseUrlField(controller: _baseUrlController),
const SizedBox(height: 16),
],
),
if (widget.viewModel.selectedTestSuite != null)