Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

flutter/lib/src/: refactoring if-chains into switch expressions #147472

Merged
merged 10 commits into from May 1, 2024

Conversation

nate-thegrate
Copy link
Member

Based on issue #144903, this pull request aims to bring the codebase more in line with the Flutter repo style guide:

Avoid using if chains or ?: or == with enum values


// before
bool get shown {
  if (overlayEntry == null) {
    return false;
  }
  if (animationController != null) {
    return animationController!.status == AnimationStatus.completed ||
        animationController!.status == AnimationStatus.forward;
  }
  return true;
}


// after
bool get shown {
  return overlayEntry != null && switch (animationController?.status) {
    AnimationStatus.forward || AnimationStatus.completed || null => true,
    AnimationStatus.reverse || AnimationStatus.dismissed => false,
  };
}

This pull request is similar to a previous PR with the same name but has a bit more thorough refactoring overall.

@github-actions github-actions bot added a: text input Entering text in a text field or keyboard related problems framework flutter/packages/flutter repository. See also f: labels. a: animation Animation APIs f: material design flutter/packages/flutter/material repository. 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 Apr 27, 2024
@nate-thegrate nate-thegrate marked this pull request as ready for review April 27, 2024 23:23
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

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 👍 Thanks for cleaning up the code as always.

@nate-thegrate Are you interested in getting contributor access by the way? I'd be happy to sponsor you. See https://github.com/flutter/flutter/wiki/Contributor-access.

@@ -1444,7 +1437,7 @@ class _SearchBarState extends State<SearchBar> {
),
),
),
if (trailing != null) ...trailing,
...?trailing,
Copy link
Contributor

Choose a reason for hiding this comment

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

I didn't realize that was a thing 👍

@justinmc justinmc merged commit 586e1fc into flutter:master May 1, 2024
72 checks passed
@nate-thegrate nate-thegrate deleted the lib-src-if-chains branch May 2, 2024 00:55
@nate-thegrate
Copy link
Member Author

@nate-thegrate Are you interested in getting contributor access by the way? I'd be happy to sponsor you.

@justinmc That would be awesome, thank you very much!

engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 2, 2024
auto-submit bot pushed a commit to flutter/packages that referenced this pull request May 2, 2024
Roll Flutter from d33bb8fa5eb8 to bf7191fd3884 (34 revisions)

flutter/flutter@d33bb8f...bf7191f

