gridDelegate static method

SliverGridDelegate? gridDelegate(
  1. DataSource source,
  2. List<Object> key
)

Returns a SliverGridDelegate from the specified map.

The type key specifies the kind of grid delegate.

A type of fixedCrossAxisCount creates a SliverGridDelegateWithFixedCrossAxisCount using the keys crossAxisCount, mainAxisSpacing, crossAxisSpacing, childAspectRatio, and mainAxisExtent.

A type of maxCrossAxisExtent creates a SliverGridDelegateWithMaxCrossAxisExtent using the keys maxCrossAxisExtent:, mainAxisSpacing, crossAxisSpacing, childAspectRatio, and mainAxisExtent`.

The types (int or double) and defaults for these keys match the identically named arguments to the default constructors of those classes.

If the type is none of these, but is not null, then the type is looked up in gridDelegateDecoders, and if an entry is found, this method defers to that callback.

Otherwise, returns null.

Implementation

static SliverGridDelegate? gridDelegate(DataSource source, List<Object> key) {
  final String? type = source.v<String>([...key, 'type']);
  switch (type) {
    case null:
      return null;
    case 'fixedCrossAxisCount':
      return SliverGridDelegateWithFixedCrossAxisCount(
        crossAxisCount: source.v<int>([...key, 'crossAxisCount']) ?? 2,
        mainAxisSpacing: source.v<double>([...key, 'mainAxisSpacing']) ?? 0.0,
        crossAxisSpacing: source.v<double>([...key, 'crossAxisSpacing']) ?? 0.0,
        childAspectRatio: source.v<double>([...key, 'childAspectRatio']) ?? 1.0,
        mainAxisExtent: source.v<double>([...key, 'mainAxisExtent']),
      );
    case 'maxCrossAxisExtent':
      return SliverGridDelegateWithMaxCrossAxisExtent(
        maxCrossAxisExtent: source.v<double>([...key, 'maxCrossAxisExtent']) ?? 100.0,
        mainAxisSpacing: source.v<double>([...key, 'mainAxisSpacing']) ?? 0.0,
        crossAxisSpacing: source.v<double>([...key, 'crossAxisSpacing']) ?? 0.0,
        childAspectRatio: source.v<double>([...key, 'childAspectRatio']) ?? 1.0,
        mainAxisExtent: source.v<double>([...key, 'mainAxisExtent']),
      );
    default:
      final ArgumentDecoder<SliverGridDelegate?>? decoder = gridDelegateDecoders[type];
      if (decoder == null) {
        return null;
      }
      return decoder(source, key);
  }
}