fromDynamic static method

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

{
  "alignment: "<AlignmentGeometry>",
  "clipBehavior": "<Clip>",
  "color": "<Color>",
  "constraints": "<BoxConstraints>",
  "curve": "<Curve>",
  "decoration": "<BoxDecoration>",
  "duration": "<int; millis>",
  "foregroundDecoration": "<BoxDecoration>",
  "height: "<double>",
  "margin": "<EdgeInsetsGeometry>",
  "onEnd": "<VoidCallback>",
  "padding": "<EdgeInsetsGeometry>",
  "transform": "<Matrix4>",
  "transformAlignment": "<TransformAlignment>",
  "width": "<double>"
}

As a note, the Curve and VoidCallback 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.

Implementation

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

  if (map != null) {
    result = JsonAnimatedContainerBuilder(
      alignment: ThemeDecoder.decodeAlignment(
        map['alignment'],
        validate: false,
      ),
      clipBehavior: ThemeDecoder.decodeClip(
            map['clipBehavior'],
            validate: false,
          ) ??
          Clip.none,
      color: ThemeDecoder.decodeColor(
        map['color'],
        validate: false,
      ),
      constraints: ThemeDecoder.decodeBoxConstraints(
        map['constraints'],
        validate: false,
      ),
      curve: map['curve'] ?? Curves.linear,
      decoration: ThemeDecoder.decodeBoxDecoration(
        map['decoration'],
        validate: false,
      ),
      duration: JsonClass.maybeParseDurationFromMillis(
        map['duration'],
      )!,
      foregroundDecoration: ThemeDecoder.decodeBoxDecoration(
        map['foregroundDecoration'],
        validate: false,
      ),
      height: JsonClass.maybeParseDouble(map['height']),
      margin: ThemeDecoder.decodeEdgeInsetsGeometry(
        map['margin'],
        validate: false,
      ),
      onEnd: map['onEnd'],
      padding: ThemeDecoder.decodeEdgeInsetsGeometry(
        map['padding'],
        validate: false,
      ),
      transform: ThemeDecoder.decodeMatrix4(
        map['transform'],
        validate: false,
      ),
      transformAlignment: ThemeDecoder.decodeAlignment(
        map['transformAlignment'],
        validate: false,
      ),
      width: JsonClass.maybeParseDouble(map['width']),
    );
  }

  return result;
}