Skip to content

Factor out unnecessary asserts#182042

Merged
auto-submit[bot] merged 2 commits intoflutter:masterfrom
nate-thegrate:factor-out-asserts
Feb 25, 2026
Merged

Factor out unnecessary asserts#182042
auto-submit[bot] merged 2 commits intoflutter:masterfrom
nate-thegrate:factor-out-asserts

Conversation

@nate-thegrate
Copy link
Contributor

The conversation in #181703 got me thinking about whether there were any assert(value != null) statements in our codebase that were written prior to Dart's null safety era and could be factored out.

It turns out that there are!

This PR updates a few setters so that incorrect null assignments are caught by static analysis instead of potentially going unnoticed until runtime.

@github-actions github-actions bot added framework flutter/packages/flutter repository. See also f: labels. f: material design flutter/packages/flutter/material repository. f: cupertino flutter/packages/flutter/cupertino repository labels Feb 7, 2026
@nate-thegrate nate-thegrate marked this pull request as ready for review February 7, 2026 15:03
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request refactors several setters in CupertinoSwitch and MaterialSwitch to leverage Dart's null safety. By changing the parameter types from nullable to non-nullable, the unnecessary assert(value != null) checks are removed, and null-correctness is now enforced at compile time instead of runtime. The changes are correct and improve code quality and clarity.

@dkwingsmt dkwingsmt self-requested a review February 11, 2026 19:49
Copy link
Contributor

@dkwingsmt dkwingsmt 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 the cleanup!

@reidbaker reidbaker added the autosubmit Merge PR when tree becomes green via auto submit App label Feb 25, 2026
@auto-submit auto-submit bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Feb 25, 2026
@auto-submit
Copy link
Contributor

auto-submit bot commented Feb 25, 2026

autosubmit label was removed for flutter/flutter/182042, because The base commit of the PR is older than 7 days and can not be merged. Please merge the latest changes from the main into this branch and resubmit the PR.

Copy link
Member

@loic-sharma loic-sharma left a comment

Choose a reason for hiding this comment

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

Nice clean up, thanks!

@loic-sharma loic-sharma added the autosubmit Merge PR when tree becomes green via auto submit App label Feb 25, 2026
@auto-submit auto-submit bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Feb 25, 2026
@auto-submit
Copy link
Contributor

auto-submit bot commented Feb 25, 2026

autosubmit label was removed for flutter/flutter/182042, because - The status or check suite Google testing has failed. Please fix the issues identified (or deflake) before re-applying this label.

@loic-sharma
Copy link
Member

Google test failure looks like an infra flake, rerunning...

@loic-sharma loic-sharma added the autosubmit Merge PR when tree becomes green via auto submit App label Feb 25, 2026
@auto-submit auto-submit bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Feb 25, 2026
@auto-submit
Copy link
Contributor

auto-submit bot commented Feb 25, 2026

autosubmit label was removed for flutter/flutter/182042, because - The status or check suite Google testing has failed. Please fix the issues identified (or deflake) before re-applying this label.

@dkwingsmt dkwingsmt added the autosubmit Merge PR when tree becomes green via auto submit App label Feb 25, 2026
@auto-submit auto-submit bot added this pull request to the merge queue Feb 25, 2026
Merged via the queue into flutter:master with commit 5ef6f6b Feb 25, 2026
74 checks passed
@flutter-dashboard flutter-dashboard bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Feb 25, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 26, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 26, 2026
ahmedsameha1 pushed a commit to ahmedsameha1/flutter that referenced this pull request Feb 27, 2026
The conversation in flutter#181703 got me thinking about whether there were any
`assert(value != null)` statements in our codebase that were written
prior to Dart's null safety era and could be factored out.

It turns out that there are!

This PR updates a few setters so that incorrect `null` assignments are
caught by static analysis instead of potentially going unnoticed until
runtime.

Co-authored-by: Victor Sanni <[email protected]>
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 27, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 27, 2026
@nate-thegrate nate-thegrate deleted the factor-out-asserts branch March 4, 2026 03:27
xxxOVALxxx pushed a commit to xxxOVALxxx/flutter that referenced this pull request Mar 10, 2026
The conversation in flutter#181703 got me thinking about whether there were any
`assert(value != null)` statements in our codebase that were written
prior to Dart's null safety era and could be factored out.

It turns out that there are!

This PR updates a few setters so that incorrect `null` assignments are
caught by static analysis instead of potentially going unnoticed until
runtime.

Co-authored-by: Victor Sanni <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

f: cupertino flutter/packages/flutter/cupertino repository f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants