Unverified Commit 8eea4f17 authored by Nate's avatar Nate Committed by GitHub

Implementing `switch` expressions in `widgets/` (#143293)

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.
parent e94e4062
...@@ -1244,12 +1244,10 @@ class _FocusableActionDetectorState extends State<FocusableActionDetector> { ...@@ -1244,12 +1244,10 @@ class _FocusableActionDetectorState extends State<FocusableActionDetector> {
bool _canShowHighlight = false; bool _canShowHighlight = false;
void _updateHighlightMode(FocusHighlightMode mode) { void _updateHighlightMode(FocusHighlightMode mode) {
_mayTriggerCallback(task: () { _mayTriggerCallback(task: () {
switch (FocusManager.instance.highlightMode) { _canShowHighlight = switch (FocusManager.instance.highlightMode) {
case FocusHighlightMode.touch: FocusHighlightMode.touch => false,
_canShowHighlight = false; FocusHighlightMode.traditional => true,
case FocusHighlightMode.traditional: };
_canShowHighlight = true;
}
}); });
} }
...@@ -1303,13 +1301,10 @@ class _FocusableActionDetectorState extends State<FocusableActionDetector> { ...@@ -1303,13 +1301,10 @@ class _FocusableActionDetectorState extends State<FocusableActionDetector> {
} }
bool canRequestFocus(FocusableActionDetector target) { bool canRequestFocus(FocusableActionDetector target) {
final NavigationMode mode = MediaQuery.maybeNavigationModeOf(context) ?? NavigationMode.traditional; return switch (MediaQuery.maybeNavigationModeOf(context)) {
switch (mode) { NavigationMode.traditional || null => target.enabled,
case NavigationMode.traditional: NavigationMode.directional => true,
return target.enabled; };
case NavigationMode.directional:
return true;
}
} }
bool shouldShowFocusHighlight(FocusableActionDetector target) { bool shouldShowFocusHighlight(FocusableActionDetector target) {
...@@ -1344,13 +1339,10 @@ class _FocusableActionDetectorState extends State<FocusableActionDetector> { ...@@ -1344,13 +1339,10 @@ class _FocusableActionDetectorState extends State<FocusableActionDetector> {
} }
bool get _canRequestFocus { bool get _canRequestFocus {
final NavigationMode mode = MediaQuery.maybeNavigationModeOf(context) ?? NavigationMode.traditional; return switch (MediaQuery.maybeNavigationModeOf(context)) {
switch (mode) { NavigationMode.traditional || null => widget.enabled,
case NavigationMode.traditional: NavigationMode.directional => true,
return widget.enabled; };
case NavigationMode.directional:
return true;
}
} }
// This global key is needed to keep only the necessary widgets in the tree // This global key is needed to keep only the necessary widgets in the tree
......
...@@ -178,64 +178,32 @@ class BannerPainter extends CustomPainter { ...@@ -178,64 +178,32 @@ class BannerPainter extends CustomPainter {
bool hitTest(Offset position) => false; bool hitTest(Offset position) => false;
double _translationX(double width) { double _translationX(double width) {
switch (layoutDirection) { return switch ((layoutDirection, location)) {
case TextDirection.rtl: (TextDirection.rtl, BannerLocation.topStart) => width,
switch (location) { (TextDirection.ltr, BannerLocation.topStart) => 0.0,
case BannerLocation.bottomEnd: (TextDirection.rtl, BannerLocation.topEnd) => 0.0,
return _kBottomOffset; (TextDirection.ltr, BannerLocation.topEnd) => width,
case BannerLocation.topEnd: (TextDirection.rtl, BannerLocation.bottomStart) => width - _kBottomOffset,
return 0.0; (TextDirection.ltr, BannerLocation.bottomStart) => _kBottomOffset,
case BannerLocation.bottomStart: (TextDirection.rtl, BannerLocation.bottomEnd) => _kBottomOffset,
return width - _kBottomOffset; (TextDirection.ltr, BannerLocation.bottomEnd) => width - _kBottomOffset,
case BannerLocation.topStart: };
return width;
}
case TextDirection.ltr:
switch (location) {
case BannerLocation.bottomEnd:
return width - _kBottomOffset;
case BannerLocation.topEnd:
return width;
case BannerLocation.bottomStart:
return _kBottomOffset;
case BannerLocation.topStart:
return 0.0;
}
}
} }
double _translationY(double height) { double _translationY(double height) {
switch (location) { return switch (location) {
case BannerLocation.bottomStart: BannerLocation.bottomStart || BannerLocation.bottomEnd => height - _kBottomOffset,
case BannerLocation.bottomEnd: BannerLocation.topStart || BannerLocation.topEnd => 0.0,
return height - _kBottomOffset; };
case BannerLocation.topStart:
case BannerLocation.topEnd:
return 0.0;
}
} }
double get _rotation { double get _rotation {
switch (layoutDirection) { return math.pi / 4.0 * switch ((layoutDirection, location)) {
case TextDirection.rtl: (TextDirection.rtl, BannerLocation.topStart || BannerLocation.bottomEnd) => 1,
switch (location) { (TextDirection.ltr, BannerLocation.topStart || BannerLocation.bottomEnd) => -1,
case BannerLocation.bottomStart: (TextDirection.rtl, BannerLocation.bottomStart || BannerLocation.topEnd) => -1,
case BannerLocation.topEnd: (TextDirection.ltr, BannerLocation.bottomStart || BannerLocation.topEnd) => 1,
return -math.pi / 4.0; };
case BannerLocation.bottomEnd:
case BannerLocation.topStart:
return math.pi / 4.0;
}
case TextDirection.ltr:
switch (location) {
case BannerLocation.bottomStart:
case BannerLocation.topEnd:
return math.pi / 4.0;
case BannerLocation.bottomEnd:
case BannerLocation.topStart:
return -math.pi / 4.0;
}
}
} }
} }
......
...@@ -2813,16 +2813,11 @@ class UnconstrainedBox extends StatelessWidget { ...@@ -2813,16 +2813,11 @@ class UnconstrainedBox extends StatelessWidget {
final Widget? child; final Widget? child;
BoxConstraintsTransform _axisToTransform(Axis? constrainedAxis) { BoxConstraintsTransform _axisToTransform(Axis? constrainedAxis) {
if (constrainedAxis != null) { return switch (constrainedAxis) {
switch (constrainedAxis) { Axis.horizontal => ConstraintsTransformBox.heightUnconstrained,
case Axis.horizontal: Axis.vertical => ConstraintsTransformBox.widthUnconstrained,
return ConstraintsTransformBox.heightUnconstrained; null => ConstraintsTransformBox.unconstrained,
case Axis.vertical: };
return ConstraintsTransformBox.widthUnconstrained;
}
} else {
return ConstraintsTransformBox.unconstrained;
}
} }
@override @override
...@@ -4263,16 +4258,10 @@ class Positioned extends ParentDataWidget<StackParentData> { ...@@ -4263,16 +4258,10 @@ class Positioned extends ParentDataWidget<StackParentData> {
double? height, double? height,
required Widget child, required Widget child,
}) { }) {
double? left; final (double? left, double? right) = switch (textDirection) {
double? right; TextDirection.rtl => (end, start),
switch (textDirection) { TextDirection.ltr => (start, end),
case TextDirection.rtl: };
left = end;
right = start;
case TextDirection.ltr:
left = start;
right = end;
}
return Positioned( return Positioned(
key: key, key: key,
left: left, left: left,
......
...@@ -785,15 +785,12 @@ mixin WidgetsBinding on BindingBase, ServicesBinding, SchedulerBinding, GestureB ...@@ -785,15 +785,12 @@ mixin WidgetsBinding on BindingBase, ServicesBinding, SchedulerBinding, GestureB
} }
Future<dynamic> _handleNavigationInvocation(MethodCall methodCall) { Future<dynamic> _handleNavigationInvocation(MethodCall methodCall) {
switch (methodCall.method) { return switch (methodCall.method) {
case 'popRoute': 'popRoute' => handlePopRoute(),
return handlePopRoute(); 'pushRoute' => handlePushRoute(methodCall.arguments as String),
case 'pushRoute': 'pushRouteInformation' => _handlePushRouteInformation(methodCall.arguments as Map<dynamic, dynamic>),
return handlePushRoute(methodCall.arguments as String); _ => Future<dynamic>.value(),
case 'pushRouteInformation': };
return _handlePushRouteInformation(methodCall.arguments as Map<dynamic, dynamic>);
}
return Future<dynamic>.value();
} }
@override @override
......
...@@ -92,13 +92,10 @@ class DecoratedBox extends SingleChildRenderObjectWidget { ...@@ -92,13 +92,10 @@ class DecoratedBox extends SingleChildRenderObjectWidget {
@override @override
void debugFillProperties(DiagnosticPropertiesBuilder properties) { void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties); super.debugFillProperties(properties);
final String label; final String label = switch (position) {
switch (position) { DecorationPosition.background => 'bg',
case DecorationPosition.background: DecorationPosition.foreground => 'fg',
label = 'bg'; };
case DecorationPosition.foreground:
label = 'fg';
}
properties.add(EnumProperty<DecorationPosition>('position', position, level: DiagnosticLevel.hidden)); properties.add(EnumProperty<DecorationPosition>('position', position, level: DiagnosticLevel.hidden));
properties.add(DiagnosticsProperty<Decoration>(label, decoration)); properties.add(DiagnosticsProperty<Decoration>(label, decoration));
} }
......
...@@ -76,13 +76,10 @@ class DecoratedSliver extends SingleChildRenderObjectWidget { ...@@ -76,13 +76,10 @@ class DecoratedSliver extends SingleChildRenderObjectWidget {
@override @override
void debugFillProperties(DiagnosticPropertiesBuilder properties) { void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties); super.debugFillProperties(properties);
final String label; final String label = switch (position) {
switch (position) { DecorationPosition.background => 'bg',
case DecorationPosition.background: DecorationPosition.foreground => 'fg',
label = 'bg'; };
case DecorationPosition.foreground:
label = 'fg';
}
properties.add(EnumProperty<DecorationPosition>('position', position, level: DiagnosticLevel.hidden)); properties.add(EnumProperty<DecorationPosition>('position', position, level: DiagnosticLevel.hidden));
properties.add(DiagnosticsProperty<Decoration>(label, decoration)); properties.add(DiagnosticsProperty<Decoration>(label, decoration));
} }
......
...@@ -472,20 +472,14 @@ class DefaultTextEditingShortcuts extends StatelessWidget { ...@@ -472,20 +472,14 @@ class DefaultTextEditingShortcuts extends StatelessWidget {
}; };
static Map<ShortcutActivator, Intent> get _shortcuts { static Map<ShortcutActivator, Intent> get _shortcuts {
switch (defaultTargetPlatform) { return switch (defaultTargetPlatform) {
case TargetPlatform.android: TargetPlatform.android => _androidShortcuts,
return _androidShortcuts; TargetPlatform.fuchsia => _fuchsiaShortcuts,
case TargetPlatform.fuchsia: TargetPlatform.iOS => _iOSShortcuts,
return _fuchsiaShortcuts; TargetPlatform.linux => _linuxShortcuts,
case TargetPlatform.iOS: TargetPlatform.macOS => _macShortcuts,
return _iOSShortcuts; TargetPlatform.windows => _windowsShortcuts,
case TargetPlatform.linux: };
return _linuxShortcuts;
case TargetPlatform.macOS:
return _macShortcuts;
case TargetPlatform.windows:
return _windowsShortcuts;
}
} }
Map<ShortcutActivator, Intent>? _getDisablingShortcut() { Map<ShortcutActivator, Intent>? _getDisablingShortcut() {
......
...@@ -341,12 +341,11 @@ class _DismissibleState extends State<Dismissible> with TickerProviderStateMixin ...@@ -341,12 +341,11 @@ class _DismissibleState extends State<Dismissible> with TickerProviderStateMixin
return DismissDirection.none; return DismissDirection.none;
} }
if (_directionIsXAxis) { if (_directionIsXAxis) {
switch (Directionality.of(context)) { return switch (Directionality.of(context)) {
case TextDirection.rtl: TextDirection.rtl when extent < 0 => DismissDirection.startToEnd,
return extent < 0 ? DismissDirection.startToEnd : DismissDirection.endToStart; TextDirection.ltr when extent > 0 => DismissDirection.startToEnd,
case TextDirection.ltr: TextDirection.rtl || TextDirection.ltr => DismissDirection.endToStart,
return extent > 0 ? DismissDirection.startToEnd : DismissDirection.endToStart; };
}
} }
return extent > 0 ? DismissDirection.down : DismissDirection.up; return extent > 0 ? DismissDirection.down : DismissDirection.up;
} }
......
...@@ -114,13 +114,10 @@ class DisplayFeatureSubScreen extends StatelessWidget { ...@@ -114,13 +114,10 @@ class DisplayFeatureSubScreen extends StatelessWidget {
} }
static Offset _fallbackAnchorPoint(BuildContext context) { static Offset _fallbackAnchorPoint(BuildContext context) {
final TextDirection textDirection = Directionality.of(context); return switch (Directionality.of(context)) {
switch (textDirection) { TextDirection.rtl => const Offset(double.maxFinite, 0),
case TextDirection.rtl: TextDirection.ltr => Offset.zero,
return const Offset(double.maxFinite, 0); };
case TextDirection.ltr:
return Offset.zero;
}
} }
/// Returns the areas of the screen that are obstructed by display features. /// Returns the areas of the screen that are obstructed by display features.
......
...@@ -109,26 +109,20 @@ class _ToolbarLayout extends MultiChildLayoutDelegate { ...@@ -109,26 +109,20 @@ class _ToolbarLayout extends MultiChildLayoutDelegate {
maxHeight: size.height, maxHeight: size.height,
); );
leadingWidth = layoutChild(_ToolbarSlot.leading, constraints).width; leadingWidth = layoutChild(_ToolbarSlot.leading, constraints).width;
final double leadingX; final double leadingX = switch (textDirection) {
switch (textDirection) { TextDirection.rtl => size.width - leadingWidth,
case TextDirection.rtl: TextDirection.ltr => 0.0,
leadingX = size.width - leadingWidth; };
case TextDirection.ltr:
leadingX = 0.0;
}
positionChild(_ToolbarSlot.leading, Offset(leadingX, 0.0)); positionChild(_ToolbarSlot.leading, Offset(leadingX, 0.0));
} }
if (hasChild(_ToolbarSlot.trailing)) { if (hasChild(_ToolbarSlot.trailing)) {
final BoxConstraints constraints = BoxConstraints.loose(size); final BoxConstraints constraints = BoxConstraints.loose(size);
final Size trailingSize = layoutChild(_ToolbarSlot.trailing, constraints); final Size trailingSize = layoutChild(_ToolbarSlot.trailing, constraints);
final double trailingX; final double trailingX = switch (textDirection) {
switch (textDirection) { TextDirection.rtl => 0.0,
case TextDirection.rtl: TextDirection.ltr => size.width - trailingSize.width,
trailingX = 0.0; };
case TextDirection.ltr:
trailingX = size.width - trailingSize.width;
}
final double trailingY = (size.height - trailingSize.height) / 2.0; final double trailingY = (size.height - trailingSize.height) / 2.0;
trailingWidth = trailingSize.width; trailingWidth = trailingSize.width;
positionChild(_ToolbarSlot.trailing, Offset(trailingX, trailingY)); positionChild(_ToolbarSlot.trailing, Offset(trailingX, trailingY));
...@@ -153,13 +147,10 @@ class _ToolbarLayout extends MultiChildLayoutDelegate { ...@@ -153,13 +147,10 @@ class _ToolbarLayout extends MultiChildLayoutDelegate {
} }
} }
final double middleX; final double middleX = switch (textDirection) {
switch (textDirection) { TextDirection.rtl => size.width - middleSize.width - middleStart,
case TextDirection.rtl: TextDirection.ltr => middleStart,
middleX = size.width - middleSize.width - middleStart; };
case TextDirection.ltr:
middleX = middleStart;
}
positionChild(_ToolbarSlot.middle, Offset(middleX, middleY)); positionChild(_ToolbarSlot.middle, Offset(middleX, middleY));
} }
......
...@@ -1686,17 +1686,11 @@ class SliverOverlapAbsorberHandle extends ChangeNotifier { ...@@ -1686,17 +1686,11 @@ class SliverOverlapAbsorberHandle extends ChangeNotifier {
@override @override
String toString() { String toString() {
String? extra; final String? extra = switch (_writers) {
switch (_writers) { 0 => ', orphan',
case 0: 1 => null, // normal case
extra = ', orphan'; _ => ', $_writers WRITERS ASSIGNED',
case 1: };
// normal case
break;
default:
extra = ', $_writers WRITERS ASSIGNED';
break;
}
return '${objectRuntimeType(this, 'SliverOverlapAbsorberHandle')}($layoutExtent$extra)'; return '${objectRuntimeType(this, 'SliverOverlapAbsorberHandle')}($layoutExtent$extra)';
} }
} }
......
...@@ -467,15 +467,11 @@ class _RenderOverflowBar extends RenderBox ...@@ -467,15 +467,11 @@ class _RenderOverflowBar extends RenderBox
double y = 0; double y = 0;
while (child != null) { while (child != null) {
final _OverflowBarParentData childParentData = child.parentData! as _OverflowBarParentData; final _OverflowBarParentData childParentData = child.parentData! as _OverflowBarParentData;
double x = 0; final double x = switch (overflowAlignment) {
switch (overflowAlignment) { OverflowBarAlignment.center => (constraints.maxWidth - child.size.width) / 2,
case OverflowBarAlignment.start: OverflowBarAlignment.start => rtl ? constraints.maxWidth - child.size.width : 0,
x = rtl ? constraints.maxWidth - child.size.width : 0; OverflowBarAlignment.end => rtl ? 0 : constraints.maxWidth - child.size.width,
case OverflowBarAlignment.center: };
x = (constraints.maxWidth - child.size.width) / 2;
case OverflowBarAlignment.end:
x = rtl ? 0 : constraints.maxWidth - child.size.width;
}
childParentData.offset = Offset(x, y); childParentData.offset = Offset(x, y);
y += child.size.height + overflowSpacing; y += child.size.height + overflowSpacing;
child = nextChild(); child = nextChild();
......
...@@ -972,12 +972,10 @@ class SliverReorderableListState extends State<SliverReorderableList> with Ticke ...@@ -972,12 +972,10 @@ class SliverReorderableListState extends State<SliverReorderableList> with Ticke
Widget _itemBuilder(BuildContext context, int index) { Widget _itemBuilder(BuildContext context, int index) {
if (_dragInfo != null && index >= widget.itemCount) { if (_dragInfo != null && index >= widget.itemCount) {
switch (_scrollDirection) { return switch (_scrollDirection) {
case Axis.horizontal: Axis.horizontal => SizedBox(width: _dragInfo!.itemExtent),
return SizedBox(width: _dragInfo!.itemExtent); Axis.vertical => SizedBox(height: _dragInfo!.itemExtent),
case Axis.vertical: };
return SizedBox(height: _dragInfo!.itemExtent);
}
} }
final Widget child = widget.itemBuilder(context, index); final Widget child = widget.itemBuilder(context, index);
assert(child.key != null, 'All list items must have a key'); assert(child.key != null, 'All list items must have a key');
...@@ -1500,39 +1498,31 @@ class _DragItemProxy extends StatelessWidget { ...@@ -1500,39 +1498,31 @@ class _DragItemProxy extends StatelessWidget {
} }
double _sizeExtent(Size size, Axis scrollDirection) { double _sizeExtent(Size size, Axis scrollDirection) {
switch (scrollDirection) { return switch (scrollDirection) {
case Axis.horizontal: Axis.horizontal => size.width,
return size.width; Axis.vertical => size.height,
case Axis.vertical: };
return size.height;
}
} }
double _offsetExtent(Offset offset, Axis scrollDirection) { double _offsetExtent(Offset offset, Axis scrollDirection) {
switch (scrollDirection) { return switch (scrollDirection) {
case Axis.horizontal: Axis.horizontal => offset.dx,
return offset.dx; Axis.vertical => offset.dy,
case Axis.vertical: };
return offset.dy;
}
} }
Offset _extentOffset(double extent, Axis scrollDirection) { Offset _extentOffset(double extent, Axis scrollDirection) {
switch (scrollDirection) { return switch (scrollDirection) {
case Axis.horizontal: Axis.horizontal => Offset(extent, 0.0),
return Offset(extent, 0.0); Axis.vertical => Offset(0.0, extent),
case Axis.vertical: };
return Offset(0.0, extent);
}
} }
Offset _restrictAxis(Offset offset, Axis scrollDirection) { Offset _restrictAxis(Offset offset, Axis scrollDirection) {
switch (scrollDirection) { return switch (scrollDirection) {
case Axis.horizontal: Axis.horizontal => Offset(offset.dx, 0.0),
return Offset(offset.dx, 0.0); Axis.vertical => Offset(0.0, offset.dy),
case Axis.vertical: };
return Offset(0.0, offset.dy);
}
} }
// A global key that takes its identity from the object and uses a value of a // A global key that takes its identity from the object and uses a value of a
......
...@@ -461,15 +461,11 @@ class SelectableRegionState extends State<SelectableRegion> with TextSelectionDe ...@@ -461,15 +461,11 @@ class SelectableRegionState extends State<SelectableRegion> with TextSelectionDe
} }
void _updateSelectionStatus() { void _updateSelectionStatus() {
final TextSelection selection;
final SelectionGeometry geometry = _selectionDelegate.value; final SelectionGeometry geometry = _selectionDelegate.value;
switch (geometry.status) { final TextSelection selection = switch (geometry.status) {
case SelectionStatus.uncollapsed: SelectionStatus.uncollapsed || SelectionStatus.collapsed => const TextSelection(baseOffset: 0, extentOffset: 1),
case SelectionStatus.collapsed: SelectionStatus.none => const TextSelection.collapsed(offset: 1),
selection = const TextSelection(baseOffset: 0, extentOffset: 1); };
case SelectionStatus.none:
selection = const TextSelection.collapsed(offset: 1);
}
textEditingValue = TextEditingValue(text: '__', selection: selection); textEditingValue = TextEditingValue(text: '__', selection: selection);
if (_hasSelectionOverlayGeometry) { if (_hasSelectionOverlayGeometry) {
_updateSelectionOverlay(); _updateSelectionOverlay();
......
...@@ -316,12 +316,10 @@ class _SemanticsDebuggerPainter extends CustomPainter { ...@@ -316,12 +316,10 @@ class _SemanticsDebuggerPainter extends CustomPainter {
effectivelabel = '${Unicode.FSI}$tooltipAndLabel${Unicode.PDI}'; effectivelabel = '${Unicode.FSI}$tooltipAndLabel${Unicode.PDI}';
annotations.insert(0, 'MISSING TEXT DIRECTION'); annotations.insert(0, 'MISSING TEXT DIRECTION');
} else { } else {
switch (data.textDirection!) { effectivelabel = switch (data.textDirection!) {
case TextDirection.rtl: TextDirection.rtl => '${Unicode.RLI}$tooltipAndLabel${Unicode.PDI}',
effectivelabel = '${Unicode.RLI}$tooltipAndLabel${Unicode.PDI}'; TextDirection.ltr => tooltipAndLabel,
case TextDirection.ltr: };
effectivelabel = tooltipAndLabel;
}
} }
if (annotations.isEmpty) { if (annotations.isEmpty) {
message = effectivelabel; message = effectivelabel;
......
...@@ -1063,13 +1063,10 @@ class SliverMultiBoxAdaptorElement extends RenderObjectElement implements Render ...@@ -1063,13 +1063,10 @@ class SliverMultiBoxAdaptorElement extends RenderObjectElement implements Render
void debugVisitOnstageChildren(ElementVisitor visitor) { void debugVisitOnstageChildren(ElementVisitor visitor) {
_childElements.values.cast<Element>().where((Element child) { _childElements.values.cast<Element>().where((Element child) {
final SliverMultiBoxAdaptorParentData parentData = child.renderObject!.parentData! as SliverMultiBoxAdaptorParentData; final SliverMultiBoxAdaptorParentData parentData = child.renderObject!.parentData! as SliverMultiBoxAdaptorParentData;
final double itemExtent; final double itemExtent = switch (renderObject.constraints.axis) {
switch (renderObject.constraints.axis) { Axis.horizontal => child.renderObject!.paintBounds.width,
case Axis.horizontal: Axis.vertical => child.renderObject!.paintBounds.height,
itemExtent = child.renderObject!.paintBounds.width; };
case Axis.vertical:
itemExtent = child.renderObject!.paintBounds.height;
}
return parentData.layoutOffset != null && return parentData.layoutOffset != null &&
parentData.layoutOffset! < renderObject.constraints.scrollOffset + renderObject.constraints.remainingPaintExtent && parentData.layoutOffset! < renderObject.constraints.scrollOffset + renderObject.constraints.remainingPaintExtent &&
......
...@@ -913,12 +913,10 @@ class TextSelectionOverlay { ...@@ -913,12 +913,10 @@ class TextSelectionOverlay {
return TextSelectionHandleType.collapsed; return TextSelectionHandleType.collapsed;
} }
switch (textDirection) { return switch (textDirection) {
case TextDirection.ltr: TextDirection.ltr => ltrType,
return ltrType; TextDirection.rtl => rtlType,
case TextDirection.rtl: };
return rtlType;
}
} }
} }
......
...@@ -296,19 +296,13 @@ class MatrixTransition extends AnimatedWidget { ...@@ -296,19 +296,13 @@ class MatrixTransition extends AnimatedWidget {
// a saveLayer call. This is usually worthwhile when animating the layer, // a saveLayer call. This is usually worthwhile when animating the layer,
// but leaving it in the layer tree before the animation has started or after // but leaving it in the layer tree before the animation has started or after
// it has finished significantly hurts performance. // it has finished significantly hurts performance.
final bool useFilterQuality;
switch (animation.status) {
case AnimationStatus.dismissed:
case AnimationStatus.completed:
useFilterQuality = false;
case AnimationStatus.forward:
case AnimationStatus.reverse:
useFilterQuality = true;
}
return Transform( return Transform(
transform: onTransform(animation.value), transform: onTransform(animation.value),
alignment: alignment, alignment: alignment,
filterQuality: useFilterQuality ? filterQuality : null, filterQuality: switch (animation.status) {
AnimationStatus.forward || AnimationStatus.reverse => filterQuality,
AnimationStatus.dismissed || AnimationStatus.completed => null,
},
child: child, child: child,
); );
} }
......
...@@ -947,31 +947,23 @@ abstract class RenderTwoDimensionalViewport extends RenderBox implements RenderA ...@@ -947,31 +947,23 @@ abstract class RenderTwoDimensionalViewport extends RenderBox implements RenderA
final RenderBox box = child as RenderBox; final RenderBox box = child as RenderBox;
final Rect rectLocal = MatrixUtils.transformRect(target.getTransformTo(child), rect); final Rect rectLocal = MatrixUtils.transformRect(target.getTransformTo(child), rect);
final double targetMainAxisExtent;
double leadingScrollOffset = offset; double leadingScrollOffset = offset;
// The scroll offset of `rect` within `child`. // The scroll offset of `rect` within `child`.
switch (axisDirection) { leadingScrollOffset += switch (axisDirection) {
case AxisDirection.up: AxisDirection.up => child.size.height - rectLocal.bottom,
leadingScrollOffset += child.size.height - rectLocal.bottom; AxisDirection.left => child.size.width - rectLocal.right,
targetMainAxisExtent = rectLocal.height; AxisDirection.right => rectLocal.left,
case AxisDirection.right: AxisDirection.down => rectLocal.top,
leadingScrollOffset += rectLocal.left; };
targetMainAxisExtent = rectLocal.width;
case AxisDirection.down:
leadingScrollOffset += rectLocal.top;
targetMainAxisExtent = rectLocal.height;
case AxisDirection.left:
leadingScrollOffset += child.size.width - rectLocal.right;
targetMainAxisExtent = rectLocal.width;
}
// The scroll offset in the viewport to `rect`. // The scroll offset in the viewport to `rect`.
final TwoDimensionalViewportParentData childParentData = parentDataOf(box); final Offset paintOffset = parentDataOf(box).paintOffset!;
leadingScrollOffset += switch (axisDirection) { leadingScrollOffset += switch (axisDirection) {
AxisDirection.down => childParentData.paintOffset!.dy, AxisDirection.up => viewportDimension.height - paintOffset.dy - box.size.height,
AxisDirection.up => viewportDimension.height - childParentData.paintOffset!.dy - box.size.height, AxisDirection.left => viewportDimension.width - paintOffset.dx - box.size.width,
AxisDirection.right => childParentData.paintOffset!.dx, AxisDirection.right => paintOffset.dx,
AxisDirection.left => viewportDimension.width - childParentData.paintOffset!.dx - box.size.width, AxisDirection.down => paintOffset.dy,
}; };
// This step assumes the viewport's layout is up-to-date, i.e., if // This step assumes the viewport's layout is up-to-date, i.e., if
...@@ -980,27 +972,24 @@ abstract class RenderTwoDimensionalViewport extends RenderBox implements RenderA ...@@ -980,27 +972,24 @@ abstract class RenderTwoDimensionalViewport extends RenderBox implements RenderA
final Matrix4 transform = target.getTransformTo(this); final Matrix4 transform = target.getTransformTo(this);
Rect targetRect = MatrixUtils.transformRect(transform, rect); Rect targetRect = MatrixUtils.transformRect(transform, rect);
final double mainAxisExtent = switch (axisDirectionToAxis(axisDirection)) { final double mainAxisExtentDifference = switch (axis) {
Axis.horizontal => viewportDimension.width, Axis.horizontal => viewportDimension.width - rectLocal.width,
Axis.vertical => viewportDimension.height, Axis.vertical => viewportDimension.height - rectLocal.height,
}; };
final double targetOffset = leadingScrollOffset - (mainAxisExtent - targetMainAxisExtent) * alignment; final double targetOffset = leadingScrollOffset - mainAxisExtentDifference * alignment;
final double offsetDifference = switch (axisDirectionToAxis(axisDirection)){ final double offsetDifference = switch (axis) {
Axis.vertical => verticalOffset.pixels - targetOffset,
Axis.horizontal => horizontalOffset.pixels - targetOffset, Axis.horizontal => horizontalOffset.pixels - targetOffset,
Axis.vertical => verticalOffset.pixels - targetOffset,
};
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),
}; };
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);
}
final RevealedOffset revealedOffset = RevealedOffset( final RevealedOffset revealedOffset = RevealedOffset(
offset: targetOffset, offset: targetOffset,
...@@ -1566,26 +1555,16 @@ abstract class RenderTwoDimensionalViewport extends RenderBox implements RenderA ...@@ -1566,26 +1555,16 @@ abstract class RenderTwoDimensionalViewport extends RenderBox implements RenderA
// This is only usable once we have sizes. // This is only usable once we have sizes.
assert(hasSize); assert(hasSize);
assert(child.hasSize); assert(child.hasSize);
final double xOffset; final double xOffset = switch (horizontalAxisDirection) {
final double yOffset; AxisDirection.right => layoutOffset.dx,
switch (verticalAxisDirection) { AxisDirection.left => viewportDimension.width - (layoutOffset.dx + child.size.width),
case AxisDirection.up: AxisDirection.up || AxisDirection.down => throw Exception('This should not happen'),
yOffset = viewportDimension.height - (layoutOffset.dy + child.size.height); };
case AxisDirection.down: final double yOffset = switch (verticalAxisDirection) {
yOffset = layoutOffset.dy; AxisDirection.up => viewportDimension.height - (layoutOffset.dy + child.size.height),
case AxisDirection.right: AxisDirection.down => layoutOffset.dy,
case AxisDirection.left: AxisDirection.right || AxisDirection.left => throw Exception('This should not happen'),
throw Exception('This should not happen'); };
}
switch (horizontalAxisDirection) {
case AxisDirection.right:
xOffset = layoutOffset.dx;
case AxisDirection.left:
xOffset = viewportDimension.width - (layoutOffset.dx + child.size.width);
case AxisDirection.up:
case AxisDirection.down:
throw Exception('This should not happen');
}
return Offset(xOffset, yOffset); return Offset(xOffset, yOffset);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment