fromJson static method

PreviewCanvas? fromJson(
  1. Object? raw
)

Reads back what toJson wrote.

An id this build has no device for is dropped, not refused. This is read on the way to drawing something rather than while checking a command line, and the config is written against the flutterware the project pins — which can run ahead of the GUI reading its manifest. A device we cannot resolve has to mean a canvas with fewer devices, never a panel that will not open.

Implementation

static PreviewCanvas? fromJson(Object? raw) {
  if (raw is! Map) return null;
  var prefix = raw['prefix'];
  if (prefix is! String) return null;
  return PreviewCanvas(
    prefix,
    devices: [
      for (var id in (raw['devices'] as List? ?? const []))
        if (id is String) ?deviceById(id),
    ],
    orientations: [
      for (var name in (raw['orientations'] as List? ?? const []))
        if (name is String) ?orientationById(name),
    ],
    keyboards: [
      for (var name in (raw['keyboards'] as List? ?? const []))
        if (name is String) ?keyboardModeById(name),
    ],
  );
}