Skip to content

Conversation

@nate-thegrate
Copy link
Contributor

This pull request fixes #143803 by taking advantage of Dart's null-aware operators.

And unlike switch expressions (9 PRs and counting), the Flutter codebase is already fantastic when it comes to null-aware coding. After refactoring the entire repo, all the changes involving ?. and ?? can fit into a single pull request.

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the Flutter Style Guide, including Features we expect every widget to implement.
  • I signed the CLA.
  • I listed at least one issue that this PR fixes in the description above.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or this PR is test-exempt.
  • All existing and new tests are passing.

@github-actions github-actions bot added a: tests "flutter test", flutter_test, or one of our tests a: text input Entering text in a text field or keyboard related problems platform-ios iOS applications specifically tool Affects the "flutter" command-line tool. See also t: labels. framework flutter/packages/flutter repository. See also f: labels. f: material design flutter/packages/flutter/material repository. a: accessibility Accessibility, e.g. VoiceOver or TalkBack. (aka a11y) f: scrolling Viewports, list views, slivers, etc. f: cupertino flutter/packages/flutter/cupertino repository f: routes Navigator, Router, and related APIs. f: gestures flutter/packages/flutter/gestures repository. labels Feb 21, 2024
@nate-thegrate nate-thegrate marked this pull request as ready for review February 21, 2024 02:36
Copy link
Contributor

@justinmc justinmc left a comment

Choose a reason for hiding this comment

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

LGTM 👍. 200+ lines saved! Thanks for all of these code migrations. Out of curiosity are you using scripts or regexes or something to help do this?

return box.size.width;
}
return _kWidth; // drawer not being shown currently
// set to _kWidth if drawer not being shown currently
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: "Return _kWidth if drawer not being shown currently."


return rootProject.android.getEmbeddingVersion().toString().split('.').last;
})();
late final String? _androidEmbeddingVersion = _rootProject?.android.getEmbeddingVersion().toString().split('.').last;
Copy link
Contributor

Choose a reason for hiding this comment

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

I really wonder why this was done in a self calling function in the first place... Maybe just to limit the scope of the variables?

@nate-thegrate
Copy link
Contributor Author

LGTM 👍. 200+ lines saved! Thanks for all of these code migrations. Out of curiosity are you using scripts or regexes or something to help do this?

Thanks very much! I've just been using VS Code's built-in regex search to look for potential stuff to improve.
For this PR it was == null or != null with something being assigned or returned in the next line.

@justinmc
Copy link
Contributor

Ah got it. Maybe at some point we can add analyzer/lint rules for stuff like this.

Copy link
Member

@goderbauer goderbauer left a comment

Choose a reason for hiding this comment

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

LGTM

@goderbauer goderbauer added the autosubmit Merge PR when tree becomes green via auto submit App label Feb 23, 2024
@auto-submit auto-submit bot merged commit c53a18f into flutter:master Feb 23, 2024
@nate-thegrate nate-thegrate deleted the null-aware-operators branch February 23, 2024 19:03
@Juliotati
Copy link

BEAUTIFUL

engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 24, 2024
auto-submit bot pushed a commit to flutter/packages that referenced this pull request Feb 24, 2024
flutter/flutter@39585e6...f6c1082

2024-02-24 [email protected] Roll Flutter Engine from 81035b7d56ef to 1d7d5e613d7e (1 revision) (flutter/flutter#144085)
2024-02-24 [email protected] Roll Flutter Engine from a148bdb63740 to 81035b7d56ef (2 revisions) (flutter/flutter#144083)
2024-02-24 [email protected] Roll Flutter Engine from 3c036c081534 to a148bdb63740 (1 revision) (flutter/flutter#144077)
2024-02-24 [email protected] Roll Flutter Engine from 738042295f97 to 3c036c081534 (2 revisions) (flutter/flutter#144073)
2024-02-24 [email protected] Roll Flutter Engine from ca2452074a49 to 738042295f97 (4 revisions) (flutter/flutter#144071)
2024-02-24 [email protected] Roll Flutter Engine from 9409b75e8f35 to ca2452074a49 (2 revisions) (flutter/flutter#144068)
2024-02-24 [email protected] Adding support for DDC modules when running Flutter Web in debug mode (flutter/flutter#141423)
2024-02-24 [email protected] Roll Flutter Engine from 733163c4e5d7 to 9409b75e8f35 (1 revision) (flutter/flutter#144061)
2024-02-23 [email protected] allow optional direct injection of Config instance into DevFS (flutter/flutter#144002)
2024-02-23 [email protected] Enable asset transformation for `flutter build` for iOS, Android, Windows, MacOS, Linux, and web (also `flutter run` without hot reload support) (flutter/flutter#143815)
2024-02-23 [email protected] Roll Flutter Engine from 5d1c0d4dc327 to 733163c4e5d7 (1 revision) (flutter/flutter#144058)
2024-02-23 49699333+dependabot[bot]@users.noreply.github.com Bump github/codeql-action from 3.24.4 to 3.24.5 (flutter/flutter#144059)
2024-02-23 49699333+dependabot[bot]@users.noreply.github.com Bump codecov/codecov-action from 4.0.1 to 4.0.2 (flutter/flutter#144060)
2024-02-23 [email protected] Render the warm up frame in a proper rendering process (flutter/flutter#143290)
2024-02-23 [email protected] Roll Flutter Engine from fbc9b889aee9 to 5d1c0d4dc327 (2 revisions) (flutter/flutter#144049)
2024-02-23 [email protected] Roll Flutter Engine from b5bebfe43d29 to fbc9b889aee9 (3 revisions) (flutter/flutter#144041)
2024-02-23 [email protected] disable debug banner in m3 page test apps. (flutter/flutter#143857)
2024-02-23 [email protected] Relands "Changing `TextPainter.getOffsetForCaret` implementation to remove the logarithmic search (#143281)" (reverted in #143801) (flutter/flutter#143954)
2024-02-23 [email protected] Roll Flutter Engine from 5f99a6c3289e to b5bebfe43d29 (1 revision) (flutter/flutter#144035)
2024-02-23 [email protected] Implementing null-aware operators throughout the repository (flutter/flutter#143804)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages
Please CC [email protected],[email protected],[email protected] on the revert to ensure that a human
is aware of the problem.

To file a bug in Packages: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
LouiseHsu pushed a commit to LouiseHsu/packages that referenced this pull request Mar 7, 2024
flutter/flutter@39585e6...f6c1082

2024-02-24 [email protected] Roll Flutter Engine from 81035b7d56ef to 1d7d5e613d7e (1 revision) (flutter/flutter#144085)
2024-02-24 [email protected] Roll Flutter Engine from a148bdb63740 to 81035b7d56ef (2 revisions) (flutter/flutter#144083)
2024-02-24 [email protected] Roll Flutter Engine from 3c036c081534 to a148bdb63740 (1 revision) (flutter/flutter#144077)
2024-02-24 [email protected] Roll Flutter Engine from 738042295f97 to 3c036c081534 (2 revisions) (flutter/flutter#144073)
2024-02-24 [email protected] Roll Flutter Engine from ca2452074a49 to 738042295f97 (4 revisions) (flutter/flutter#144071)
2024-02-24 [email protected] Roll Flutter Engine from 9409b75e8f35 to ca2452074a49 (2 revisions) (flutter/flutter#144068)
2024-02-24 [email protected] Adding support for DDC modules when running Flutter Web in debug mode (flutter/flutter#141423)
2024-02-24 [email protected] Roll Flutter Engine from 733163c4e5d7 to 9409b75e8f35 (1 revision) (flutter/flutter#144061)
2024-02-23 [email protected] allow optional direct injection of Config instance into DevFS (flutter/flutter#144002)
2024-02-23 [email protected] Enable asset transformation for `flutter build` for iOS, Android, Windows, MacOS, Linux, and web (also `flutter run` without hot reload support) (flutter/flutter#143815)
2024-02-23 [email protected] Roll Flutter Engine from 5d1c0d4dc327 to 733163c4e5d7 (1 revision) (flutter/flutter#144058)
2024-02-23 49699333+dependabot[bot]@users.noreply.github.com Bump github/codeql-action from 3.24.4 to 3.24.5 (flutter/flutter#144059)
2024-02-23 49699333+dependabot[bot]@users.noreply.github.com Bump codecov/codecov-action from 4.0.1 to 4.0.2 (flutter/flutter#144060)
2024-02-23 [email protected] Render the warm up frame in a proper rendering process (flutter/flutter#143290)
2024-02-23 [email protected] Roll Flutter Engine from fbc9b889aee9 to 5d1c0d4dc327 (2 revisions) (flutter/flutter#144049)
2024-02-23 [email protected] Roll Flutter Engine from b5bebfe43d29 to fbc9b889aee9 (3 revisions) (flutter/flutter#144041)
2024-02-23 [email protected] disable debug banner in m3 page test apps. (flutter/flutter#143857)
2024-02-23 [email protected] Relands "Changing `TextPainter.getOffsetForCaret` implementation to remove the logarithmic search (#143281)" (reverted in #143801) (flutter/flutter#143954)
2024-02-23 [email protected] Roll Flutter Engine from 5f99a6c3289e to b5bebfe43d29 (1 revision) (flutter/flutter#144035)
2024-02-23 [email protected] Implementing null-aware operators throughout the repository (flutter/flutter#143804)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages
Please CC [email protected],[email protected],[email protected] on the revert to ensure that a human
is aware of the problem.

To file a bug in Packages: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 14, 2024
@nate-thegrate nate-thegrate added the refactor Improving readability/efficiency without behavioral changes label Jul 12, 2024
auto-submit bot pushed a commit that referenced this pull request Jul 31, 2024
Hopefully soon, [flutter.dev/go/dart-patterns](https://flutter.dev/go/dart-patterns) will have lots of good feedback; in the meantime, I'll focus refactoring efforts on uncontroversial things :)

Previously, I was under the impression that I could solve issue #143803 with [just 1 PR](#143804).
It turns out that I had overlooked quite a bit!

<br>

```dart
// before
if (chunkEvents != null) {
  chunkEvents.listen((ImageChunkEvent event) {
      reportImageChunkEvent(event);
    },
  );
}

// after
chunkEvents?.listen(reportImageChunkEvent);
```
TytaniumDev pushed a commit to TytaniumDev/flutter that referenced this pull request Aug 7, 2024
Hopefully soon, [flutter.dev/go/dart-patterns](https://flutter.dev/go/dart-patterns) will have lots of good feedback; in the meantime, I'll focus refactoring efforts on uncontroversial things :)

Previously, I was under the impression that I could solve issue flutter#143803 with [just 1 PR](flutter#143804).
It turns out that I had overlooked quite a bit!

<br>

```dart
// before
if (chunkEvents != null) {
  chunkEvents.listen((ImageChunkEvent event) {
      reportImageChunkEvent(event);
    },
  );
}

// after
chunkEvents?.listen(reportImageChunkEvent);
```
Buchimi pushed a commit to Buchimi/flutter that referenced this pull request Sep 2, 2024
Hopefully soon, [flutter.dev/go/dart-patterns](https://flutter.dev/go/dart-patterns) will have lots of good feedback; in the meantime, I'll focus refactoring efforts on uncontroversial things :)

Previously, I was under the impression that I could solve issue flutter#143803 with [just 1 PR](flutter#143804).
It turns out that I had overlooked quite a bit!

<br>

```dart
// before
if (chunkEvents != null) {
  chunkEvents.listen((ImageChunkEvent event) {
      reportImageChunkEvent(event);
    },
  );
}

// after
chunkEvents?.listen(reportImageChunkEvent);
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

a: accessibility Accessibility, e.g. VoiceOver or TalkBack. (aka a11y) a: tests "flutter test", flutter_test, or one of our tests a: text input Entering text in a text field or keyboard related problems autosubmit Merge PR when tree becomes green via auto submit App f: cupertino flutter/packages/flutter/cupertino repository f: gestures flutter/packages/flutter/gestures repository. f: material design flutter/packages/flutter/material repository. f: routes Navigator, Router, and related APIs. f: scrolling Viewports, list views, slivers, etc. framework flutter/packages/flutter repository. See also f: labels. platform-ios iOS applications specifically refactor Improving readability/efficiency without behavioral changes tool Affects the "flutter" command-line tool. See also t: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Proposal to implement null-aware operators (?. and ??) throughout the repo

4 participants