gridDelegate static method
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 Map<String, dynamic>? gridDelegate(SliverGridDelegate? delegate) {
if (delegate == null) return null;
if (delegate is SliverGridDelegateWithFixedCrossAxisCount) {
return NotNullMap.from({
'type': 'fixedCrossAxisCount',
'crossAxisCount': delegate.crossAxisCount,
'mainAxisSpacing': delegate.mainAxisSpacing,
'crossAxisSpacing': delegate.crossAxisSpacing,
'childAspectRatio': delegate.childAspectRatio,
'mainAxisExtent': delegate.mainAxisExtent
});
} else if (delegate is SliverGridDelegateWithMaxCrossAxisExtent) {
return NotNullMap.from({
'type': 'maxCrossAxisExtent',
'maxCrossAxisExtent': delegate.maxCrossAxisExtent,
'mainAxisSpacing': delegate.mainAxisSpacing,
'crossAxisSpacing': delegate.crossAxisSpacing,
'childAspectRatio': delegate.childAspectRatio,
'mainAxisExtent': delegate.mainAxisExtent
});
}
final encoder = gridDelegateEncoders[delegate.runtimeType];
if (encoder == null) return null;
return encoder(delegate);
}