Skip to content

Conversation

@nate-thegrate
Copy link
Contributor

I previously made a PR (#136140) that used switch expressions to make some parts of the Flutter codebase easier to understand. It was assigned to the framework team, and @christopherfujino let me know that it was too large to effectively review and recommended breaking it up into smaller pull requests.

Here's a PR that only targets files in the dev/ directory. Hopefully this will be easier to work with!

(solves issue #136139)

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.

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@github-actions github-actions bot added a: animation Animation APIs f: material design flutter/packages/flutter/material repository. f: scrolling Viewports, list views, slivers, etc. labels Nov 27, 2023
case TestScenario.resampleOff59Hz:
return false;
}
return switch (currentValue) {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit while you're at it, you can make this an arrow function:

  bool get resample => switch (currentValue) {
    TestScenario.resampleOn90Hz || TestScenario.resampleOn59Hz => true,
    TestScenario.resampleOff90Hz || TestScenario.resampleOff59Hz => false,
  };

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, that looks even better!

But it might be good to keep it as-is to follow the style guide.

only use => when everything, including the function declaration, fits on a single line.

Copy link
Contributor

@christopherfujino christopherfujino Nov 27, 2023

Choose a reason for hiding this comment

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

the next rule is a further exception for list and map literals, and which I would argue switch expressions should be added: https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo#use--for-inline-callbacks-that-just-return-literals-or-switch-expressions

(edited by @andrewkolos to fix the link)

Copy link
Contributor

@andrewkolos andrewkolos Nov 28, 2023

Choose a reason for hiding this comment

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

@christopherfujino The rule seems ambiguous to me. Consider this from the body of the rule:

then rather than using braces and a return` [sic.] statement, you can instead use the ⇒ form

The use of "can" in body of the rule makes the rule sound optional. However, the title makes this seems non-optional. Given this, I won't be retracting my approval on this PR despite me just learning about this rule.

Copy link
Contributor

@christopherfujino christopherfujino 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, this is a nice readability improvement! The nit about migrating the getters with only one statement to be arrow functions is completely optional, this looks ready to merge as far as I'm concerned.

Copy link
Contributor

@andrewkolos andrewkolos left a comment

Choose a reason for hiding this comment

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

LGTM

@nate-thegrate
Copy link
Contributor Author

It looks like in order to merge this PR, I need to add the "autosubmit" label, but it also looks like I don't have permission to do that. 🫤

@christopherfujino christopherfujino added the autosubmit Merge PR when tree becomes green via auto submit App label Nov 28, 2023
@auto-submit auto-submit bot merged commit 3267fbc into flutter:master Nov 28, 2023
@nate-thegrate nate-thegrate deleted the switch-expressions-1 branch November 29, 2023 00:07
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Nov 29, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Nov 29, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Nov 29, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Nov 29, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Nov 29, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Nov 29, 2023
auto-submit bot pushed a commit to flutter/packages that referenced this pull request Nov 29, 2023
Roll Flutter from 6bf3ccd to 5e5b529 (58 revisions)

flutter/flutter@6bf3ccd...5e5b529

2023-11-29 [email protected] Roll Flutter Engine from 60b963930202 to 222beb28a8eb (2 revisions) (flutter/flutter#139242)
2023-11-29 [email protected] Roll Flutter Engine from eebbe7e15c7d to 60b963930202 (2 revisions) (flutter/flutter#139237)
2023-11-29 [email protected] Roll Packages from 3c05466 to e4aaba8 (5 revisions) (flutter/flutter#139232)
2023-11-29 [email protected] Update VelocityTracker (4) (flutter/flutter#139166)
2023-11-29 [email protected] Analyze against using Stopwatches in the framework (flutter/flutter#138507)
2023-11-29 [email protected] Roll Flutter Engine from ecc9c7b6be7d to eebbe7e15c7d (1 revision) (flutter/flutter#139225)
2023-11-29 [email protected] Roll Flutter Engine from 28aae2d29822 to ecc9c7b6be7d (1 revision) (flutter/flutter#139210)
2023-11-29 [email protected] Improve documentation of CardTheme.shape (flutter/flutter#139096)
2023-11-29 [email protected] Simplify devicelab logic and fix tests (flutter/flutter#139122)
2023-11-29 [email protected] implemented leadingWidth and automaticallyImplyLeading options  (flutter/flutter#136165)
2023-11-29 [email protected] TextField and TextFormField can use a MaterialStatesController (flutter/flutter#133977)
2023-11-29 [email protected] Provide parameter to Icon and IconThemeData for they to consider the context's text scaler (flutter/flutter#135708)
2023-11-29 [email protected] Roll Flutter Engine from be4d7c8b760c to 28aae2d29822 (1 revision) (flutter/flutter#139204)
2023-11-29 [email protected] Update `ButtonStyleButton.scaledPadding` documentation. Migrate callers in flutter/flutter (flutter/flutter#139014)
2023-11-29 [email protected] Roll Flutter Engine from de99c71c598f to be4d7c8b760c (1 revision) (flutter/flutter#139199)
2023-11-29 [email protected] Roll Flutter Engine from 9a840e8dba40 to de99c71c598f (2 revisions) (flutter/flutter#139195)
2023-11-29 [email protected] Roll Flutter Engine from fbb2b1e880fa to 9a840e8dba40 (1 revision) (flutter/flutter#139192)
2023-11-29 [email protected] Roll Flutter Engine from 4beaa1195b74 to fbb2b1e880fa (1 revision) (flutter/flutter#139191)
2023-11-29 [email protected] Roll Flutter Engine from 570fec4fa92c to 4beaa1195b74 (3 revisions) (flutter/flutter#139190)
2023-11-29 98614782+auto-submit[bot]@users.noreply.github.com Reverts "Reland Add platform view wide gamut test" (flutter/flutter#139189)
2023-11-28 [email protected] Move analysis test to shard tests. (flutter/flutter#139161)
2023-11-28 [email protected] Write Tests for API Examples of `snack_bar.0`, `elevated_button.0`, `stepper.0`, `radio.0`, `filled_button.0`, `outlined_button.0` & `card.0` (flutter/flutter#138987)
2023-11-28 [email protected] Implement `switch` expressions in `dev/` (flutter/flutter#139048)
2023-11-28 [email protected] Roll Flutter Engine from 01fcec7214db to 570fec4fa92c (2 revisions) (flutter/flutter#139178)
2023-11-28 [email protected] Fix comment (flutter/flutter#138973)
2023-11-28 [email protected] Added some documentation for OverlayPortal (flutter/flutter#138934)
2023-11-28 [email protected] feature(table-widget): Added intrinsicHeight to TableCellVerticalAlignment enum. (flutter/flutter#130264)
2023-11-28 [email protected] Roll Flutter Engine from 97ede154dcd8 to 01fcec7214db (1 revision) (flutter/flutter#139172)
2023-11-28 [email protected] Ensure Icon vertically centers its icon glyph. (flutter/flutter#138937)
2023-11-28 [email protected] Roll Flutter Engine from fd3a33f8b239 to 97ede154dcd8 (2 revisions) (flutter/flutter#139168)
2023-11-28 [email protected] Roll Flutter Engine from d375d5b95d59 to fd3a33f8b239 (2 revisions) (flutter/flutter#139163)
2023-11-28 [email protected] Roll Flutter Engine from e4b18fa3661e to d375d5b95d59 (2 revisions) (flutter/flutter#139157)
2023-11-28 [email protected] Added keyboardType & textInputAction props to SearchBar, SearchAnchor & SearchAnchor.bar (flutter/flutter#138553)
2023-11-28 [email protected] Fix header formatting typo in PopupMenuButton docs (flutter/flutter#139084)
2023-11-28 [email protected] Fix turbulence seed for all tests with ink sparkles (flutter/flutter#138757)
2023-11-28 [email protected] Renable macOS 13 tests (flutter/flutter#139083)
2023-11-28 [email protected] Roll Flutter Engine from 8715e9b9119d to e4b18fa3661e (1 revision) (flutter/flutter#139142)
2023-11-28 [email protected] Roll Packages from e774e88 to 3c05466 (2 revisions) (flutter/flutter#139140)
2023-11-28 [email protected] Roll Flutter Engine from 6ad827e9a71b to 8715e9b9119d (1 revision) (flutter/flutter#139136)
2023-11-28 [email protected] Roll Flutter Engine from c18d3df967dc to 6ad827e9a71b (1 revision) (flutter/flutter#139135)
2023-11-28 [email protected] Roll Flutter Engine from 1caa7478db0d to c18d3df967dc (1 revision) (flutter/flutter#139133)
2023-11-28 [email protected] Roll Flutter Engine from 4f217e1f9afe to 1caa7478db0d (1 revision) (flutter/flutter#139129)
2023-11-28 [email protected] Fix textScalerOf and maybeTextScalerOf documentations (flutter/flutter#139123)
2023-11-28 [email protected] Roll Flutter Engine from c25cc65720de to 4f217e1f9afe (1 revision) (flutter/flutter#139126)
2023-11-28 [email protected] Roll Flutter Engine from 3381d3ff0df7 to c25cc65720de (1 revision) (flutter/flutter#139121)
2023-11-28 [email protected] Roll Flutter Engine from 96137d05fabc to 3381d3ff0df7 (4 revisions) (flutter/flutter#139119)
...
auto-submit bot pushed a commit that referenced this pull request Dec 11, 2023
Thanks so much for approving the previous PR (#139048) a couple weeks ago!

This one is the same, except it's covering files in `examples/` and `packages/flutter/lib/src/animation/`.

(solving issue #136139)
caseycrogers pushed a commit to caseycrogers/flutter that referenced this pull request Dec 29, 2023
I previously made a PR (flutter#136140) that used `switch` expressions to make some parts of the Flutter codebase easier to understand. It was assigned to the framework team, and @christopherfujino let me know that it was too large to effectively review and recommended breaking it up into smaller pull requests.

Here's a PR that only targets files in the `dev/` directory. Hopefully this will be easier to work with!

(solves issue flutter#136139)
auto-submit bot pushed a commit that referenced this pull request Jan 29, 2024
…142279)

This PR is the fourth step in the journey to solve issue #136139 and make the entire Flutter repo more readable.

(previous pull requests: #139048, #139882, #141591)

This one is covering files in `packages/flutter/lib/src/foundation/` and `packages/flutter/lib/src/material/`.  
The `material/` directory is pretty big though, so for now I just did the files that start with `a`, `b`, and `c`.
auto-submit bot pushed a commit that referenced this pull request Feb 1, 2024
This PR is step 5 in the journey to solve issue #136139 and make the entire Flutter repo more readable.

(previous pull requests: #139048, #139882, #141591, #142279)

The current focus is on `packages/flutter/lib/src/material/`.  
The previous PR covered files in this directory starting with `a`, `b`, and `c`; this pull request is for `d` through `m`.
auto-submit bot pushed a commit that referenced this pull request Feb 9, 2024
This PR is the 6�ʰ step in the journey to solve issue #136139 and make the entire Flutter repo more readable.

(previous pull requests: #139048, #139882, #141591, #142279, #142634)

The current focus is on `packages/flutter/lib/src/material/`. The previous 2 PRs covered files in this directory starting with letters `a-m`; this one takes care of everything else.
auto-submit bot pushed a commit that referenced this pull request Feb 13, 2024
This PR is the 7�ʰ step in the journey to solve issue #136139 and make the entire Flutter repo more readable.

(previous pull requests: #139048, #139882, #141591, #142279, #142634, #142793)

This pull request covers everything in `packages/flutter/lib/src/widgets/`. Most of it should be really straightforward, but there was some refactoring in the `getOffsetToReveal()` function in `two_dimensional_viewport.dart`. I'll add some comments to describe those changes.
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 16, 2024
auto-submit bot pushed a commit that referenced this pull request Feb 16, 2024
…143496)

This PR is the 8�ʰ step in the journey to solve issue #136139 and make the entire Flutter repo more readable.

(previous pull requests: #139048, #139882, #141591, #142279, #142634, #142793, #143293)

I did a pass through all of `packages/flutter/lib/src/` and found a whole bunch of `switch` statements to improve: most of them were really simple, but many involved some thorough refactoring.

This pull request is just the complicated stuff. � I'll make comments to describe the changes, and then in the future there will be another PR (and it'll be much easier to review than this one).
auto-submit bot pushed a commit that referenced this pull request Feb 20, 2024
…143634)

This PR is the 9�ʰ step in the journey to solve issue #136139 and make the entire Flutter repo more readable.

(previous pull requests: #139048, #139882, #141591, #142279, #142634, #142793, #143293, #143496)

I did a pass through all of `packages/flutter/lib/src/` and found an abundance of `switch` statements to improve. Whereas #143496 focused on in-depth refactoring, this PR is full of simple, straightforward changes. (I ended up making some more complicated changes in `rendering/` and will file those separately after this PR is done.)
auto-submit bot pushed a commit that referenced this pull request Mar 29, 2024
This pull request is step 12 in the journey to make this entire repository more readable.

(previous PRs: #139048, #139882, #141591, #142279, #142634, #142793, #143293, #143496, #143634, #143812, #144580)

We're getting close to the end! �
@nate-thegrate nate-thegrate added the refactor Improving readability/efficiency without behavioral changes label Jul 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

a: animation Animation APIs autosubmit Merge PR when tree becomes green via auto submit App f: material design flutter/packages/flutter/material repository. f: scrolling Viewports, list views, slivers, etc. refactor Improving readability/efficiency without behavioral changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants