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,75 +0,0 @@
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});
@override
Widget build(BuildContext context) {
return Consumer<ApiSettingsViewModel>(
builder: (context, apiSettingsViewModel, child) {
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 16),
child: Column(
children: [
Container(
height: 50,
decoration: BoxDecoration(
color: Colors.white,
border: Border.all(color: Colors.black, width: 0.5),
borderRadius: BorderRadius.circular(8),
),
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 8),
child: TextField(
controller: controller,
decoration: const InputDecoration(
border: InputBorder.none,
hintText: 'API Base URL',
),
),
),
),
const SizedBox(height: 16),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
ElevatedButton(
onPressed: () {
controller.text = 'http://127.0.0.1:8000/api/v1';
apiSettingsViewModel.updateBaseURL(controller.text);
},
style: ElevatedButton.styleFrom(
backgroundColor: Colors.white,
foregroundColor: Colors.black,
textStyle: const TextStyle(
color: Colors.black,
),
),
child: const Text("Reset"),
),
ElevatedButton(
onPressed: () {
apiSettingsViewModel.updateBaseURL(controller.text);
},
style: ElevatedButton.styleFrom(
backgroundColor: Colors.white,
foregroundColor: Colors.black,
textStyle: const TextStyle(
color: Colors.black,
),
),
child: const Text("Update"),
),
],
),
],
),
);
},
);
}
}

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)