[go: nahoru, domu]

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

Intensive if chain refactoring #145194

Merged

Conversation

nate-thegrate
Copy link
Member
@nate-thegrate nate-thegrate commented Mar 15, 2024

This pull request refactors if-statements into switch expressions, as part of the effort to solve issue #144903.

Making changes beyond just swapping syntax is more difficult (and also more difficult to review, I apologize), but much more satisfying too.

@github-actions github-actions bot added framework flutter/packages/flutter repository. See also f: labels. f: material design flutter/packages/flutter/material repository. f: scrolling Viewports, list views, slivers, etc. labels Mar 15, 2024
@nate-thegrate nate-thegrate marked this pull request as ready for review March 15, 2024 05:27
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 with nits 👍 Thanks as always for doing these migrations!

dev/manual_tests/lib/star_border.dart Show resolved Hide resolved
(TraversalDirection.right, Axis.vertical) => buttonIsFocused ? _moveToPreviousFocusableTopLevel : _moveToParent,
};
if (!traversal(anchor)) {
super.invoke(intent);
Copy link
Contributor

Choose a reason for hiding this comment

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

Or maybe this one is the record haha.

Copy link
Member Author

Choose a reason for hiding this comment

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

reduction of 93 lines 😎

case _SliderAdjustmentType.down:
renderSlider.decreaseAction();
}
final bool rtl = switch (Directionality.of(_renderObjectKey.currentContext!)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Maybe just assign the Directionality to a variable, then below do _SliderAdjustmentType.left => directionality == TextDirection.rtl, etc.?

Copy link
Member Author
@nate-thegrate nate-thegrate Mar 18, 2024

Choose a reason for hiding this comment

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

This was set up as a switch expression since the style guide recommends not using == with enum values.

But in the case of TextDirection, there's already an abundance of == TextDirection.rtl in this repo. And the probability of this enum eventually being expanded into more than two values is pretty much zero.

I'm good with making this change 👍

Copy link
Contributor
@bleroux bleroux left a comment

Choose a reason for hiding this comment

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

LGTM!!! with nits.
Thanks for this impressive work!

Comment on lines 477 to 483
final OutlinedBorder targetBorder = switch (target) {
LerpTarget.circle => const CircleBorder(side: lerpToBorder, eccentricity: 0.5),
LerpTarget.rect => const RoundedRectangleBorder(side: lerpToBorder),
LerpTarget.stadium => const StadiumBorder(side: lerpToBorder),
LerpTarget.polygon => const StarBorder.polygon(side: lerpToBorder, sides: 4),
LerpTarget.star => const StarBorder(side: lerpToBorder, innerRadiusRatio: .5),
LerpTarget.roundedRect => RoundedRectangleBorder(side: lerpToBorder, borderRadius: BorderRadius.circular(10)),
Copy link
Contributor

Choose a reason for hiding this comment

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

Impressive change!
You know better than me, consider aligning the arrows (it is not always better but in this case It might be).

It was there before but maybe consider replacing .5 with 0.5 (for homogeneity).

Copy link
Member Author

Choose a reason for hiding this comment

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

Sounds good—and I totally missed the 0.5, thanks for catching that!

(TraversalDirection.right, Axis.vertical) when !rtl => buttonIsFocused ? _moveToSubmenu : _moveToNextFocusableTopLevel,
(TraversalDirection.left, Axis.vertical) when differentParent => _moveToPreviousFocusableTopLevel,
(TraversalDirection.right, Axis.vertical) when differentParent => _moveToPreviousFocusableTopLevel,
(TraversalDirection.left, Axis.vertical) => buttonIsFocused ? _moveToPreviousFocusableTopLevel : _moveToParent,
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure about how to make it clearer here. When comparing to the previous logic, I feel that having lines 2451/2453/2455 next to each others would be more readable.

Copy link
Member Author

Choose a reason for hiding this comment

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

That's actually how I had it a few days ago, and then I switched to this cause I thought it looked just a bit nicer.

Honestly not a huge deal, so I'll go ahead and revert.

packages/flutter/lib/src/material/menu_anchor.dart Outdated Show resolved Hide resolved
@bleroux bleroux added the autosubmit Merge PR when tree becomes green via auto submit App label Mar 22, 2024
@auto-submit auto-submit bot merged commit 7fb35db into flutter:master Mar 22, 2024
132 checks passed
@nate-thegrate nate-thegrate deleted the intensive-if-chain-refactoring branch March 22, 2024 14:58
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 22, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 22, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 22, 2024
camsim99 pushed a commit to flutter/packages that referenced this pull request Mar 25, 2024
flutter/flutter@18340ea...14774b9

2024-03-22 engine-flutter-autoroll@skia.org Roll Flutter Engine from
eba6e31498b8 to 09dadce76828 (1 revision) (flutter/flutter#145603)
2024-03-22 engine-flutter-autoroll@skia.org Roll Flutter Engine from
f9a34ae0b14f to eba6e31498b8 (1 revision) (flutter/flutter#145598)
2024-03-22 nate.w5687@gmail.com Intensive `if` chain refactoring
(flutter/flutter#145194)
2024-03-22 leroux_bruno@yahoo.fr Adds numpad navigation shortcuts for
Linux (flutter/flutter#145464)
2024-03-22 engine-flutter-autoroll@skia.org Roll Flutter Engine from
5a12de1beab7 to f9a34ae0b14f (1 revision) (flutter/flutter#145581)
2024-03-22 engine-flutter-autoroll@skia.org Roll Flutter Engine from
e2f324beac3b to 5a12de1beab7 (1 revision) (flutter/flutter#145578)
2024-03-22 31859944+LongCatIsLooong@users.noreply.github.com Replace
`RenderBox.compute*` with `RenderBox.get*` and add
`@visibleForOverriding` (flutter/flutter#145503)
2024-03-22 gspencergoog@users.noreply.github.com Add some cross
references in the docs, move an example to a dartpad example
(flutter/flutter#145571)
2024-03-22 bernaferrari2@gmail.com Fix `BorderSide.none` requiring
explicit transparent color for `UnderlineInputBorder`
(flutter/flutter#145329)
2024-03-22 engine-flutter-autoroll@skia.org Roll Flutter Engine from
a46a7b273a5b to e2f324beac3b (1 revision) (flutter/flutter#145576)
2024-03-21 goderbauer@google.com Fix nullability of
getFullHeightForCaret (flutter/flutter#145554)
2024-03-21 34871572+gmackall@users.noreply.github.com Add a
`--no-gradle-generation` mode to the `generate_gradle_lockfiles.dart`
script (flutter/flutter#145568)
2024-03-21 engine-flutter-autoroll@skia.org Roll Flutter Engine from
1b842ae58b3d to a46a7b273a5b (2 revisions) (flutter/flutter#145569)
2024-03-21 chingjun@google.com Fixed race condition in
PollingDeviceDiscovery. (flutter/flutter#145506)
2024-03-21 engine-flutter-autoroll@skia.org Roll Flutter Engine from
a2ed373fa70f to 1b842ae58b3d (1 revision) (flutter/flutter#145565)
2024-03-21 ian@hixie.ch Clarify AutomaticKeepAliveClientMixin semantics
in build method (flutter/flutter#145297)
2024-03-21 goderbauer@google.com Eliminate more window singleton usages
(flutter/flutter#145560)
2024-03-21 jacksongardner@google.com `flutter test --wasm` support
(flutter/flutter#145347)
2024-03-21 engine-flutter-autoroll@skia.org Roll Flutter Engine from
eb262e9c34db to a2ed373fa70f (2 revisions) (flutter/flutter#145556)
2024-03-21 engine-flutter-autoroll@skia.org Roll Flutter Engine from
bad4a30e1c75 to eb262e9c34db (1 revision) (flutter/flutter#145555)

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
camillesimon@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

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
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>
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 14, 2024
arc-yong pushed a commit to Arctuition/packages-arc that referenced this pull request Jun 14, 2024
…r#6376)

flutter/flutter@18340ea...14774b9

2024-03-22 engine-flutter-autoroll@skia.org Roll Flutter Engine from
eba6e31498b8 to 09dadce76828 (1 revision) (flutter/flutter#145603)
2024-03-22 engine-flutter-autoroll@skia.org Roll Flutter Engine from
f9a34ae0b14f to eba6e31498b8 (1 revision) (flutter/flutter#145598)
2024-03-22 nate.w5687@gmail.com Intensive `if` chain refactoring
(flutter/flutter#145194)
2024-03-22 leroux_bruno@yahoo.fr Adds numpad navigation shortcuts for
Linux (flutter/flutter#145464)
2024-03-22 engine-flutter-autoroll@skia.org Roll Flutter Engine from
5a12de1beab7 to f9a34ae0b14f (1 revision) (flutter/flutter#145581)
2024-03-22 engine-flutter-autoroll@skia.org Roll Flutter Engine from
e2f324beac3b to 5a12de1beab7 (1 revision) (flutter/flutter#145578)
2024-03-22 31859944+LongCatIsLooong@users.noreply.github.com Replace
`RenderBox.compute*` with `RenderBox.get*` and add
`@visibleForOverriding` (flutter/flutter#145503)
2024-03-22 gspencergoog@users.noreply.github.com Add some cross
references in the docs, move an example to a dartpad example
(flutter/flutter#145571)
2024-03-22 bernaferrari2@gmail.com Fix `BorderSide.none` requiring
explicit transparent color for `UnderlineInputBorder`
(flutter/flutter#145329)
2024-03-22 engine-flutter-autoroll@skia.org Roll Flutter Engine from
a46a7b273a5b to e2f324beac3b (1 revision) (flutter/flutter#145576)
2024-03-21 goderbauer@google.com Fix nullability of
getFullHeightForCaret (flutter/flutter#145554)
2024-03-21 34871572+gmackall@users.noreply.github.com Add a
`--no-gradle-generation` mode to the `generate_gradle_lockfiles.dart`
script (flutter/flutter#145568)
2024-03-21 engine-flutter-autoroll@skia.org Roll Flutter Engine from
1b842ae58b3d to a46a7b273a5b (2 revisions) (flutter/flutter#145569)
2024-03-21 chingjun@google.com Fixed race condition in
PollingDeviceDiscovery. (flutter/flutter#145506)
2024-03-21 engine-flutter-autoroll@skia.org Roll Flutter Engine from
a2ed373fa70f to 1b842ae58b3d (1 revision) (flutter/flutter#145565)
2024-03-21 ian@hixie.ch Clarify AutomaticKeepAliveClientMixin semantics
in build method (flutter/flutter#145297)
2024-03-21 goderbauer@google.com Eliminate more window singleton usages
(flutter/flutter#145560)
2024-03-21 jacksongardner@google.com `flutter test --wasm` support
(flutter/flutter#145347)
2024-03-21 engine-flutter-autoroll@skia.org Roll Flutter Engine from
eb262e9c34db to a2ed373fa70f (2 revisions) (flutter/flutter#145556)
2024-03-21 engine-flutter-autoroll@skia.org Roll Flutter Engine from
bad4a30e1c75 to eb262e9c34db (1 revision) (flutter/flutter#145555)

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
camillesimon@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

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
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: material design flutter/packages/flutter/material repository. 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