2024-05-02 engine-flutter-autoroll@skia.org Roll Flutter Engine from b989d239e281 to 1fb36ac9d718 (2 revisions) (flutter/flutter#147713)
2024-05-02 engine-flutter-autoroll@skia.org Roll Flutter Engine from 3c9c2ce8369e to b989d239e281 (1 revision) (flutter/flutter#147711)
2024-05-02 engine-flutter-autoroll@skia.org Roll Flutter Engine from 58b031c096ea to 3c9c2ce8369e (2 revisions) (flutter/flutter#147703)
2024-05-02 engine-flutter-autoroll@skia.org Roll Flutter Engine from fc28057dbd4d to 58b031c096ea (1 revision) (flutter/flutter#147701)
2024-05-02 engine-flutter-autoroll@skia.org Roll Flutter Engine from bfc6787eedc3 to fc28057dbd4d (1 revision) (flutter/flutter#147700)
2024-05-02 engine-flutter-autoroll@skia.org Roll Flutter Engine from 7cbef71f4f54 to bfc6787eedc3 (1 revision) (flutter/flutter#147699)
2024-05-02 engine-flutter-autoroll@skia.org Roll Flutter Engine from 90ce9e5959fc to 7cbef71f4f54 (1 revision) (flutter/flutter#147696)
2024-05-02 engine-flutter-autoroll@skia.org Roll Flutter Engine from 78dced50c467 to 90ce9e5959fc (1 revision) (flutter/flutter#147695)
2024-05-02 andrewrkolos@gmail.com add verbose logging to select hot reload/hot restart tests (flutter/flutter#147673)
2024-05-02 engine-flutter-autoroll@skia.org Roll Flutter Engine from 3087ec1adddd to 78dced50c467 (3 revisions) (flutter/flutter#147693)
2024-05-02 98614782+auto-submit[bot]@users.noreply.github.com Reverts "Implement computeDryBaseline for `RenderWrap` (#146260)" (flutter/flutter#147692)
2024-05-02 engine-flutter-autoroll@skia.org Roll Flutter Engine from f56c20c6ac67 to 3087ec1adddd (2 revisions) (flutter/flutter#147688)
2024-05-02 gspencergoog@users.noreply.github.com Allow explicit exclusion of packages from pinned packages in `flutter update-packages --force-update` (flutter/flutter#147679)
2024-05-02 31859944+LongCatIsLooong@users.noreply.github.com Implement getDryBaseline for Stack and Overlay (flutter/flutter#146253)
2024-05-02 engine-flutter-autoroll@skia.org Roll Flutter Engine from 2d73fa207927 to f56c20c6ac67 (2 revisions) (flutter/flutter#147681)
2024-05-02 polinach@google.com Update selectable_text_test.dart (flutter/flutter#147677)
2024-05-01 engine-flutter-autoroll@skia.org Roll Flutter Engine from c536a14052e5 to 2d73fa207927 (2 revisions) (flutter/flutter#147678)
2024-05-01 31859944+LongCatIsLooong@users.noreply.github.com Implement computeDryBaseline for `RenderWrap` (flutter/flutter#146260)
2024-05-01 engine-flutter-autoroll@skia.org Roll Flutter Engine from 842cf254ec58 to c536a14052e5 (1 revision) (flutter/flutter#147675)
2024-05-01 49699333+dependabot[bot]@users.noreply.github.com Bump codecov/codecov-action from 4.3.0 to 4.3.1 (flutter/flutter#147674)
2024-05-01 ian@hixie.ch Remove obsolete performance analysis tools. (flutter/flutter#147663)
2024-05-01 engine-flutter-autoroll@skia.org Roll Flutter Engine from 5129b4919434 to 842cf254ec58 (3 revisions) (flutter/flutter#147670)
2024-05-01 120297255+PurplePolyhedron@users.noreply.github.com fix DropdownMenu overflow (flutter/flutter#147233)
2024-05-01 yjbanov@google.com [web] remove platform_messages_integration test (flutter/flutter#147654)
2024-05-01 rmolivares@renzo-olivares.dev Fix `TextField` horizontal drag conflicts (flutter/flutter#147341)
2024-05-01 nate.w5687@gmail.com `flutter/lib/src/`: refactoring if-chains into switch expressions (flutter/flutter#147472)
2024-05-01 98614782+auto-submit[bot]@users.noreply.github.com Reverts "Draggable feedback positioning (#145647)" (flutter/flutter#147658)
2024-05-01 engine-flutter-autoroll@skia.org Roll Flutter Engine from 0014e0353aa9 to 5129b4919434 (1 revision) (flutter/flutter#147655)
2024-05-01 yjbanov@google.com add lang attribute to the a11y_assessments app (flutter/flutter#147586)
2024-05-01 hi@timcreated.it Draggable feedback positioning (flutter/flutter#145647)
2024-05-01 engine-flutter-autoroll@skia.org Roll Flutter Engine from 0ce67714ce4c to 0014e0353aa9 (13 revisions) (flutter/flutter#147649)
2024-05-01 sokolovskyi.konstantin@gmail.com Add test for animated_fractionally_sized_box.0.dart API example. (flutter/flutter#146721)
2024-05-01 engine-flutter-autoroll@skia.org Roll Packages from cc47b06 to aea93d2 (5 revisions) (flutter/flutter#147647)
2024-05-01 73608287+ellet0@users.noreply.github.com Update reorderable_list.dart to use Dart 3 return switch statement for consistency (flutter/flutter#147505)

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 dit@google.com,rmistry@google.com,stuartmorgan@google.com 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

...
nate-thegrate added a commit that referenced this pull request May 10, 2024
Previous "if-chains" pull requests:
- #144905
- #144977
- #145194
- #146293
- #147472

<br>

I think this one should be enough to wrap things up!

fixes #144903

---------

Co-authored-by: Victor Sanni <victorsanniay@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a: animation Animation APIs a: text input Entering text in a text field or keyboard related problems 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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants