fromDynamic static method

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

{
  "animateColor: "<bool>",
  "animateShadowColor: "<bool>",
  "borderRadius: "<BorderRadius>",
  "clipBehavior: "<Clip>",
  "color": "<Color>",
  "curve": "<Curve>",
  "duration": "<int; millis>",
  "elevation": "<double>",
  "onEnd": "<VoidCallback>",
  "shadowColor": "<Color>",
  "shape": "<BoxShape>"
}

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.\

See also:

  • ThemeDecoder.decodeBoxShape

Implementation

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

  if (map != null) {
    result = JsonAnimatedPhysicalModelBuilder(
      animateColor: JsonClass.parseBool(
        map['animateColor'] ?? true,
      ),
      animateShadowColor: JsonClass.parseBool(
        map['animateShadowColor'] ?? true,
      ),
      borderRadius: ThemeDecoder.decodeBorderRadius(
            map['borderRadius'],
            validate: false,
          ) ??
          BorderRadius.zero,
      clipBehavior: ThemeDecoder.decodeClip(
            map['clipBehavior'],
            validate: false,
          ) ??
          Clip.none,
      color: ThemeDecoder.decodeColor(
        map['color'],
        validate: false,
      )!,
      curve: map['curve'] ?? Curves.linear,
      duration: JsonClass.maybeParseDurationFromMillis(
        map['duration'],
      )!,
      elevation: JsonClass.maybeParseDouble(
        map['elevation'],
      )!,
      onEnd: map['onEnd'],
      shadowColor: ThemeDecoder.decodeColor(
        map['shadowColor'],
        validate: false,
      )!,
      shape: ThemeDecoder.decodeBoxShape(
        map['shape'],
        validate: false,
      )!,
    );
  }

  return result;
}