Skip to content

Conversation

@nate-thegrate
Copy link
Contributor

This pull request is part of the effort to solve issue #136139.

The previous switch expressions PR was comprised of many simple changes throughout flutter/lib/src/, but due to some more in-depth refactoring in flutter/lib/src/rendering/, I decided to submit the changes to this directory as a separate pull request.

There was really just one function that I changed significantly; I'll add a comment for explanation.

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 framework flutter/packages/flutter repository. See also f: labels. f: scrolling Viewports, list views, slivers, etc. labels Feb 21, 2024
@nate-thegrate nate-thegrate marked this pull request as ready for review February 21, 2024 03:21
@goderbauer
Copy link
Member

@Piinks can you take a look at this one since it is mostly slivers and scrolling?

@Piinks
Copy link
Contributor

Piinks commented Feb 21, 2024

@Piinks can you take a look at this one since it is mostly slivers and scrolling?

For sure!

lastFlexChild = child;
} else {
final BoxConstraints innerConstraints;
if (crossAxisAlignment == CrossAxisAlignment.stretch) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, this caught my eye. It is an enum without an exhaustive switch statement!
Do you think crossAxisAlignment and _direction can be used together?

I think there is one other if (crossAxisAlignment == CrossAxisAlignment.stretch) { in this file too if it seems feasible to alter the loci to be exhaustive.

What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think that sounds great 🙂👍

I updated _computeSizes() to get rid of every == enum comparison. Really happy with how it looks now!

Comment on lines -98 to -99
final Size childSize;
final Offset scrollOffset;
Copy link
Contributor

Choose a reason for hiding this comment

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

Could these be combined into a record for one switch statement? I noticed that in packages/flutter/lib/src/rendering/paragraph.dart in this PR. :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes they could! I had them combined originally but the line length was a bit much.

But after looking over it again, I think we could make it work by inverting the if-statement, so it returns early instead of indenting the whole function.

While I'm at it, I'll refactor position into an exhaustive switch statement too :)

@nate-thegrate nate-thegrate requested a review from Piinks February 23, 2024 16:59
Copy link
Contributor

@Piinks Piinks left a comment

Choose a reason for hiding this comment

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

LGTM!

@Piinks Piinks requested a review from goderbauer February 24, 2024 00:10
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 26, 2024
@auto-submit auto-submit bot merged commit 60d28ad into flutter:master Feb 26, 2024
@nate-thegrate nate-thegrate deleted the switch-expressions-10 branch February 26, 2024 17:36
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 27, 2024
auto-submit bot pushed a commit to flutter/packages that referenced this pull request Feb 27, 2024
flutter/flutter@b77560e...c30f998

2024-02-27 [email protected] [flutter_tools] Fix missing stack trace from daemon (flutter/flutter#144113)
2024-02-27 [email protected] Roll Flutter Engine from 04ff2868ce80 to 0bc21ea7bc92 (21 revisions) (flutter/flutter#144208)
2024-02-26 [email protected] Move debugShowWidgetInspectorOverride (flutter/flutter#144029)
2024-02-26 [email protected] Allow `Listenable.merge()` to use any iterable (flutter/flutter#143675)
2024-02-26 [email protected] Mark firebase_release_smoke_test as `bringup: true` (flutter/flutter#144186)
2024-02-26 [email protected] refactor: Differentiate pubspec and resolution errors for plugins (flutter/flutter#142035)
2024-02-26 [email protected] Roll Flutter Engine from 34a8b9bdaaac to 04ff2868ce80 (1 revision) (flutter/flutter#144159)
2024-02-26 [email protected] Implementing `switch` expressions in `rendering/` (flutter/flutter#143812)
2024-02-26 [email protected] Roll Flutter Engine from 7a573c21a4ad to 34a8b9bdaaac (1 revision) (flutter/flutter#144147)
2024-02-26 [email protected] Roll Flutter Engine from a15326b2c439 to 7a573c21a4ad (1 revision) (flutter/flutter#144145)
2024-02-26 [email protected] Update copyDirectory to allow links to not be followed (flutter/flutter#144040)
2024-02-26 [email protected] Roll Packages from 7df2085 to 353086c (7 revisions) (flutter/flutter#144144)

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@b77560e...c30f998

2024-02-27 [email protected] [flutter_tools] Fix missing stack trace from daemon (flutter/flutter#144113)
2024-02-27 [email protected] Roll Flutter Engine from 04ff2868ce80 to 0bc21ea7bc92 (21 revisions) (flutter/flutter#144208)
2024-02-26 [email protected] Move debugShowWidgetInspectorOverride (flutter/flutter#144029)
2024-02-26 [email protected] Allow `Listenable.merge()` to use any iterable (flutter/flutter#143675)
2024-02-26 [email protected] Mark firebase_release_smoke_test as `bringup: true` (flutter/flutter#144186)
2024-02-26 [email protected] refactor: Differentiate pubspec and resolution errors for plugins (flutter/flutter#142035)
2024-02-26 [email protected] Roll Flutter Engine from 34a8b9bdaaac to 04ff2868ce80 (1 revision) (flutter/flutter#144159)
2024-02-26 [email protected] Implementing `switch` expressions in `rendering/` (flutter/flutter#143812)
2024-02-26 [email protected] Roll Flutter Engine from 7a573c21a4ad to 34a8b9bdaaac (1 revision) (flutter/flutter#144147)
2024-02-26 [email protected] Roll Flutter Engine from a15326b2c439 to 7a573c21a4ad (1 revision) (flutter/flutter#144145)
2024-02-26 [email protected] Update copyDirectory to allow links to not be followed (flutter/flutter#144040)
2024-02-26 [email protected] Roll Packages from 7df2085 to 353086c (7 revisions) (flutter/flutter#144144)

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
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! �
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 14, 2024
@nate-thegrate nate-thegrate mentioned this pull request Jun 21, 2024
8 tasks
@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

autosubmit Merge PR when tree becomes green via auto submit App f: scrolling Viewports, list views, slivers, etc. framework flutter/packages/flutter repository. See also f: labels. refactor Improving readability/efficiency without behavioral changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants