From ed03a32bc3a75785be21a8b1e2dc6ad942ad1bf0 Mon Sep 17 00:00:00 2001 From: hunteraraujo Date: Thu, 31 Aug 2023 14:56:32 -0700 Subject: [PATCH] Create Step Class to Model Step Information This commit introduces the Step class to the codebase, designed to model the steps related to tasks. - Implemented Step class with both required and optional fields. - Provided a fromMap factory method for easy deserialization from API responses. - Ensured that optional fields are handled gracefully, providing default values where necessary. The addition of the Step class lays the foundation for more complex interactions with tasks, including the ability to handle steps with varying levels of information. This makes the application more flexible and robust when interfacing with the backend. --- lib/models/step.dart | 49 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 lib/models/step.dart diff --git a/lib/models/step.dart b/lib/models/step.dart new file mode 100644 index 00000000..21b7e47c --- /dev/null +++ b/lib/models/step.dart @@ -0,0 +1,49 @@ +// TODO: Refactor this to match which values are required and optional +class Step { + final String input; + final Map additionalInput; + final String taskId; + final String stepId; + final String name; + final String status; + final String output; + final Map additionalOutput; + final List artifacts; + final bool isLast; + + Step({ + required this.input, + required this.additionalInput, + required this.taskId, + required this.stepId, + required this.name, + required this.status, + required this.output, + required this.additionalOutput, + required this.artifacts, + required this.isLast, + }); + + factory Step.fromMap(Map? map) { + if (map == null) { + throw ArgumentError('Null map provided to Step.fromMap'); + } + return Step( + input: map['input'] ?? '', + additionalInput: map['additional_input'] != null + ? Map.from(map['additional_input']) + : {}, + taskId: map['task_id'] ?? '', + stepId: map['step_id'] ?? '', + name: map['name'] ?? '', + status: map['status'] ?? '', + output: map['output'] ?? '', + additionalOutput: map['additional_output'] != null + ? Map.from(map['additional_output']) + : {}, + artifacts: + map['artifacts'] != null ? List.from(map['artifacts']) : [], + isLast: map['is_last'] ?? false, + ); + } +}