fromDynamic static method

JsonSliverGridBuilder? 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>,
  "findChildIndexCallback": <ChildIndexGetter>,
  "gridDelegate": <SliverGridDelegate>,
  "semanticIndexCallback": <SemanticIndexCallback>,
  "semanticIndexOffset": <int>
}

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.

Implementation

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

  if (map != null) {
    result = JsonSliverGridBuilder(
      addAutomaticKeepAlives: JsonClass.parseBool(
        map['addAutomaticKeepAlives'],
        whenNull: true,
      ),
      addRepaintBoundaries: JsonClass.parseBool(
        map['addRepaintBoundaries'],
        whenNull: true,
      ),
      addSemanticIndexes: JsonClass.parseBool(
        map['addSemanticIndexes'],
        whenNull: true,
      ),
      findChildIndexCallback: map['findChildIndexCallback'],
      gridDelegate: map['gridDelegate'],
      semanticIndexCallback: map['semanticIndexCallback'],
      semanticIndexOffset:
          JsonClass.parseInt(map['semanticIndexOffset']) ?? 0,
    );
  }

  return result;
}