config property

  1. @override
Map<String, Object?> get config
override

Per-instance configuration, handed to the GUI-side implementation. Must be JSON-encodable — it crosses a process boundary.

Implementation

@override
Map<String, Object?> get config {
  for (var package in packages) {
    if (package.duplicateCanvasPrefix case var prefix?) {
      throw StateError(
        'Package "${package.path}" declares the canvas '
        '"${prefix.isEmpty ? '<the whole package>' : prefix}" twice. '
        'Longest prefix wins, so two canvases with one prefix are the same '
        'rule written twice. Put its devices in a single PreviewCanvas.',
      );
    }
    if (package.unknownDevice case var device?) {
      throw StateError(
        'Package "${package.path}" frames previews on the device '
        '"${device.id}", which is not one of `Devices`. A preview names its '
        'device by id, so this one would be dropped and its entries drawn '
        'on the plain $previewPanelWidth × $previewPanelHeight rectangle. '
        'Pick a device from `Devices`. For a size no device has, leave the '
        'canvas without devices and give the screenshot a width and a '
        'height.',
      );
    }
  }
  return {
    'packages': [for (var p in packages) p.toJson()],
  };
}