fromDynamic static method

JsonInteractiveViewerBuilder? 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:

{
  "alignPanAxis": <bool>,
  "boundaryMargin": <EdgeInsets>,
  "clipBehavior": <Clip>,
  "constrained": <bool>,
  "maxScale": <double>,
  "minScale": <double>,
  "onInteractionEnd": <GestureScaleEndCallback>,
  "onInteractionStart": <GestureScaleStartCallback>,
  "onInteractionUpdate": <GestureScaleUpdateCallback>,
  "panEnabled": <bool>,
  "scaleEnabled": <bool>,
  "transformationController": <TransformationController>
}

As a note, the GestureScaleEndCallback, GestureScaleStartCallback, GestureScaleUpdateCallback, and TransformationController cannot be decoded via JSON. Instead, the only way to bind those values to the builder is to use a function or a variable reference via the JsonWidgetRegistry.

See also:

  • ThemeDecoder.decodeEdgeInsetsGeometry

Implementation

static JsonInteractiveViewerBuilder? fromDynamic(
  dynamic map, {
  JsonWidgetRegistry? registry,
}) {
  JsonInteractiveViewerBuilder? result;

  if (map != null) {
    result = JsonInteractiveViewerBuilder(
      alignPanAxis: map['alignPanAxis'] == null
          ? false
          : JsonClass.parseBool(
              map['alignPanAxis'],
            ),
      boundaryMargin: ThemeDecoder.decodeEdgeInsetsGeometry(
            map['boundaryMargin'],
            validate: false,
          ) as EdgeInsets? ??
          EdgeInsets.zero,
      clipBehavior: ThemeDecoder.decodeClip(
            map['clipBehavior'],
            validate: false,
          ) ??
          Clip.hardEdge,
      constrained: map['constrained'] == null
          ? true
          : JsonClass.parseBool(
              map['constrained'],
            ),
      maxScale: JsonClass.parseDouble(
        map['maxScale'],
        2.5,
      )!,
      minScale: JsonClass.parseDouble(
        map['minScale'],
        0.8,
      )!,
      onInteractionEnd: map['onInteractionEnd'],
      onInteractionStart: map['onInteractionStart'],
      onInteractionUpdate: map['onInteractionUpdate'],
      panEnabled: map['panEnabled'] == null
          ? true
          : JsonClass.parseBool(
              map['panEnabled'],
            ),
      scaleEnabled: map['scaleEnabled'] == null
          ? true
          : JsonClass.parseBool(
              map['scaleEnabled'],
            ),
      transformationController: map['transformationController'],
    );
  }

  return result;
}