migration & enhancement for Axis / AxisDirection
#151771
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is a small change, but it still might be difficult to review.
Related:
DragGestureRecognizerabstract methods public #151446Motivation
Dependency conflict
Currently, package:flutter/painting.dart depends on package:flutter/gestures.dart, so anything within the gestures library cannot use something declared in painting (since that would create a dependency loop).
This resulted in a less-than-ideal situation: the
DragGestureRecognizerneeds to use anAxisvalue for itsprimaryDragAxisfield and itsgetSumDelta()method, but it isn't allowed to import theAxisenum.So instead, the enum was copied into the file and given a private name. All methods that use this enum have to be private as well: if someone needs a version of
PanGestureRecognizerwith a slight change to the distance required to accept the gesture, they need to copy the entireDragGestureRecognizerinterface and re-implement each abstract method before tweaking to the desired behavior.Enum enhancements
AxisandAxisDirectionwere given a few helper methods before enhanced enum features were added to Dart. This provides an opportunity for a satisfying refactor:It's much easier for me to understand the process of "convert the
AxisDirectionto anAxis, and then flip it" when it isn't a nested function call that's read from right-to-left.Summary of changes
Migration
Since painting/basic_types.dart is already exporting a type from the foundation package, the migration was more-or-less trivial: enums in that file were moved into foundation/basic_types.dart.
Deprecation
AxisandAxisDirectionwere given a.flippedgetter that corresponds toflipAxis()andflipAxisDirection()respectively.AxisDirectionalso has.axisand.isReversedthat corresponds toaxisDirectionToAxis()&axisDirectionIsReversed().I also added
@Deprecated()to the functions being replaced; unfortunately at this point we can't implement a data-driven fix for a "function → getter" migration. Perhaps instead of deprecating now, we could do something similar toWidgetStateProperty.all:flutter/packages/flutter/lib/src/widgets/widget_state.dart
Lines 552 to 555 in fbb12c2