From bf60feaa7e9aa2391af95e10ae425533b7a1586f Mon Sep 17 00:00:00 2001 From: hunteraraujo Date: Sat, 2 Sep 2023 20:34:40 -0700 Subject: [PATCH] Refactor TaskView to Include API Base URL Field - Added ApiBaseUrlField widget to the TaskView. - Included a TextEditingController to manage the API base URL value. - Initialized the text field with the current base URL value from ApiSettingsViewModel. - Modified the layout to place the API base URL field and associated buttons below the task list. The commit introduces a user interface enhancement that allows the user to update the API base URL directly from the TaskView. This ensures better configurability and user experience. --- lib/views/task/task_view.dart | 47 +++++++++++++++++------------------ 1 file changed, 23 insertions(+), 24 deletions(-) diff --git a/lib/views/task/task_view.dart b/lib/views/task/task_view.dart index f93c6eda..0f34bf1a 100644 --- a/lib/views/task/task_view.dart +++ b/lib/views/task/task_view.dart @@ -1,8 +1,10 @@ -import 'package:auto_gpt_flutter_client/viewmodels/chat_viewmodel.dart'; -import 'package:auto_gpt_flutter_client/views/task/new_task_button.dart'; -import 'package:auto_gpt_flutter_client/views/task/task_list_tile.dart'; +import 'package:auto_gpt_flutter_client/views/task/api_base_url_field.dart'; import 'package:flutter/material.dart'; import 'package:auto_gpt_flutter_client/viewmodels/task_viewmodel.dart'; +import 'package:auto_gpt_flutter_client/viewmodels/chat_viewmodel.dart'; +import 'package:auto_gpt_flutter_client/viewmodels/api_settings_viewmodel.dart'; +import 'package:auto_gpt_flutter_client/views/task/new_task_button.dart'; +import 'package:auto_gpt_flutter_client/views/task/task_list_tile.dart'; import 'package:provider/provider.dart'; class TaskView extends StatefulWidget { @@ -15,6 +17,8 @@ class TaskView extends StatefulWidget { } class _TaskViewState extends State { + final TextEditingController _baseUrlController = TextEditingController(); + @override void initState() { super.initState(); @@ -22,6 +26,8 @@ class _TaskViewState extends State { // Schedule the fetchTasks call for after the initial build WidgetsBinding.instance.addPostFrameCallback((_) { widget.viewModel.fetchTasks(); + _baseUrlController.text = + Provider.of(context, listen: false).baseURL; }); } @@ -33,27 +39,17 @@ class _TaskViewState extends State { children: [ // Title and New Task button Padding( - padding: const EdgeInsets.all(8.0), - child: Column( - children: [ - const Text( - 'Tasks', - style: TextStyle(fontSize: 20, fontWeight: FontWeight.normal), - ), - const SizedBox(height: 8), - NewTaskButton( - onPressed: () async { - // Update the current task ID and chats in ChatViewModel - final chatViewModel = - Provider.of(context, listen: false); - chatViewModel.clearCurrentTaskAndChats(); - print( - 'New Task button pressed, cleared current task ID and chats'); - }, - ) - ], - ), - ), + padding: const EdgeInsets.all(8.0), + child: NewTaskButton( + onPressed: () async { + // Update the current task ID and chats in ChatViewModel + final chatViewModel = + Provider.of(context, listen: false); + chatViewModel.clearCurrentTaskAndChats(); + print( + 'New Task button pressed, cleared current task ID and chats'); + }, + )), // Task List Expanded( child: ListView.builder( @@ -90,6 +86,9 @@ class _TaskViewState extends State { }, ), ), + const SizedBox(height: 16), + ApiBaseUrlField(controller: _baseUrlController), + const SizedBox(height: 16), ], ), );