From 3b710b3c7c50d41c7743d33280d7c36692b0616b Mon Sep 17 00:00:00 2001 From: hunteraraujo Date: Sat, 2 Sep 2023 15:06:23 -0700 Subject: [PATCH] Add TaskResponse model to encapsulate tasks and pagination data This commit introduces a new class called TaskResponse, which holds both the tasks and pagination information returned from the API. The class includes a factory constructor to create an instance from JSON data, ensuring that the API response is neatly packaged into an easily manageable object. This enhances code readability and maintainability. - Create a TaskResponse class with tasks and pagination fields - Add a factory constructor for JSON to TaskResponse conversion --- lib/models/task_response.dart | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 lib/models/task_response.dart diff --git a/lib/models/task_response.dart b/lib/models/task_response.dart new file mode 100644 index 00000000..9e1c18cc --- /dev/null +++ b/lib/models/task_response.dart @@ -0,0 +1,19 @@ +import 'package:auto_gpt_flutter_client/models/pagination.dart'; +import 'package:auto_gpt_flutter_client/models/task.dart'; + +class TaskResponse { + final List tasks; + final Pagination pagination; + + TaskResponse({required this.tasks, required this.pagination}); + + factory TaskResponse.fromJson(Map json) { + return TaskResponse( + tasks: (json['tasks'] as List).map((taskJson) { + var task = Task.fromMap(taskJson); + return task; + }).toList(), + pagination: Pagination.fromJson(json['pagination']), + ); + } +}