copyWith method

  1. @override
InfiniteExtentMetrics copyWith({
  1. double? minScrollExtent,
  2. double? maxScrollExtent,
  3. double? pixels,
  4. double? viewportDimension,
  5. AxisDirection? axisDirection,
  6. double? devicePixelRatio,
  7. int? itemIndex,
})
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
InfiniteExtentMetrics copyWith({
  double? minScrollExtent,
  double? maxScrollExtent,
  double? pixels,
  double? viewportDimension,
  AxisDirection? axisDirection,
  double? devicePixelRatio,
  int? itemIndex,
}) {
  return InfiniteExtentMetrics(
    // 解决 Null check operator used on a null value
    minScrollExtent: minScrollExtent ??
        (hasContentDimensions ? this.minScrollExtent : 0.0),
    maxScrollExtent: maxScrollExtent ?? this.maxScrollExtent,
    pixels: pixels ?? this.pixels,
    viewportDimension: viewportDimension ?? this.viewportDimension,
    axisDirection: axisDirection ?? this.axisDirection,
    devicePixelRatio: devicePixelRatio ?? this.devicePixelRatio,
    itemIndex: itemIndex ?? this.itemIndex,
  );
}