|
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/settings_viewmodel.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'; |
|
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/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 { |
|
final TaskViewModel viewModel; |
|
|
|
const TaskView({Key? key, required this.viewModel}) : super(key: key); |
|
|
|
@override |
|
_TaskViewState createState() => _TaskViewState(); |
|
} |
|
|
|
class _TaskViewState extends State<TaskView> { |
|
@override |
|
void initState() { |
|
super.initState(); |
|
|
|
|
|
WidgetsBinding.instance.addPostFrameCallback((_) { |
|
widget.viewModel.fetchAndCombineData(); |
|
}); |
|
} |
|
|
|
@override |
|
Widget build(BuildContext context) { |
|
|
|
final items = Provider.of<SettingsViewModel>(context, listen: false) |
|
.isDeveloperModeEnabled |
|
? widget.viewModel.combinedDataSource |
|
: widget.viewModel.tasksDataSource; |
|
return Scaffold( |
|
backgroundColor: Colors.white, |
|
body: Stack( |
|
children: [ |
|
Column( |
|
children: [ |
|
|
|
Padding( |
|
padding: const EdgeInsets.all(8.0), |
|
child: NewTaskButton( |
|
onPressed: () async { |
|
|
|
final chatViewModel = |
|
Provider.of<ChatViewModel>(context, listen: false); |
|
chatViewModel.clearCurrentTaskAndChats(); |
|
widget.viewModel.deselectTask(); |
|
print( |
|
'New Task button pressed, cleared current task ID and chats'); |
|
}, |
|
)), |
|
|
|
Expanded( |
|
child: ListView.builder( |
|
itemCount: items.length, |
|
itemBuilder: (context, index) { |
|
final item = items[index]; |
|
|
|
if (item is Task) { |
|
return TaskListTile( |
|
task: item, |
|
onTap: () { |
|
|
|
widget.viewModel.selectTask(item.id); |
|
|
|
|
|
|
|
final chatViewModel = Provider.of<ChatViewModel>( |
|
context, |
|
listen: false); |
|
chatViewModel.setCurrentTaskId(item.id); |
|
|
|
print('Task ${item.title} tapped'); |
|
}, |
|
onDelete: () { |
|
|
|
widget.viewModel.deleteTask(item.id); |
|
|
|
final chatViewModel = Provider.of<ChatViewModel>( |
|
context, |
|
listen: false); |
|
if (chatViewModel.currentTaskId == item.id) { |
|
chatViewModel.clearCurrentTaskAndChats(); |
|
} |
|
|
|
print('Task ${item.title} delete button tapped'); |
|
}, |
|
selected: item.id == widget.viewModel.selectedTask?.id, |
|
); |
|
} else if (item is TestSuite) { |
|
return TestSuiteListTile( |
|
testSuite: item, |
|
onTap: () { |
|
|
|
widget.viewModel.deselectTask(); |
|
widget.viewModel.selectTestSuite(item); |
|
|
|
Provider.of<ChatViewModel>(context, listen: false) |
|
.clearCurrentTaskAndChats(); |
|
}, |
|
); |
|
} else { |
|
return const SizedBox |
|
.shrink(); |
|
} |
|
}, |
|
), |
|
), |
|
], |
|
), |
|
if (widget.viewModel.selectedTestSuite != null) |
|
Positioned( |
|
top: 0, |
|
left: 0, |
|
right: 0, |
|
bottom: 0, |
|
child: TestSuiteDetailView( |
|
testSuite: widget.viewModel.selectedTestSuite!, |
|
viewModel: widget.viewModel, |
|
), |
|
), |
|
], |
|
), |
|
); |
|
} |
|
} |
|
|