fromDynamic static method

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

{
  "addAutomaticKeepAlives": "<bool>",
  "addRepaintBoundaries": "<bool>",
  "addSemanticIndexes": "<bool>",
  "cacheExtent": "<double>",
  "clipBehavior": "<Clip>",
  "controller": "<ScrollController>",
  "dragStartBehavior": "<DragStartBehavior>",
  "findChildIndexCallback": "<ChildIndexGetter>",
  "gridDelegate": "<SliverGridDelegate>",
  "keyboardDismissBehavior": "<ScrollViewKeyboardDismissBehavior>",
  "padding": "<EdgeInsetsGeometry>",
  "physics": "<ScrollPhysics>",
  "primary": "<bool>",
  "prototypeItem": "<JsonWidgetData>",
  "restorationId": "<String>",
  "reverse": "<bool>",
  "scrollDirection": "<Axis>",
  "shrinkWrap": "<bool>"
}

As a note, the ScrollController 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.

The "gridDelegate" can be passed in via a variable or it can be decoded using one of the two schemas:

{
  "type": "max_cross_axis_extent",
  "childAspectRatio": "<double?>",
  "crossAxisSpacing": "<double?>",
  "mainAxisExtent": "<double?>",
  "mainAxisSpacing": "<double?>",
  "maxCrossAxisExtent": "<double>"
}

... or ...

{
  "type": "fixed_cross_axis_count",
  "crossAxisCount": "<int>",
  "childAspectRatio": "<double?>",
  "crossAxisSpacing": "<double?>",
  "mainAxisExtent": "<double?>",
  "mainAxisSpacing": "<double?>"
}

See also:

  • ThemeDecoder.decodeAxis
  • ThemeDecoder.decodeClip
  • ThemeDecoder.decodeDragStartBehavior
  • ThemeDecoder.decodeEdgeInsetsGeometry
  • ThemeDecoder.decodeScrollPhysics

Implementation

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

  if (map != null) {
    result = JsonGridViewBuilder(
      addAutomaticKeepAlives: map['addAutomaticKeepAlives'] == null
          ? true
          : JsonClass.parseBool(map['addAutomaticKeepAlives']),
      addRepaintBoundaries: map['addRepaintBoundaries'] == null
          ? true
          : JsonClass.parseBool(map['addRepaintBoundaries']),
      addSemanticIndexes: map['addSemanticIndexes'] == null
          ? true
          : JsonClass.parseBool(map['addSemanticIndexes']),
      cacheExtent: JsonClass.maybeParseDouble(map['cacheExtent']),
      clipBehavior: ThemeDecoder.decodeClip(
            map['clipBehavior'],
            validate: false,
          ) ??
          Clip.hardEdge,
      controller: map['controller'],
      dragStartBehavior: ThemeDecoder.decodeDragStartBehavior(
            map['dragStartBehavior'],
            validate: false,
          ) ??
          DragStartBehavior.start,
      findChildIndexCallback: map['findChildIndexCallback'],
      gridDelegate: map['gridDelegate'],
      keyboardDismissBehavior:
          ThemeDecoder.decodeScrollViewKeyboardDismissBehavior(
                map['keyboardDismissBehavior'],
                validate: false,
              ) ??
              ScrollViewKeyboardDismissBehavior.manual,
      padding: ThemeDecoder.decodeEdgeInsetsGeometry(
        map['padding'],
        validate: false,
      ) as EdgeInsets?,
      physics: ThemeDecoder.decodeScrollPhysics(
        map['physics'],
        validate: false,
      ),
      primary: JsonClass.parseBool(map['primary']),
      restorationId: map['restorationId'],
      reverse: JsonClass.parseBool(map['reverse']),
      scrollDirection: ThemeDecoder.decodeAxis(
            map['scrollDirection'],
            validate: false,
          ) ??
          Axis.vertical,
      shrinkWrap: JsonClass.parseBool(map['shrinkWrap']),
    );
  }

  return result;
}