mirror of
https://github.com/flutter/flutter
synced 2024-08-24 18:36:03 +00:00
Implementing switch
expressions [refactoring flutter/lib/src/
] (#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).
This commit is contained in:
parent
383067fc93
commit
944cd11d87
|
@ -1013,36 +1013,27 @@ class CupertinoDynamicColor extends Color with Diagnosticable {
|
|||
/// brightness, normal contrast, [CupertinoUserInterfaceLevelData.base]
|
||||
/// elevation level).
|
||||
CupertinoDynamicColor resolveFrom(BuildContext context) {
|
||||
Brightness brightness = Brightness.light;
|
||||
if (_isPlatformBrightnessDependent) {
|
||||
brightness = CupertinoTheme.maybeBrightnessOf(context) ?? Brightness.light;
|
||||
}
|
||||
bool isHighContrastEnabled = false;
|
||||
if (_isHighContrastDependent) {
|
||||
isHighContrastEnabled = MediaQuery.maybeHighContrastOf(context) ?? false;
|
||||
}
|
||||
final Brightness brightness = _isPlatformBrightnessDependent
|
||||
? CupertinoTheme.maybeBrightnessOf(context) ?? Brightness.light
|
||||
: Brightness.light;
|
||||
|
||||
final CupertinoUserInterfaceLevelData level = _isInterfaceElevationDependent
|
||||
? CupertinoUserInterfaceLevel.maybeOf(context) ?? CupertinoUserInterfaceLevelData.base
|
||||
: CupertinoUserInterfaceLevelData.base;
|
||||
|
||||
final Color resolved;
|
||||
switch (brightness) {
|
||||
case Brightness.light:
|
||||
switch (level) {
|
||||
case CupertinoUserInterfaceLevelData.base:
|
||||
resolved = isHighContrastEnabled ? highContrastColor : color;
|
||||
case CupertinoUserInterfaceLevelData.elevated:
|
||||
resolved = isHighContrastEnabled ? highContrastElevatedColor : elevatedColor;
|
||||
}
|
||||
case Brightness.dark:
|
||||
switch (level) {
|
||||
case CupertinoUserInterfaceLevelData.base:
|
||||
resolved = isHighContrastEnabled ? darkHighContrastColor : darkColor;
|
||||
case CupertinoUserInterfaceLevelData.elevated:
|
||||
resolved = isHighContrastEnabled ? darkHighContrastElevatedColor : darkElevatedColor;
|
||||
}
|
||||
}
|
||||
final bool highContrast = _isHighContrastDependent
|
||||
&& (MediaQuery.maybeHighContrastOf(context) ?? false);
|
||||
|
||||
final Color resolved = switch ((brightness, level, highContrast)) {
|
||||
(Brightness.light, CupertinoUserInterfaceLevelData.base, false) => color,
|
||||
(Brightness.light, CupertinoUserInterfaceLevelData.base, true) => highContrastColor,
|
||||
(Brightness.light, CupertinoUserInterfaceLevelData.elevated, false) => elevatedColor,
|
||||
(Brightness.light, CupertinoUserInterfaceLevelData.elevated, true) => highContrastElevatedColor,
|
||||
(Brightness.dark, CupertinoUserInterfaceLevelData.base, false) => darkColor,
|
||||
(Brightness.dark, CupertinoUserInterfaceLevelData.base, true) => darkHighContrastColor,
|
||||
(Brightness.dark, CupertinoUserInterfaceLevelData.elevated, false) => darkElevatedColor,
|
||||
(Brightness.dark, CupertinoUserInterfaceLevelData.elevated, true) => darkHighContrastElevatedColor,
|
||||
};
|
||||
|
||||
Element? debugContext;
|
||||
assert(() {
|
||||
|
|
|
@ -1925,10 +1925,11 @@ class _RenderChip extends RenderBox with SlottedContainerRenderObjectMixin<_Chip
|
|||
assert(sizes.content >= boxSize.height);
|
||||
switch (textDirection!) {
|
||||
case TextDirection.rtl:
|
||||
return Offset(x - boxSize.width, (sizes.content - boxSize.height + sizes.densityAdjustment.dy) / 2.0);
|
||||
x -= boxSize.width;
|
||||
case TextDirection.ltr:
|
||||
return Offset(x, (sizes.content - boxSize.height + sizes.densityAdjustment.dy) / 2.0);
|
||||
break;
|
||||
}
|
||||
return Offset(x, (sizes.content - boxSize.height + sizes.densityAdjustment.dy) / 2.0);
|
||||
}
|
||||
|
||||
// These are the offsets to the upper left corners of the boxes (including
|
||||
|
@ -2036,20 +2037,11 @@ class _RenderChip extends RenderBox with SlottedContainerRenderObjectMixin<_Chip
|
|||
if (enableAnimation.isCompleted) {
|
||||
return Colors.white;
|
||||
}
|
||||
final ColorTween enableTween;
|
||||
switch (theme.brightness) {
|
||||
case Brightness.light:
|
||||
enableTween = ColorTween(
|
||||
begin: Colors.white.withAlpha(_kDisabledAlpha),
|
||||
end: Colors.white,
|
||||
);
|
||||
case Brightness.dark:
|
||||
enableTween = ColorTween(
|
||||
begin: Colors.black.withAlpha(_kDisabledAlpha),
|
||||
end: Colors.black,
|
||||
);
|
||||
}
|
||||
return enableTween.evaluate(enableAnimation)!;
|
||||
final Color color = switch (theme.brightness) {
|
||||
Brightness.light => Colors.white,
|
||||
Brightness.dark => Colors.black,
|
||||
};
|
||||
return ColorTween(begin: color.withAlpha(_kDisabledAlpha), end: color).evaluate(enableAnimation)!;
|
||||
}
|
||||
|
||||
void _paintCheck(Canvas canvas, Offset origin, double size) {
|
||||
|
|
|
@ -482,26 +482,20 @@ class _DatePickerDialogState extends State<DatePickerDialog> with RestorationMix
|
|||
|
||||
Size _dialogSize(BuildContext context) {
|
||||
final bool useMaterial3 = Theme.of(context).useMaterial3;
|
||||
final bool isCalendar = switch (_entryMode.value) {
|
||||
DatePickerEntryMode.calendar || DatePickerEntryMode.calendarOnly => true,
|
||||
DatePickerEntryMode.input || DatePickerEntryMode.inputOnly => false,
|
||||
};
|
||||
final Orientation orientation = MediaQuery.orientationOf(context);
|
||||
|
||||
switch (_entryMode.value) {
|
||||
case DatePickerEntryMode.calendar:
|
||||
case DatePickerEntryMode.calendarOnly:
|
||||
switch (orientation) {
|
||||
case Orientation.portrait:
|
||||
return useMaterial3 ? _calendarPortraitDialogSizeM3 : _calendarPortraitDialogSizeM2;
|
||||
case Orientation.landscape:
|
||||
return _calendarLandscapeDialogSize;
|
||||
}
|
||||
case DatePickerEntryMode.input:
|
||||
case DatePickerEntryMode.inputOnly:
|
||||
switch (orientation) {
|
||||
case Orientation.portrait:
|
||||
return useMaterial3 ? _inputPortraitDialogSizeM3 : _inputPortraitDialogSizeM2;
|
||||
case Orientation.landscape:
|
||||
return _inputLandscapeDialogSize;
|
||||
}
|
||||
}
|
||||
return switch ((isCalendar, orientation)) {
|
||||
(true, Orientation.portrait) when useMaterial3 => _calendarPortraitDialogSizeM3,
|
||||
(false, Orientation.portrait) when useMaterial3 => _inputPortraitDialogSizeM3,
|
||||
(true, Orientation.portrait) => _calendarPortraitDialogSizeM2,
|
||||
(false, Orientation.portrait) => _inputPortraitDialogSizeM2,
|
||||
(true, Orientation.landscape) => _calendarLandscapeDialogSize,
|
||||
(false, Orientation.landscape) => _inputLandscapeDialogSize,
|
||||
};
|
||||
}
|
||||
|
||||
static const Map<ShortcutActivator, Intent> _formShortcutMap = <ShortcutActivator, Intent>{
|
||||
|
|
|
@ -662,8 +662,6 @@ class DrawerControllerState extends State<DrawerController> with SingleTickerPro
|
|||
}
|
||||
|
||||
Widget _buildDrawer(BuildContext context) {
|
||||
final bool drawerIsStart = widget.alignment == DrawerAlignment.start;
|
||||
final TextDirection textDirection = Directionality.of(context);
|
||||
final bool isDesktop;
|
||||
switch (Theme.of(context).platform) {
|
||||
case TargetPlatform.android:
|
||||
|
@ -676,18 +674,13 @@ class DrawerControllerState extends State<DrawerController> with SingleTickerPro
|
|||
isDesktop = true;
|
||||
}
|
||||
|
||||
double? dragAreaWidth = widget.edgeDragWidth;
|
||||
if (widget.edgeDragWidth == null) {
|
||||
final EdgeInsets padding = MediaQuery.paddingOf(context);
|
||||
switch (textDirection) {
|
||||
case TextDirection.ltr:
|
||||
dragAreaWidth = _kEdgeDragWidth +
|
||||
(drawerIsStart ? padding.left : padding.right);
|
||||
case TextDirection.rtl:
|
||||
dragAreaWidth = _kEdgeDragWidth +
|
||||
(drawerIsStart ? padding.right : padding.left);
|
||||
}
|
||||
}
|
||||
final double dragAreaWidth = widget.edgeDragWidth
|
||||
?? _kEdgeDragWidth + switch ((widget.alignment, Directionality.of(context))) {
|
||||
(DrawerAlignment.start, TextDirection.ltr) => MediaQuery.paddingOf(context).left,
|
||||
(DrawerAlignment.start, TextDirection.rtl) => MediaQuery.paddingOf(context).right,
|
||||
(DrawerAlignment.end, TextDirection.rtl) => MediaQuery.paddingOf(context).left,
|
||||
(DrawerAlignment.end, TextDirection.ltr) => MediaQuery.paddingOf(context).right,
|
||||
};
|
||||
|
||||
if (_controller.status == AnimationStatus.dismissed) {
|
||||
if (widget.enableOpenDragGesture && !isDesktop) {
|
||||
|
|
|
@ -1377,55 +1377,27 @@ class _RenderListTile extends RenderBox with SlottedContainerRenderObjectMixin<_
|
|||
}
|
||||
}
|
||||
|
||||
final double leadingY;
|
||||
final double trailingY;
|
||||
final double leadingDiff = tileHeight - leadingSize.height;
|
||||
final double trailingDiff = tileHeight - trailingSize.height;
|
||||
|
||||
switch (titleAlignment) {
|
||||
case ListTileTitleAlignment.threeLine: {
|
||||
if (isThreeLine) {
|
||||
leadingY = _minVerticalPadding;
|
||||
trailingY = _minVerticalPadding;
|
||||
} else {
|
||||
leadingY = (tileHeight - leadingSize.height) / 2.0;
|
||||
trailingY = (tileHeight - trailingSize.height) / 2.0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case ListTileTitleAlignment.titleHeight: {
|
||||
// This attempts to implement the redlines for the vertical position of the
|
||||
// leading and trailing icons on the spec page:
|
||||
// https://m2.material.io/components/lists#specs
|
||||
// The interpretation for these redlines is as follows:
|
||||
// - For large tiles (> 72dp), both leading and trailing controls should be
|
||||
// a fixed distance from top. As per guidelines this is set to 16dp.
|
||||
// - For smaller tiles, trailing should always be centered. Leading can be
|
||||
// centered or closer to the top. It should never be further than 16dp
|
||||
// to the top.
|
||||
if (tileHeight > 72.0) {
|
||||
leadingY = 16.0;
|
||||
trailingY = 16.0;
|
||||
} else {
|
||||
leadingY = math.min((tileHeight - leadingSize.height) / 2.0, 16.0);
|
||||
trailingY = (tileHeight - trailingSize.height) / 2.0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case ListTileTitleAlignment.top: {
|
||||
leadingY = _minVerticalPadding;
|
||||
trailingY = _minVerticalPadding;
|
||||
break;
|
||||
}
|
||||
case ListTileTitleAlignment.center: {
|
||||
leadingY = (tileHeight - leadingSize.height) / 2.0;
|
||||
trailingY = (tileHeight - trailingSize.height) / 2.0;
|
||||
break;
|
||||
}
|
||||
case ListTileTitleAlignment.bottom: {
|
||||
leadingY = tileHeight - leadingSize.height - _minVerticalPadding;
|
||||
trailingY = tileHeight - trailingSize.height - _minVerticalPadding;
|
||||
break;
|
||||
}
|
||||
}
|
||||
final (double leadingY, double trailingY) = switch (titleAlignment) {
|
||||
ListTileTitleAlignment.threeLine when isThreeLine => (_minVerticalPadding, _minVerticalPadding),
|
||||
ListTileTitleAlignment.threeLine => (leadingDiff / 2.0, trailingDiff / 2.0),
|
||||
// This attempts to implement the redlines for the vertical position of the
|
||||
// leading and trailing icons on the spec page:
|
||||
// https://m2.material.io/components/lists#specs
|
||||
//
|
||||
// For large tiles (> 72dp), both leading and trailing controls should be
|
||||
// a fixed distance from top. As per guidelines this is set to 16dp.
|
||||
ListTileTitleAlignment.titleHeight when tileHeight > 72.0 => (16.0, 16.0),
|
||||
// For smaller tiles, trailing should always be centered. Leading can be
|
||||
// centered or closer to the top. It should never be further than 16dp
|
||||
// to the top.
|
||||
ListTileTitleAlignment.titleHeight => (math.min(leadingDiff / 2.0, 16.0), trailingDiff / 2.0),
|
||||
ListTileTitleAlignment.top => (_minVerticalPadding, _minVerticalPadding),
|
||||
ListTileTitleAlignment.center => (leadingDiff / 2.0, trailingDiff / 2.0),
|
||||
ListTileTitleAlignment.bottom => (leadingDiff - _minVerticalPadding, trailingDiff - _minVerticalPadding),
|
||||
};
|
||||
|
||||
switch (textDirection) {
|
||||
case TextDirection.rtl: {
|
||||
|
|
|
@ -1729,22 +1729,11 @@ abstract class RenderSliver extends RenderObject {
|
|||
/// Mixin for [RenderSliver] subclasses that provides some utility functions.
|
||||
mixin RenderSliverHelpers implements RenderSliver {
|
||||
bool _getRightWayUp(SliverConstraints constraints) {
|
||||
bool rightWayUp;
|
||||
switch (constraints.axisDirection) {
|
||||
case AxisDirection.up:
|
||||
case AxisDirection.left:
|
||||
rightWayUp = false;
|
||||
case AxisDirection.down:
|
||||
case AxisDirection.right:
|
||||
rightWayUp = true;
|
||||
}
|
||||
switch (constraints.growthDirection) {
|
||||
case GrowthDirection.forward:
|
||||
break;
|
||||
case GrowthDirection.reverse:
|
||||
rightWayUp = !rightWayUp;
|
||||
}
|
||||
return rightWayUp;
|
||||
final bool reversed = axisDirectionIsReversed(constraints.axisDirection);
|
||||
return switch (constraints.growthDirection) {
|
||||
GrowthDirection.forward => !reversed,
|
||||
GrowthDirection.reverse => reversed,
|
||||
};
|
||||
}
|
||||
|
||||
/// Utility function for [hitTestChildren] for use when the children are
|
||||
|
|
|
@ -37,14 +37,11 @@ class RenderSliverCrossAxisGroup extends RenderSliver with ContainerRenderObject
|
|||
|
||||
@override
|
||||
double childCrossAxisPosition(RenderSliver child) {
|
||||
switch (constraints.axisDirection) {
|
||||
case AxisDirection.up:
|
||||
case AxisDirection.down:
|
||||
return (child.parentData! as SliverPhysicalParentData).paintOffset.dx;
|
||||
case AxisDirection.left:
|
||||
case AxisDirection.right:
|
||||
return (child.parentData! as SliverPhysicalParentData).paintOffset.dy;
|
||||
}
|
||||
final Offset paintOffset = (child.parentData! as SliverPhysicalParentData).paintOffset;
|
||||
return switch (constraints.axis) {
|
||||
Axis.vertical => paintOffset.dx,
|
||||
Axis.horizontal => paintOffset.dy,
|
||||
};
|
||||
}
|
||||
|
||||
@override
|
||||
|
|
|
@ -925,22 +925,13 @@ abstract class RenderViewportBase<ParentDataClass extends ContainerParentDataMix
|
|||
assert(child is RenderSliver);
|
||||
final RenderSliver sliver = child as RenderSliver;
|
||||
|
||||
final double targetMainAxisExtent;
|
||||
// The scroll offset of `rect` within `child`.
|
||||
switch (applyGrowthDirectionToAxisDirection(axisDirection, growthDirection)) {
|
||||
case AxisDirection.up:
|
||||
leadingScrollOffset += pivotExtent - rectLocal.bottom;
|
||||
targetMainAxisExtent = rectLocal.height;
|
||||
case AxisDirection.right:
|
||||
leadingScrollOffset += rectLocal.left;
|
||||
targetMainAxisExtent = rectLocal.width;
|
||||
case AxisDirection.down:
|
||||
leadingScrollOffset += rectLocal.top;
|
||||
targetMainAxisExtent = rectLocal.height;
|
||||
case AxisDirection.left:
|
||||
leadingScrollOffset += pivotExtent - rectLocal.right;
|
||||
targetMainAxisExtent = rectLocal.width;
|
||||
}
|
||||
leadingScrollOffset += switch (applyGrowthDirectionToAxisDirection(axisDirection, growthDirection)) {
|
||||
AxisDirection.up => pivotExtent - rectLocal.bottom,
|
||||
AxisDirection.left => pivotExtent - rectLocal.right,
|
||||
AxisDirection.right => rectLocal.left,
|
||||
AxisDirection.down => rectLocal.top,
|
||||
};
|
||||
|
||||
// So far leadingScrollOffset is the scroll offset of `rect` in the `child`
|
||||
// sliver's sliver coordinate system. The sign of this value indicates
|
||||
|
@ -973,35 +964,26 @@ abstract class RenderViewportBase<ParentDataClass extends ContainerParentDataMix
|
|||
// If child's growth direction is reverse, when viewport.offset is
|
||||
// `leadingScrollOffset`, it is positioned just outside of the leading
|
||||
// edge of the viewport.
|
||||
switch (axis) {
|
||||
case Axis.vertical:
|
||||
leadingScrollOffset -= targetRect.height;
|
||||
case Axis.horizontal:
|
||||
leadingScrollOffset -= targetRect.width;
|
||||
}
|
||||
leadingScrollOffset -= switch (axis) {
|
||||
Axis.vertical => targetRect.height,
|
||||
Axis.horizontal => targetRect.width,
|
||||
};
|
||||
}
|
||||
|
||||
final double mainAxisExtent;
|
||||
switch (axis) {
|
||||
case Axis.horizontal:
|
||||
mainAxisExtent = size.width - extentOfPinnedSlivers;
|
||||
case Axis.vertical:
|
||||
mainAxisExtent = size.height - extentOfPinnedSlivers;
|
||||
}
|
||||
final double mainAxisExtentDifference = switch (axis) {
|
||||
Axis.horizontal => size.width - extentOfPinnedSlivers - rectLocal.width,
|
||||
Axis.vertical => size.height - extentOfPinnedSlivers - rectLocal.height,
|
||||
};
|
||||
|
||||
final double targetOffset = leadingScrollOffset - (mainAxisExtent - targetMainAxisExtent) * alignment;
|
||||
final double targetOffset = leadingScrollOffset - mainAxisExtentDifference * alignment;
|
||||
final double offsetDifference = offset.pixels - targetOffset;
|
||||
|
||||
switch (axisDirection) {
|
||||
case AxisDirection.down:
|
||||
targetRect = targetRect.translate(0.0, offsetDifference);
|
||||
case AxisDirection.right:
|
||||
targetRect = targetRect.translate(offsetDifference, 0.0);
|
||||
case AxisDirection.up:
|
||||
targetRect = targetRect.translate(0.0, -offsetDifference);
|
||||
case AxisDirection.left:
|
||||
targetRect = targetRect.translate(-offsetDifference, 0.0);
|
||||
}
|
||||
targetRect = switch (axisDirection) {
|
||||
AxisDirection.up => targetRect.translate(0.0, -offsetDifference),
|
||||
AxisDirection.down => targetRect.translate(0.0, offsetDifference),
|
||||
AxisDirection.left => targetRect.translate(-offsetDifference, 0.0),
|
||||
AxisDirection.right => targetRect.translate( offsetDifference, 0.0),
|
||||
};
|
||||
|
||||
return RevealedOffset(offset: targetOffset, rect: targetRect);
|
||||
}
|
||||
|
|
|
@ -145,21 +145,19 @@ class RawKeyEventDataIos extends RawKeyEventData {
|
|||
if (modifiers & anyMask == 0) {
|
||||
return false;
|
||||
}
|
||||
// If only the "anyMask" bit is set, then we respond true for requests of
|
||||
// whether either left or right is pressed. Handles the case where iOS
|
||||
// supplies just the "either" modifier flag, but not the left/right flag.
|
||||
// (e.g. modifierShift but not modifierLeftShift).
|
||||
final bool anyOnly = modifiers & (leftMask | rightMask | anyMask) == anyMask;
|
||||
switch (side) {
|
||||
case KeyboardSide.any:
|
||||
return true;
|
||||
case KeyboardSide.all:
|
||||
return modifiers & leftMask != 0 && modifiers & rightMask != 0 || anyOnly;
|
||||
case KeyboardSide.left:
|
||||
return modifiers & leftMask != 0 || anyOnly;
|
||||
case KeyboardSide.right:
|
||||
return modifiers & rightMask != 0 || anyOnly;
|
||||
if (modifiers & (leftMask | rightMask | anyMask) == anyMask) {
|
||||
// If only the "anyMask" bit is set, then we respond true for requests of
|
||||
// whether either left or right is pressed. Handles the case where iOS
|
||||
// supplies just the "either" modifier flag, but not the left/right flag.
|
||||
// (e.g. modifierShift but not modifierLeftShift).
|
||||
return true;
|
||||
}
|
||||
return switch (side) {
|
||||
KeyboardSide.any => true,
|
||||
KeyboardSide.all => modifiers & leftMask != 0 && modifiers & rightMask != 0,
|
||||
KeyboardSide.left => modifiers & leftMask != 0,
|
||||
KeyboardSide.right => modifiers & rightMask != 0,
|
||||
};
|
||||
}
|
||||
|
||||
@override
|
||||
|
|
|
@ -147,21 +147,19 @@ class RawKeyEventDataMacOs extends RawKeyEventData {
|
|||
if (modifiers & anyMask == 0) {
|
||||
return false;
|
||||
}
|
||||
// If only the "anyMask" bit is set, then we respond true for requests of
|
||||
// whether either left or right is pressed. Handles the case where macOS
|
||||
// supplies just the "either" modifier flag, but not the left/right flag.
|
||||
// (e.g. modifierShift but not modifierLeftShift).
|
||||
final bool anyOnly = modifiers & (leftMask | rightMask | anyMask) == anyMask;
|
||||
switch (side) {
|
||||
case KeyboardSide.any:
|
||||
return true;
|
||||
case KeyboardSide.all:
|
||||
return modifiers & leftMask != 0 && modifiers & rightMask != 0 || anyOnly;
|
||||
case KeyboardSide.left:
|
||||
return modifiers & leftMask != 0 || anyOnly;
|
||||
case KeyboardSide.right:
|
||||
return modifiers & rightMask != 0 || anyOnly;
|
||||
if (modifiers & (leftMask | rightMask | anyMask) == anyMask) {
|
||||
// If only the "anyMask" bit is set, then we respond true for requests of
|
||||
// whether either left or right is pressed. Handles the case where macOS
|
||||
// supplies just the "either" modifier flag, but not the left/right flag.
|
||||
// (e.g. modifierShift but not modifierLeftShift).
|
||||
return true;
|
||||
}
|
||||
return switch (side) {
|
||||
KeyboardSide.any => true,
|
||||
KeyboardSide.all => modifiers & leftMask != 0 && modifiers & rightMask != 0,
|
||||
KeyboardSide.left => modifiers & leftMask != 0,
|
||||
KeyboardSide.right => modifiers & rightMask != 0,
|
||||
};
|
||||
}
|
||||
|
||||
@override
|
||||
|
|
|
@ -101,26 +101,22 @@ class RawKeyEventDataWindows extends RawKeyEventData {
|
|||
}
|
||||
|
||||
bool _isLeftRightModifierPressed(KeyboardSide side, int anyMask, int leftMask, int rightMask) {
|
||||
if (modifiers & anyMask == 0 &&
|
||||
modifiers & leftMask == 0 &&
|
||||
modifiers & rightMask == 0) {
|
||||
if (modifiers & (leftMask | rightMask | anyMask) == 0) {
|
||||
return false;
|
||||
}
|
||||
// If only the "anyMask" bit is set, then we respond true for requests of
|
||||
// whether either left or right is pressed. Handles the case where Windows
|
||||
// supplies just the "either" modifier flag, but not the left/right flag.
|
||||
// (e.g. modifierShift but not modifierLeftShift).
|
||||
final bool anyOnly = modifiers & (leftMask | rightMask | anyMask) == anyMask;
|
||||
switch (side) {
|
||||
case KeyboardSide.any:
|
||||
return true;
|
||||
case KeyboardSide.all:
|
||||
return modifiers & leftMask != 0 && modifiers & rightMask != 0 || anyOnly;
|
||||
case KeyboardSide.left:
|
||||
return modifiers & leftMask != 0 || anyOnly;
|
||||
case KeyboardSide.right:
|
||||
return modifiers & rightMask != 0 || anyOnly;
|
||||
if (modifiers & (leftMask | rightMask | anyMask) == anyMask) {
|
||||
// If only the "anyMask" bit is set, then we respond true for requests of
|
||||
// whether either left or right is pressed. Handles the case where Windows
|
||||
// supplies just the "either" modifier flag, but not the left/right flag.
|
||||
// (e.g. modifierShift but not modifierLeftShift).
|
||||
return true;
|
||||
}
|
||||
return switch (side) {
|
||||
KeyboardSide.any => true,
|
||||
KeyboardSide.all => modifiers & leftMask != 0 && modifiers & rightMask != 0,
|
||||
KeyboardSide.left => modifiers & leftMask != 0,
|
||||
KeyboardSide.right => modifiers & rightMask != 0,
|
||||
};
|
||||
}
|
||||
|
||||
@override
|
||||
|
|
|
@ -731,24 +731,16 @@ class _StretchingOverscrollIndicatorState extends State<StretchingOverscrollIndi
|
|||
|
||||
AlignmentGeometry _getAlignmentForAxisDirection(_StretchDirection stretchDirection) {
|
||||
// Accounts for reversed scrollables by checking the AxisDirection
|
||||
switch (widget.axisDirection) {
|
||||
case AxisDirection.up:
|
||||
return stretchDirection == _StretchDirection.trailing
|
||||
? AlignmentDirectional.topCenter
|
||||
: AlignmentDirectional.bottomCenter;
|
||||
case AxisDirection.right:
|
||||
return stretchDirection == _StretchDirection.trailing
|
||||
? Alignment.centerRight
|
||||
: Alignment.centerLeft;
|
||||
case AxisDirection.down:
|
||||
return stretchDirection == _StretchDirection.trailing
|
||||
? AlignmentDirectional.bottomCenter
|
||||
: AlignmentDirectional.topCenter;
|
||||
case AxisDirection.left:
|
||||
return stretchDirection == _StretchDirection.trailing
|
||||
? Alignment.centerLeft
|
||||
: Alignment.centerRight;
|
||||
}
|
||||
final AxisDirection direction = switch (stretchDirection) {
|
||||
_StretchDirection.trailing => widget.axisDirection,
|
||||
_StretchDirection.leading => flipAxisDirection(widget.axisDirection),
|
||||
};
|
||||
return switch (direction) {
|
||||
AxisDirection.up => AlignmentDirectional.topCenter,
|
||||
AxisDirection.down => AlignmentDirectional.bottomCenter,
|
||||
AxisDirection.left => Alignment.centerLeft,
|
||||
AxisDirection.right => Alignment.centerRight,
|
||||
};
|
||||
}
|
||||
|
||||
@override
|
||||
|
|
|
@ -885,7 +885,6 @@ class ScrollableState extends State<Scrollable> with TickerProviderStateMixin, R
|
|||
// direction, and any modifiers specified by the ScrollBehavior taken into
|
||||
// account.
|
||||
double _pointerSignalEventDelta(PointerScrollEvent event) {
|
||||
late double delta;
|
||||
final Set<LogicalKeyboardKey> pressed = HardwareKeyboard.instance.logicalKeysPressed;
|
||||
final bool flipAxes = pressed.any(_configuration.pointerAxisModifiers.contains) &&
|
||||
// Axes are only flipped for physical mouse wheel input.
|
||||
|
@ -896,21 +895,13 @@ class ScrollableState extends State<Scrollable> with TickerProviderStateMixin, R
|
|||
// axis.
|
||||
event.kind == PointerDeviceKind.mouse;
|
||||
|
||||
switch (widget.axis) {
|
||||
case Axis.horizontal:
|
||||
delta = flipAxes
|
||||
? event.scrollDelta.dy
|
||||
: event.scrollDelta.dx;
|
||||
case Axis.vertical:
|
||||
delta = flipAxes
|
||||
? event.scrollDelta.dx
|
||||
: event.scrollDelta.dy;
|
||||
}
|
||||
final Axis axis = flipAxes ? flipAxis(widget.axis) : widget.axis;
|
||||
final double delta = switch (axis) {
|
||||
Axis.horizontal => event.scrollDelta.dx,
|
||||
Axis.vertical => event.scrollDelta.dy,
|
||||
};
|
||||
|
||||
if (axisDirectionIsReversed(widget.axisDirection)) {
|
||||
delta *= -1;
|
||||
}
|
||||
return delta;
|
||||
return axisDirectionIsReversed(widget.axisDirection) ? -delta : delta;
|
||||
}
|
||||
|
||||
void _receivedPointerSignal(PointerSignalEvent event) {
|
||||
|
|
|
@ -426,49 +426,11 @@ class ScrollAction extends ContextAction<ScrollIntent> {
|
|||
/// Find out how much of an increment to move by, taking the different
|
||||
/// directions into account.
|
||||
static double getDirectionalIncrement(ScrollableState state, ScrollIntent intent) {
|
||||
final double increment = _calculateScrollIncrement(state, type: intent.type);
|
||||
switch (intent.direction) {
|
||||
case AxisDirection.down:
|
||||
switch (state.axisDirection) {
|
||||
case AxisDirection.up:
|
||||
return -increment;
|
||||
case AxisDirection.down:
|
||||
return increment;
|
||||
case AxisDirection.right:
|
||||
case AxisDirection.left:
|
||||
return 0.0;
|
||||
}
|
||||
case AxisDirection.up:
|
||||
switch (state.axisDirection) {
|
||||
case AxisDirection.up:
|
||||
return increment;
|
||||
case AxisDirection.down:
|
||||
return -increment;
|
||||
case AxisDirection.right:
|
||||
case AxisDirection.left:
|
||||
return 0.0;
|
||||
}
|
||||
case AxisDirection.left:
|
||||
switch (state.axisDirection) {
|
||||
case AxisDirection.right:
|
||||
return -increment;
|
||||
case AxisDirection.left:
|
||||
return increment;
|
||||
case AxisDirection.up:
|
||||
case AxisDirection.down:
|
||||
return 0.0;
|
||||
}
|
||||
case AxisDirection.right:
|
||||
switch (state.axisDirection) {
|
||||
case AxisDirection.right:
|
||||
return increment;
|
||||
case AxisDirection.left:
|
||||
return -increment;
|
||||
case AxisDirection.up:
|
||||
case AxisDirection.down:
|
||||
return 0.0;
|
||||
}
|
||||
if (axisDirectionToAxis(intent.direction) == axisDirectionToAxis(state.axisDirection)) {
|
||||
final double increment = _calculateScrollIncrement(state, type: intent.type);
|
||||
return intent.direction == state.axisDirection ? increment : -increment;
|
||||
}
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
@override
|
||||
|
|
Loading…
Reference in a new issue