ScrollPositionWithSingleContext constructor

ScrollPositionWithSingleContext(
  1. {required ScrollPhysics physics,
  2. required ScrollContext context,
  3. double? initialPixels = 0.0,
  4. bool keepScrollOffset = true,
  5. ScrollPosition? oldPosition,
  6. String? debugLabel}
)

Create a ScrollPosition object that manages its behavior using ScrollActivity objects.

The initialPixels argument can be null, but in that case it is imperative that the value be set, using correctPixels, as soon as applyNewDimensions is invoked, before calling the inherited implementation of that method.

If keepScrollOffset is true (the default), the current scroll offset is saved with PageStorage and restored it if this scroll position's scrollable is recreated.

Implementation

ScrollPositionWithSingleContext({
  required super.physics,
  required super.context,
  double? initialPixels = 0.0,
  super.keepScrollOffset,
  super.oldPosition,
  super.debugLabel,
}) {
  // If oldPosition is not null, the superclass will first call absorb(),
  // which may set _pixels and _activity.
  if (!hasPixels && initialPixels != null) {
    correctPixels(initialPixels);
  }
  if (activity == null) {
    goIdle();
  }
  assert(activity != null);
}