beginActivity method Null safety

void beginActivity(
  1. ScrollActivity? newActivity
)

Change the current activity, disposing of the old one and sending scroll notifications as necessary.

If the argument is null, this method has no effect. This is convenient for cases where the new activity is obtained from another method, and that method might return null, since it means the caller does not have to explicitly null-check the argument.

Implementation

void beginActivity(ScrollActivity? newActivity) {
  if (newActivity == null) {
    return;
  }
  bool wasScrolling, oldIgnorePointer;
  if (_activity != null) {
    oldIgnorePointer = _activity!.shouldIgnorePointer;
    wasScrolling = _activity!.isScrolling;
    if (wasScrolling && !newActivity.isScrolling) {
      // Notifies and then saves the scroll offset.
      didEndScroll();
    }
    _activity!.dispose();
  } else {
    oldIgnorePointer = false;
    wasScrolling = false;
  }
  _activity = newActivity;
  if (oldIgnorePointer != activity!.shouldIgnorePointer) {
    context.setIgnorePointer(activity!.shouldIgnorePointer);
  }
  isScrollingNotifier.value = activity!.isScrolling;
  if (!wasScrolling && _activity!.isScrolling) {
    didStartScroll();
  }
}