fromDynamic static method

JsonSetWidgetBuilder? fromDynamic(
  1. dynamic map, {
  2. JsonWidgetRegistry? registry,
})

Builds the builder from a Map-like dynamic structure. This expects the JSON format to be of the following structure:

{
  "<key>": "<JsonWidgetData>"
}

Where the key is any arbitrary String. That key will be used as the key on JsonWidgetRegistry.setValue and the JsonWidgetData value will be used as the value.

See also:

Implementation

static JsonSetWidgetBuilder? fromDynamic(
  dynamic map, {
  JsonWidgetRegistry? registry,
}) {
  JsonSetWidgetBuilder? result;
  final innerRegistry = registry ?? JsonWidgetRegistry.instance;

  if (map != null) {
    final widgets = <String, JsonWidgetData?>{};
    map.forEach(
      (key, value) => widgets[key] = JsonWidgetData.fromDynamic(value),
    );

    result = JsonSetWidgetBuilder(widgets: widgets);
    registry ??= JsonWidgetRegistry.instance;
    result.widgets?.forEach(
      (key, value) => innerRegistry.setValue(
        key,
        value,
        originator: null,
      ),
    );
  }

  return result;
}