Skip to content

Remove nullOk in MediaQuery.of - #68736

Merged
gspencergoog merged 3 commits into
flutter:masterfrom
gspencergoog:remove_null_ok
Oct 28, 2020
Merged

gspencergoog merged 3 commits into
flutter:masterfrom
gspencergoog:remove_null_ok

Conversation

@gspencergoog

@gspencergoog gspencergoog commented Oct 21, 2020 •

Copy link
Copy Markdown
Contributor

Description

Adds MediaQuery.maybeOf to replace calling MediaQuery.of(context, nullOk: true), and removes the nullOk parameter. Also changes MediaQuery.of to return a non-nullable value, and removes many instances of the ! operator, reducing the possible places where a null dereference could occur.

Related Issues

Tests

  • No tests were harmed in the making of this PR.
  • Added a test to make sure that maybeOf works as expected, updated test output for media_query_test.dart and others.

Breaking Change

  • Yes, this is a breaking change that will require a migration guide.

@flutter-dashboard flutter-dashboard Bot added p: cupertino_ui cupertino_ui package in flutter/packages p: material_ui material_ui package in flutter/packages framework flutter/packages/flutter repository. See also f: labels. work in progress; do not review labels Oct 21, 2020
@google-cla google-cla Bot added the cla: yes label Oct 21, 2020
@gspencergoog gspencergoog changed the title Remove null ok Deprecate/disable nullOk in MediaQuery.of Oct 21, 2020
@gspencergoog
gspencergoog force-pushed the remove_null_ok branch 3 times, most recently from a3f89ee to 08827b6 Compare October 21, 2020 20:46
@gspencergoog
gspencergoog marked this pull request as ready for review October 21, 2020 21:15

@goderbauer goderbauer left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Changes LGTM. Since this is failing google3 I would argue that this is a breaking change, though, and we should probably publish a quick migration guide.

@gspencergoog

Copy link
Copy Markdown
Contributor Author

I agree, I'll work on the guide.

@goderbauer

Copy link
Copy Markdown
Member

@bwilkerson This would be another great use case for a flutter fix that automatically migrates user code.

@gspencergoog

Copy link
Copy Markdown
Contributor Author

Here's the design doc for the migration.

Writing the migration guide itself next.

@gspencergoog
gspencergoog force-pushed the remove_null_ok branch 2 times, most recently from 9745730 to 46010dd Compare October 23, 2020 17:30
@gspencergoog

Copy link
Copy Markdown
Contributor Author

OK, I just removed the nullOk entirely, since I don't like the fact that we're avoiding a compile time check in order to fail at runtime: that's a much more error-prone failure mode, and will definitely surprise people: I'd rather it just fail to compile.

@Hixie

Hixie commented Oct 24, 2020

Copy link
Copy Markdown
Contributor

It's a pity we lose the analyzer warning that way.

@gspencergoog gspencergoog changed the title Deprecate/disable nullOk in MediaQuery.of Remove nullOk in MediaQuery.of Oct 27, 2020
@flutter-dashboard flutter-dashboard Bot added d: examples Sample code and demos c: contributor-productivity Team-specific productivity, code health, technical debt. labels Oct 27, 2020

@goderbauer goderbauer left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@gspencergoog

gspencergoog commented Oct 27, 2020 •

Copy link
Copy Markdown
Contributor Author

@Hixie Well, we lose the analyzer warning, but gain a compiler error. I agree, is a pity that there's no way to say "Fail to compile, but give a custom message like a deprecation" for when someone uses a removed parameter.

Hopefully the docs at the site are clear enough that they'll understand what to do when they get the compiler error.

@Hixie

Hixie commented Oct 27, 2020

Copy link
Copy Markdown
Contributor

Might be worth following up with @leafpetersen to see if we can change Dart in some way in the future to make this kind of thing better.

@gspencergoog

Copy link
Copy Markdown
Contributor Author

OK, I submitted dart-lang/sdk#43942 as a feature request.

@fluttergithubbot

Copy link
Copy Markdown
Contributor

This pull request is not suitable for automatic merging in its current state.

  • The status or check suite Mac framework_tests has failed. Please fix the issues identified (or deflake) before re-applying this label.

@fluttergithubbot

Copy link
Copy Markdown
Contributor

This pull request is not suitable for automatic merging in its current state.

  • The status or check suite Mac framework_tests has failed. Please fix the issues identified (or deflake) before re-applying this label.

@gspencergoog
gspencergoog merged commit 5528932 into flutter:master Oct 28, 2020
josh-burton added a commit to josh-burton/flutter_device_preview that referenced this pull request Nov 3, 2020
This constructor has been replaced by a new MediaQuery.maybeOf() constructor.

flutter/flutter#68736
@gspencergoog
gspencergoog deleted the remove_null_ok branch October 7, 2022 22:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c: contributor-productivity Team-specific productivity, code health, technical debt. d: examples Sample code and demos framework flutter/packages/flutter repository. See also f: labels. p: cupertino_ui cupertino_ui package in flutter/packages p: material_ui material_ui package in flutter/packages

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants