Skip to content

Conversation

@bleroux
Copy link
Contributor

@bleroux bleroux commented May 23, 2022

Description

This PR fixes a null check error in PageView.

The null check was added by the following PR : #65015

Flutter 3.0 is the first stable release where the null check error surfaces.
It surfaces due to the following PR : #97971
which added a call to MediaQuery in SrollableState.didChangeDependencies (line 462) :

  @override
  void didChangeDependencies() {
    _mediaQueryData = MediaQuery.maybeOf(context);
    _updatePosition();
    super.didChangeDependencies();
  }

During startup, especially in release mode, MediaQuery.of(context).size might return (0,0). The size will be updated when the native platform reports the actual resolution (several milliseconds later). This seems to be by design for performance reasons (see #25827 (comment)).

For PageView, it means that the Viewport dimensions are updated during startup which was not expected with the previous code.

Related Issue

Fixes #101007

Tests

Adds 1 test.

@flutter-dashboard flutter-dashboard bot added the framework flutter/packages/flutter repository. See also f: labels. label May 23, 2022
@bleroux bleroux force-pushed the fix_page_view_null_check_error branch 3 times, most recently from f44c7cf to 531feee Compare May 24, 2022 06:52
@goderbauer goderbauer requested a review from Piinks May 25, 2022 21:39
Copy link
Contributor

@Piinks Piinks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thank you for fixing this! @xu-baolin WDYT?

@xu-baolin
Copy link
Member

xu-baolin commented Jun 8, 2022

Hey @Piinks this issue is similar to this #103328,
We should override absorb when the _PagePosition was replaced.

  @override
  void absorb(ScrollPosition other) {
    super.absorb(other);
    assert(_cachedPage == null);

    if (other is! _PagePosition) {
      return;
    }

    if (other._cachedPage != null) {
      _cachedPage = other._cachedPage;
      other._cachedPage = null;
    }
  }

Copy link
Member

@xu-baolin xu-baolin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See the comment above.

@bleroux bleroux force-pushed the fix_page_view_null_check_error branch from 531feee to d335c33 Compare June 8, 2022 08:47
@bleroux bleroux force-pushed the fix_page_view_null_check_error branch from d335c33 to b15311e Compare June 8, 2022 08:49
@bleroux bleroux requested a review from xu-baolin June 8, 2022 09:25
Copy link
Member

@xu-baolin xu-baolin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM,need a second review from @Piinks

@bleroux bleroux requested a review from Piinks June 8, 2022 12:17
Copy link
Contributor

@Piinks Piinks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah nice @xu-baolin! Thanks @bleroux, LGTM!

@Piinks Piinks added waiting for tree to go green f: scrolling Viewports, list views, slivers, etc. labels Jun 8, 2022
@fluttergithubbot fluttergithubbot merged commit 4dec56b into flutter:master Jun 8, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/plugins that referenced this pull request Jun 9, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 9, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 9, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 9, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/plugins that referenced this pull request Jun 9, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 10, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 10, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 10, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 11, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 11, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 12, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 12, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 13, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 13, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 14, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 14, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 14, 2022
@bleroux bleroux deleted the fix_page_view_null_check_error branch June 17, 2022 09:47
@armandojimenez
Copy link

armandojimenez commented Jul 11, 2022

Anyone knows when is this landing on stable branch?

idealclover added a commit to idealclover/Caritas-APP that referenced this pull request Jul 13, 2022
@ffamar
Copy link

ffamar commented Jul 15, 2022

The issue still exist in the flutter version 3.0.5.
Anyone knows when the patch will be released?

@alexaung
Copy link

Yes still happening in version 3.0.5

@bleroux
Copy link
Contributor Author

bleroux commented Jul 20, 2022

From https://github.com/flutter/flutter/wiki/Flutter-build-release-channels,
"Roughly once a quarter, a branch that has been stabilized on beta will become our next stable branch and we will create a stable release from that branch".

@antonshkurenko
Copy link

Is this expected to be fixed in 3.0.5 and it's an issue again or it wasn't included in 3.0.5?

@bleroux
Copy link
Contributor Author

bleroux commented Jul 21, 2022

@tonyshkurenko
It was not included in 3.0.5.
For the moment, this fix is available in the master channel and in the 3.3 beta channel.

camsim99 pushed a commit to camsim99/flutter that referenced this pull request Aug 10, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 30, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/plugins that referenced this pull request Aug 30, 2022
@ffamar
Copy link

ffamar commented Aug 31, 2022

I confirm, issue fixed in 3.3.0 release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

f: scrolling Viewports, list views, slivers, etc. framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PageView applyViewportDimension throws Null check operator used on a null value

8 participants