fromJson static method

StackRun? fromJson(
  1. Object? raw
)

Reads back what toJson wrote, or null for a shape this build cannot read.

A bare list is accepted too: that is what start, stop and a command were before this class existed, and a project pinning an older flutterware still writes one.

Implementation

static StackRun? fromJson(Object? raw) {
  if (raw is List) {
    var command = [for (var arg in raw) '$arg'];
    return command.isEmpty ? null : CommandRun(command);
  }
  if (raw is! Map) return null;
  if (raw['script'] case String path) {
    return ScriptRun(
      path,
      args: [
        for (var arg in (raw['args'] as List? ?? const []))
          if (arg is String) arg,
      ],
    );
  }
  if (raw['command'] case List raw) {
    var command = [for (var arg in raw) '$arg'];
    return command.isEmpty ? null : CommandRun(command);
  }
  return null;
}