encodeScrollPhysics static method
Encodes the given value
to a JSON compatible Map.
This returns the JSON representation to follow the structure:
{
"parent": <ScrollPhysics>,
"type": <String>
}
Where "type" will be one of:
always
bouncing
clamping
fixedExtent
never
page
rangeMaintaining
Implementation
static Map<String, dynamic>? encodeScrollPhysics(ScrollPhysics? value) {
assert(value == null ||
value is AlwaysScrollableScrollPhysics ||
value is BouncingScrollPhysics ||
value is ClampingScrollPhysics ||
value is FixedExtentScrollPhysics ||
value is NeverScrollableScrollPhysics ||
value is PageScrollPhysics ||
value is RangeMaintainingScrollPhysics);
Map<String, dynamic>? result;
if (value != null) {
String? type;
if (value is AlwaysScrollableScrollPhysics) {
type = 'always';
} else if (value is BouncingScrollPhysics) {
type = 'bouncing';
} else if (value is ClampingScrollPhysics) {
type = 'clamping';
} else if (value is FixedExtentScrollPhysics) {
type = 'fixedExtent';
} else if (value is NeverScrollableScrollPhysics) {
type = 'never';
} else if (value is PageScrollPhysics) {
type = 'page';
} else if (value is RangeMaintainingScrollPhysics) {
type = 'rangeMaintaining';
}
if (type == null) {
throw Exception(
'Unknown ScrollPhysics class encounted: ${value.runtimeType}');
}
result = {
'parent': encodeScrollPhysics(value.parent),
'type': type,
};
}
return result;
}