copyWith method

  1. @override
FixedExtentMetrics copyWith(
  1. {double? minScrollExtent,
  2. double? maxScrollExtent,
  3. double? pixels,
  4. double? viewportDimension,
  5. AxisDirection? axisDirection,
  6. int? itemIndex,
  7. double? devicePixelRatio}
)
override

Creates a ScrollMetrics that has the same properties as this object.

This is useful if this object is mutable, but you want to get a snapshot of the current state.

The named arguments allow the values to be adjusted in the process. This is useful to examine hypothetical situations, for example "would applying this delta unmodified take the position outOfRange?".

Implementation

@override
FixedExtentMetrics copyWith({
  double? minScrollExtent,
  double? maxScrollExtent,
  double? pixels,
  double? viewportDimension,
  AxisDirection? axisDirection,
  int? itemIndex,
  double? devicePixelRatio,
}) {
  return FixedExtentMetrics(
    minScrollExtent: minScrollExtent ?? (hasContentDimensions ? this.minScrollExtent : null),
    maxScrollExtent: maxScrollExtent ?? (hasContentDimensions ? this.maxScrollExtent : null),
    pixels: pixels ?? (hasPixels ? this.pixels : null),
    viewportDimension: viewportDimension ?? (hasViewportDimension ? this.viewportDimension : null),
    axisDirection: axisDirection ?? this.axisDirection,
    itemIndex: itemIndex ?? this.itemIndex,
    devicePixelRatio: devicePixelRatio ?? this.devicePixelRatio,
  );
}