Unverified Commit 1887bc41 authored by Nate's avatar Nate Committed by GitHub

Implementing `switch` expressions in `lib/src/material/` (#142793)

This PR is the 6ᵗʰ step in the journey to solve issue #136139 and make the entire Flutter repo more readable.

(previous pull requests: #139048, #139882, #141591, #142279, #142634)

The current focus is on `packages/flutter/lib/src/material/`. The previous 2 PRs covered files in this directory starting with letters `a-m`; this one takes care of everything else.
parent fa71e802
...@@ -866,14 +866,10 @@ mixin _ZoomTransitionBase<S extends StatefulWidget> on State<S> { ...@@ -866,14 +866,10 @@ mixin _ZoomTransitionBase<S extends StatefulWidget> on State<S> {
} }
void onAnimationStatusChange(AnimationStatus status) { void onAnimationStatusChange(AnimationStatus status) {
switch (status) { controller.allowSnapshotting = switch (status) {
case AnimationStatus.dismissed: AnimationStatus.dismissed || AnimationStatus.completed => false,
case AnimationStatus.completed: AnimationStatus.forward || AnimationStatus.reverse => useSnapshot,
controller.allowSnapshotting = false; };
case AnimationStatus.forward:
case AnimationStatus.reverse:
controller.allowSnapshotting = useSnapshot;
}
} }
@override @override
......
...@@ -730,12 +730,10 @@ class _PopupMenuRouteLayout extends SingleChildLayoutDelegate { ...@@ -730,12 +730,10 @@ class _PopupMenuRouteLayout extends SingleChildLayoutDelegate {
x = position.left; x = position.left;
} else { } else {
// Menu button is equidistant from both edges, so grow in reading direction. // Menu button is equidistant from both edges, so grow in reading direction.
switch (textDirection) { x = switch (textDirection) {
case TextDirection.rtl: TextDirection.rtl => size.width - position.right - childSize.width,
x = size.width - position.right - childSize.width; TextDirection.ltr => position.left,
case TextDirection.ltr: };
x = position.left;
}
} }
final Offset wantedPosition = Offset(x, y); final Offset wantedPosition = Offset(x, y);
final Offset originCenter = position.toRect(Offset.zero & size).center; final Offset originCenter = position.toRect(Offset.zero & size).center;
...@@ -1395,12 +1393,10 @@ class PopupMenuButtonState<T> extends State<PopupMenuButton<T>> { ...@@ -1395,12 +1393,10 @@ class PopupMenuButtonState<T> extends State<PopupMenuButton<T>> {
bool get _canRequestFocus { bool get _canRequestFocus {
final NavigationMode mode = MediaQuery.maybeNavigationModeOf(context) ?? NavigationMode.traditional; final NavigationMode mode = MediaQuery.maybeNavigationModeOf(context) ?? NavigationMode.traditional;
switch (mode) { return switch (mode) {
case NavigationMode.traditional: NavigationMode.traditional => widget.enabled,
return widget.enabled; NavigationMode.directional => true,
case NavigationMode.directional: };
return true;
}
} }
@override @override
......
...@@ -191,13 +191,10 @@ class _LinearProgressIndicatorPainter extends CustomPainter { ...@@ -191,13 +191,10 @@ class _LinearProgressIndicatorPainter extends CustomPainter {
return; return;
} }
final double left; final double left = switch (textDirection) {
switch (textDirection) { TextDirection.rtl => size.width - width - x,
case TextDirection.rtl: TextDirection.ltr => x,
left = size.width - width - x; };
case TextDirection.ltr:
left = x;
}
final Rect rect = Offset(left, 0.0) & Size(width, size.height); final Rect rect = Offset(left, 0.0) & Size(width, size.height);
if (indicatorBorderRadius != BorderRadius.zero) { if (indicatorBorderRadius != BorderRadius.zero) {
......
...@@ -453,13 +453,10 @@ class _RadioState<T> extends State<Radio<T>> with TickerProviderStateMixin, Togg ...@@ -453,13 +453,10 @@ class _RadioState<T> extends State<Radio<T>> with TickerProviderStateMixin, Togg
final VisualDensity effectiveVisualDensity = widget.visualDensity final VisualDensity effectiveVisualDensity = widget.visualDensity
?? radioTheme.visualDensity ?? radioTheme.visualDensity
?? defaults.visualDensity!; ?? defaults.visualDensity!;
Size size; Size size = switch (effectiveMaterialTapTargetSize) {
switch (effectiveMaterialTapTargetSize) { MaterialTapTargetSize.padded => const Size(kMinInteractiveDimension, kMinInteractiveDimension),
case MaterialTapTargetSize.padded: MaterialTapTargetSize.shrinkWrap => const Size(kMinInteractiveDimension - 8.0, kMinInteractiveDimension - 8.0),
size = const Size(kMinInteractiveDimension, kMinInteractiveDimension); };
case MaterialTapTargetSize.shrinkWrap:
size = const Size(kMinInteractiveDimension - 8.0, kMinInteractiveDimension - 8.0);
}
size += effectiveVisualDensity.baseSizeAdjustment; size += effectiveVisualDensity.baseSizeAdjustment;
final MaterialStateProperty<MouseCursor> effectiveMouseCursor = MaterialStateProperty.resolveWith<MouseCursor>((Set<MaterialState> states) { final MaterialStateProperty<MouseCursor> effectiveMouseCursor = MaterialStateProperty.resolveWith<MouseCursor>((Set<MaterialState> states) {
......
...@@ -485,15 +485,10 @@ class RadioListTile<T> extends StatelessWidget { ...@@ -485,15 +485,10 @@ class RadioListTile<T> extends StatelessWidget {
} }
Widget? leading, trailing; Widget? leading, trailing;
switch (controlAffinity) { (leading, trailing) = switch (controlAffinity) {
case ListTileControlAffinity.leading: ListTileControlAffinity.leading || ListTileControlAffinity.platform => (control, secondary),
case ListTileControlAffinity.platform: ListTileControlAffinity.trailing => (secondary, control),
leading = control; };
trailing = secondary;
case ListTileControlAffinity.trailing:
leading = secondary;
trailing = control;
}
final ThemeData theme = Theme.of(context); final ThemeData theme = Theme.of(context);
final RadioThemeData radioThemeData = RadioTheme.of(context); final RadioThemeData radioThemeData = RadioTheme.of(context);
final Set<MaterialState> states = <MaterialState>{ final Set<MaterialState> states = <MaterialState>{
......
...@@ -558,16 +558,10 @@ class _RangeSliderState extends State<RangeSlider> with TickerProviderStateMixin ...@@ -558,16 +558,10 @@ class _RangeSliderState extends State<RangeSlider> with TickerProviderStateMixin
// thumb selection is determined by the direction of the dx. The left thumb // thumb selection is determined by the direction of the dx. The left thumb
// is chosen for negative dx, and the right thumb is chosen for positive dx. // is chosen for negative dx, and the right thumb is chosen for positive dx.
if (inStartTouchTarget && inEndTouchTarget) { if (inStartTouchTarget && inEndTouchTarget) {
final bool towardsStart; final (bool towardsStart, bool towardsEnd) = switch (textDirection) {
final bool towardsEnd; TextDirection.ltr => (dx < 0, dx > 0),
switch (textDirection) { TextDirection.rtl => (dx > 0, dx < 0),
case TextDirection.ltr: };
towardsStart = dx < 0;
towardsEnd = dx > 0;
case TextDirection.rtl:
towardsStart = dx > 0;
towardsEnd = dx < 0;
}
if (towardsStart) { if (towardsStart) {
return Thumb.start; return Thumb.start;
} }
...@@ -1102,16 +1096,12 @@ class _RenderRangeSlider extends RenderBox with RelayoutWhenSystemFontsChangeMix ...@@ -1102,16 +1096,12 @@ class _RenderRangeSlider extends RenderBox with RelayoutWhenSystemFontsChangeMix
} }
bool get showValueIndicator { bool get showValueIndicator {
switch (_sliderTheme.showValueIndicator!) { return switch (_sliderTheme.showValueIndicator!) {
case ShowValueIndicator.onlyForDiscrete: ShowValueIndicator.onlyForDiscrete => isDiscrete,
return isDiscrete; ShowValueIndicator.onlyForContinuous => !isDiscrete,
case ShowValueIndicator.onlyForContinuous: ShowValueIndicator.always => true,
return !isDiscrete; ShowValueIndicator.never => false,
case ShowValueIndicator.always: };
return true;
case ShowValueIndicator.never:
return false;
}
} }
Size get _thumbSize => _sliderTheme.rangeThumbShape!.getPreferredSize(isEnabled, isDiscrete); Size get _thumbSize => _sliderTheme.rangeThumbShape!.getPreferredSize(isEnabled, isDiscrete);
...@@ -1142,16 +1132,10 @@ class _RenderRangeSlider extends RenderBox with RelayoutWhenSystemFontsChangeMix ...@@ -1142,16 +1132,10 @@ class _RenderRangeSlider extends RenderBox with RelayoutWhenSystemFontsChangeMix
return; return;
} }
final String text; final (String text, TextPainter labelPainter) = switch (thumb) {
final TextPainter labelPainter; Thumb.start => (labels.start, _startLabelPainter),
switch (thumb) { Thumb.end => (labels.end, _endLabelPainter),
case Thumb.start: };
text = labels.start;
labelPainter = _startLabelPainter;
case Thumb.end:
text = labels.end;
labelPainter = _endLabelPainter;
}
labelPainter labelPainter
..text = TextSpan( ..text = TextSpan(
...@@ -1205,12 +1189,10 @@ class _RenderRangeSlider extends RenderBox with RelayoutWhenSystemFontsChangeMix ...@@ -1205,12 +1189,10 @@ class _RenderRangeSlider extends RenderBox with RelayoutWhenSystemFontsChangeMix
} }
double _getValueFromVisualPosition(double visualPosition) { double _getValueFromVisualPosition(double visualPosition) {
switch (textDirection) { return switch (textDirection) {
case TextDirection.rtl: TextDirection.rtl => 1.0 - visualPosition,
return 1.0 - visualPosition; TextDirection.ltr => visualPosition,
case TextDirection.ltr: };
return visualPosition;
}
} }
double _getValueFromGlobalPosition(Offset globalPosition) { double _getValueFromGlobalPosition(Offset globalPosition) {
...@@ -1399,16 +1381,10 @@ class _RenderRangeSlider extends RenderBox with RelayoutWhenSystemFontsChangeMix ...@@ -1399,16 +1381,10 @@ class _RenderRangeSlider extends RenderBox with RelayoutWhenSystemFontsChangeMix
// The visual position is the position of the thumb from 0 to 1 from left // The visual position is the position of the thumb from 0 to 1 from left
// to right. In left to right, this is the same as the value, but it is // to right. In left to right, this is the same as the value, but it is
// reversed for right to left text. // reversed for right to left text.
final double startVisualPosition; final (double startVisualPosition, double endVisualPosition) = switch (textDirection) {
final double endVisualPosition; TextDirection.rtl => (1.0 - startValue, 1.0 - endValue),
switch (textDirection) { TextDirection.ltr => (startValue, endValue),
case TextDirection.rtl: };
startVisualPosition = 1.0 - startValue;
endVisualPosition = 1.0 - endValue;
case TextDirection.ltr:
startVisualPosition = startValue;
endVisualPosition = endValue;
}
final Rect trackRect = _sliderTheme.rangeTrackShape!.getPreferredRect( final Rect trackRect = _sliderTheme.rangeTrackShape!.getPreferredRect(
parentBox: this, parentBox: this,
...@@ -1585,15 +1561,10 @@ class _RenderRangeSlider extends RenderBox with RelayoutWhenSystemFontsChangeMix ...@@ -1585,15 +1561,10 @@ class _RenderRangeSlider extends RenderBox with RelayoutWhenSystemFontsChangeMix
labelPainter: _endLabelPainter, labelPainter: _endLabelPainter,
textScaleFactor: textScaleFactor, textScaleFactor: textScaleFactor,
).width / 2; ).width / 2;
double innerOverflow = startHalfWidth + endHalfWidth; final double innerOverflow = startHalfWidth + endHalfWidth + switch (textDirection) {
switch (textDirection) { TextDirection.ltr => startOffset - endOffset,
case TextDirection.ltr: TextDirection.rtl => endOffset - startOffset,
innerOverflow += startOffset; };
innerOverflow -= endOffset;
case TextDirection.rtl:
innerOverflow -= startOffset;
innerOverflow += endOffset;
}
_state.paintTopValueIndicator = (PaintingContext context, Offset offset) { _state.paintTopValueIndicator = (PaintingContext context, Offset offset) {
if (attached) { if (attached) {
......
...@@ -357,15 +357,10 @@ class RefreshIndicatorState extends State<RefreshIndicator> with TickerProviderS ...@@ -357,15 +357,10 @@ class RefreshIndicatorState extends State<RefreshIndicator> with TickerProviderS
}); });
return false; return false;
} }
bool? indicatorAtTopNow; final bool? indicatorAtTopNow = switch (notification.metrics.axisDirection) {
switch (notification.metrics.axisDirection) { AxisDirection.down || AxisDirection.up => true,
case AxisDirection.down: AxisDirection.left || AxisDirection.right => null,
case AxisDirection.up: };
indicatorAtTopNow = true;
case AxisDirection.left:
case AxisDirection.right:
indicatorAtTopNow = null;
}
if (indicatorAtTopNow != _isIndicatorAtTop) { if (indicatorAtTopNow != _isIndicatorAtTop) {
if (_mode == _RefreshIndicatorMode.drag || _mode == _RefreshIndicatorMode.armed) { if (_mode == _RefreshIndicatorMode.drag || _mode == _RefreshIndicatorMode.armed) {
_dismiss(_RefreshIndicatorMode.canceled); _dismiss(_RefreshIndicatorMode.canceled);
......
...@@ -874,13 +874,10 @@ class _SliderState extends State<Slider> with TickerProviderStateMixin { ...@@ -874,13 +874,10 @@ class _SliderState extends State<Slider> with TickerProviderStateMixin {
}; };
} }
final Map<ShortcutActivator, Intent> shortcutMap; final Map<ShortcutActivator, Intent> shortcutMap = switch (MediaQuery.navigationModeOf(context)) {
switch (MediaQuery.navigationModeOf(context)) { NavigationMode.directional => _directionalNavShortcutMap,
case NavigationMode.directional: NavigationMode.traditional => _traditionalNavShortcutMap,
shortcutMap = _directionalNavShortcutMap; };
case NavigationMode.traditional:
shortcutMap = _traditionalNavShortcutMap;
}
final double fontSize = sliderTheme.valueIndicatorTextStyle?.fontSize ?? kDefaultFontSize; final double fontSize = sliderTheme.valueIndicatorTextStyle?.fontSize ?? kDefaultFontSize;
final double fontSizeToScale = fontSize == 0.0 ? kDefaultFontSize : fontSize; final double fontSizeToScale = fontSize == 0.0 ? kDefaultFontSize : fontSize;
...@@ -1386,16 +1383,12 @@ class _RenderSlider extends RenderBox with RelayoutWhenSystemFontsChangeMixin { ...@@ -1386,16 +1383,12 @@ class _RenderSlider extends RenderBox with RelayoutWhenSystemFontsChangeMixin {
} }
bool get showValueIndicator { bool get showValueIndicator {
switch (_sliderTheme.showValueIndicator!) { return switch (_sliderTheme.showValueIndicator!) {
case ShowValueIndicator.onlyForDiscrete: ShowValueIndicator.onlyForDiscrete => isDiscrete,
return isDiscrete; ShowValueIndicator.onlyForContinuous => !isDiscrete,
case ShowValueIndicator.onlyForContinuous: ShowValueIndicator.always => true,
return !isDiscrete; ShowValueIndicator.never => false,
case ShowValueIndicator.always: };
return true;
case ShowValueIndicator.never:
return false;
}
} }
double get _adjustmentUnit { double get _adjustmentUnit {
...@@ -1466,12 +1459,10 @@ class _RenderSlider extends RenderBox with RelayoutWhenSystemFontsChangeMixin { ...@@ -1466,12 +1459,10 @@ class _RenderSlider extends RenderBox with RelayoutWhenSystemFontsChangeMixin {
} }
double _getValueFromVisualPosition(double visualPosition) { double _getValueFromVisualPosition(double visualPosition) {
switch (textDirection) { return switch (textDirection) {
case TextDirection.rtl: TextDirection.rtl => 1.0 - visualPosition,
return 1.0 - visualPosition; TextDirection.ltr => visualPosition,
case TextDirection.ltr: };
return visualPosition;
}
} }
double _getValueFromGlobalPosition(Offset globalPosition) { double _getValueFromGlobalPosition(Offset globalPosition) {
...@@ -1566,12 +1557,10 @@ class _RenderSlider extends RenderBox with RelayoutWhenSystemFontsChangeMixin { ...@@ -1566,12 +1557,10 @@ class _RenderSlider extends RenderBox with RelayoutWhenSystemFontsChangeMixin {
case SliderInteraction.slideThumb: case SliderInteraction.slideThumb:
if (_active && isInteractive) { if (_active && isInteractive) {
final double valueDelta = details.primaryDelta! / _trackRect.width; final double valueDelta = details.primaryDelta! / _trackRect.width;
switch (textDirection) { _currentDragValue += switch (textDirection) {
case TextDirection.rtl: TextDirection.rtl => -valueDelta,
_currentDragValue -= valueDelta; TextDirection.ltr => valueDelta,
case TextDirection.ltr: };
_currentDragValue += valueDelta;
}
onChanged!(_discretize(_currentDragValue)); onChanged!(_discretize(_currentDragValue));
} }
case SliderInteraction.tapOnly: case SliderInteraction.tapOnly:
......
...@@ -1597,16 +1597,10 @@ class RectangularSliderTrackShape extends SliderTrackShape with BaseSliderTrackS ...@@ -1597,16 +1597,10 @@ class RectangularSliderTrackShape extends SliderTrackShape with BaseSliderTrackS
final ColorTween inactiveTrackColorTween = ColorTween(begin: sliderTheme.disabledInactiveTrackColor, end: sliderTheme.inactiveTrackColor); final ColorTween inactiveTrackColorTween = ColorTween(begin: sliderTheme.disabledInactiveTrackColor, end: sliderTheme.inactiveTrackColor);
final Paint activePaint = Paint()..color = activeTrackColorTween.evaluate(enableAnimation)!; final Paint activePaint = Paint()..color = activeTrackColorTween.evaluate(enableAnimation)!;
final Paint inactivePaint = Paint()..color = inactiveTrackColorTween.evaluate(enableAnimation)!; final Paint inactivePaint = Paint()..color = inactiveTrackColorTween.evaluate(enableAnimation)!;
final Paint leftTrackPaint; final (Paint leftTrackPaint, Paint rightTrackPaint) = switch (textDirection) {
final Paint rightTrackPaint; TextDirection.ltr => (activePaint, inactivePaint),
switch (textDirection) { TextDirection.rtl => (inactivePaint, activePaint),
case TextDirection.ltr: };
leftTrackPaint = activePaint;
rightTrackPaint = inactivePaint;
case TextDirection.rtl:
leftTrackPaint = inactivePaint;
rightTrackPaint = activePaint;
}
final Rect trackRect = getPreferredRect( final Rect trackRect = getPreferredRect(
parentBox: parentBox, parentBox: parentBox,
...@@ -1708,16 +1702,10 @@ class RoundedRectSliderTrackShape extends SliderTrackShape with BaseSliderTrackS ...@@ -1708,16 +1702,10 @@ class RoundedRectSliderTrackShape extends SliderTrackShape with BaseSliderTrackS
final ColorTween inactiveTrackColorTween = ColorTween(begin: sliderTheme.disabledInactiveTrackColor, end: sliderTheme.inactiveTrackColor); final ColorTween inactiveTrackColorTween = ColorTween(begin: sliderTheme.disabledInactiveTrackColor, end: sliderTheme.inactiveTrackColor);
final Paint activePaint = Paint()..color = activeTrackColorTween.evaluate(enableAnimation)!; final Paint activePaint = Paint()..color = activeTrackColorTween.evaluate(enableAnimation)!;
final Paint inactivePaint = Paint()..color = inactiveTrackColorTween.evaluate(enableAnimation)!; final Paint inactivePaint = Paint()..color = inactiveTrackColorTween.evaluate(enableAnimation)!;
final Paint leftTrackPaint; final (Paint leftTrackPaint, Paint rightTrackPaint) = switch (textDirection) {
final Paint rightTrackPaint; TextDirection.ltr => (activePaint, inactivePaint),
switch (textDirection) { TextDirection.rtl => (inactivePaint, activePaint),
case TextDirection.ltr: };
leftTrackPaint = activePaint;
rightTrackPaint = inactivePaint;
case TextDirection.rtl:
leftTrackPaint = inactivePaint;
rightTrackPaint = activePaint;
}
final Rect trackRect = getPreferredRect( final Rect trackRect = getPreferredRect(
parentBox: parentBox, parentBox: parentBox,
...@@ -1895,16 +1883,10 @@ class RectangularRangeSliderTrackShape extends RangeSliderTrackShape with BaseRa ...@@ -1895,16 +1883,10 @@ class RectangularRangeSliderTrackShape extends RangeSliderTrackShape with BaseRa
final Paint activePaint = Paint()..color = activeTrackColorTween.evaluate(enableAnimation!)!; final Paint activePaint = Paint()..color = activeTrackColorTween.evaluate(enableAnimation!)!;
final Paint inactivePaint = Paint()..color = inactiveTrackColorTween.evaluate(enableAnimation)!; final Paint inactivePaint = Paint()..color = inactiveTrackColorTween.evaluate(enableAnimation)!;
final Offset leftThumbOffset; final (Offset leftThumbOffset, Offset rightThumbOffset) = switch (textDirection) {
final Offset rightThumbOffset; TextDirection.ltr => (startThumbCenter, endThumbCenter),
switch (textDirection) { TextDirection.rtl => (endThumbCenter, startThumbCenter),
case TextDirection.ltr: };
leftThumbOffset = startThumbCenter;
rightThumbOffset = endThumbCenter;
case TextDirection.rtl:
leftThumbOffset = endThumbCenter;
rightThumbOffset = startThumbCenter;
}
final Rect trackRect = getPreferredRect( final Rect trackRect = getPreferredRect(
parentBox: parentBox, parentBox: parentBox,
...@@ -2001,16 +1983,10 @@ class RoundedRectRangeSliderTrackShape extends RangeSliderTrackShape with BaseRa ...@@ -2001,16 +1983,10 @@ class RoundedRectRangeSliderTrackShape extends RangeSliderTrackShape with BaseRa
final Paint inactivePaint = Paint() final Paint inactivePaint = Paint()
..color = inactiveTrackColorTween.evaluate(enableAnimation)!; ..color = inactiveTrackColorTween.evaluate(enableAnimation)!;
final Offset leftThumbOffset; final (Offset leftThumbOffset, Offset rightThumbOffset) = switch (textDirection) {
final Offset rightThumbOffset; TextDirection.ltr => (startThumbCenter, endThumbCenter),
switch (textDirection) { TextDirection.rtl => (endThumbCenter, startThumbCenter),
case TextDirection.ltr: };
leftThumbOffset = startThumbCenter;
rightThumbOffset = endThumbCenter;
case TextDirection.rtl:
leftThumbOffset = endThumbCenter;
rightThumbOffset = startThumbCenter;
}
final Size thumbSize = sliderTheme.rangeThumbShape!.getPreferredSize(isEnabled, isDiscrete); final Size thumbSize = sliderTheme.rangeThumbShape!.getPreferredSize(isEnabled, isDiscrete);
final double thumbRadius = thumbSize.width / 2; final double thumbRadius = thumbSize.width / 2;
assert(thumbRadius > 0); assert(thumbRadius > 0);
...@@ -2203,13 +2179,10 @@ class RoundRangeSliderTickMarkShape extends RangeSliderTickMarkShape { ...@@ -2203,13 +2179,10 @@ class RoundRangeSliderTickMarkShape extends RangeSliderTickMarkShape {
assert(sliderTheme.activeTickMarkColor != null); assert(sliderTheme.activeTickMarkColor != null);
assert(sliderTheme.inactiveTickMarkColor != null); assert(sliderTheme.inactiveTickMarkColor != null);
final bool isBetweenThumbs; final bool isBetweenThumbs = switch (textDirection) {
switch (textDirection) { TextDirection.ltr => startThumbCenter.dx < center.dx && center.dx < endThumbCenter.dx,
case TextDirection.ltr: TextDirection.rtl => endThumbCenter.dx < center.dx && center.dx < startThumbCenter.dx,
isBetweenThumbs = startThumbCenter.dx < center.dx && center.dx < endThumbCenter.dx; };
case TextDirection.rtl:
isBetweenThumbs = endThumbCenter.dx < center.dx && center.dx < startThumbCenter.dx;
}
final Color? begin = isBetweenThumbs ? sliderTheme.disabledActiveTickMarkColor : sliderTheme.disabledInactiveTickMarkColor; final Color? begin = isBetweenThumbs ? sliderTheme.disabledActiveTickMarkColor : sliderTheme.disabledInactiveTickMarkColor;
final Color? end = isBetweenThumbs ? sliderTheme.activeTickMarkColor : sliderTheme.inactiveTickMarkColor; final Color? end = isBetweenThumbs ? sliderTheme.activeTickMarkColor : sliderTheme.inactiveTickMarkColor;
final Paint paint = Paint()..color = ColorTween(begin: begin, end: end).evaluate(enableAnimation)!; final Paint paint = Paint()..color = ColorTween(begin: begin, end: end).evaluate(enableAnimation)!;
......
...@@ -566,12 +566,10 @@ class Switch extends StatelessWidget { ...@@ -566,12 +566,10 @@ class Switch extends StatelessWidget {
final MaterialTapTargetSize effectiveMaterialTapTargetSize = materialTapTargetSize final MaterialTapTargetSize effectiveMaterialTapTargetSize = materialTapTargetSize
?? switchTheme.materialTapTargetSize ?? switchTheme.materialTapTargetSize
?? theme.materialTapTargetSize; ?? theme.materialTapTargetSize;
switch (effectiveMaterialTapTargetSize) { return switch (effectiveMaterialTapTargetSize) {
case MaterialTapTargetSize.padded: MaterialTapTargetSize.padded => Size(switchConfig.switchWidth, switchConfig.switchHeight),
return Size(switchConfig.switchWidth, switchConfig.switchHeight); MaterialTapTargetSize.shrinkWrap => Size(switchConfig.switchWidth, switchConfig.switchHeightCollapsed),
case MaterialTapTargetSize.shrinkWrap: };
return Size(switchConfig.switchWidth, switchConfig.switchHeightCollapsed);
}
} }
@override @override
...@@ -815,12 +813,10 @@ class _MaterialSwitchState extends State<_MaterialSwitch> with TickerProviderSta ...@@ -815,12 +813,10 @@ class _MaterialSwitchState extends State<_MaterialSwitch> with TickerProviderSta
..curve = Curves.linear ..curve = Curves.linear
..reverseCurve = null; ..reverseCurve = null;
final double delta = details.primaryDelta! / _trackInnerLength; final double delta = details.primaryDelta! / _trackInnerLength;
switch (Directionality.of(context)) { positionController.value += switch (Directionality.of(context)) {
case TextDirection.rtl: TextDirection.rtl => -delta,
positionController.value -= delta; TextDirection.ltr => delta,
case TextDirection.ltr: };
positionController.value += delta;
}
} }
} }
...@@ -1422,13 +1418,10 @@ class _SwitchPainter extends ToggleablePainter { ...@@ -1422,13 +1418,10 @@ class _SwitchPainter extends ToggleablePainter {
void paint(Canvas canvas, Size size) { void paint(Canvas canvas, Size size) {
final double currentValue = position.value; final double currentValue = position.value;
final double visualPosition; final double visualPosition = switch (textDirection) {
switch (textDirection) { TextDirection.rtl => 1.0 - currentValue,
case TextDirection.rtl: TextDirection.ltr => currentValue,
visualPosition = 1.0 - currentValue; };
case TextDirection.ltr:
visualPosition = currentValue;
}
if (reaction.status == AnimationStatus.reverse && !_stopPressAnimation) { if (reaction.status == AnimationStatus.reverse && !_stopPressAnimation) {
_stopPressAnimation = true; _stopPressAnimation = true;
} else { } else {
......
...@@ -563,15 +563,10 @@ class SwitchListTile extends StatelessWidget { ...@@ -563,15 +563,10 @@ class SwitchListTile extends StatelessWidget {
} }
Widget? leading, trailing; Widget? leading, trailing;
switch (controlAffinity) { (leading, trailing) = switch (controlAffinity) {
case ListTileControlAffinity.leading: ListTileControlAffinity.leading => (control, secondary),
leading = control; ListTileControlAffinity.trailing || ListTileControlAffinity.platform => (secondary, control),
trailing = secondary; };
case ListTileControlAffinity.trailing:
case ListTileControlAffinity.platform:
leading = secondary;
trailing = control;
}
final ThemeData theme = Theme.of(context); final ThemeData theme = Theme.of(context);
final SwitchThemeData switchTheme = SwitchTheme.of(context); final SwitchThemeData switchTheme = SwitchTheme.of(context);
......
...@@ -511,14 +511,10 @@ class _IndicatorPainter extends CustomPainter { ...@@ -511,14 +511,10 @@ class _IndicatorPainter extends CustomPainter {
assert(tabIndex >= 0); assert(tabIndex >= 0);
assert(tabIndex <= maxTabIndex); assert(tabIndex <= maxTabIndex);
double tabLeft, tabRight; double tabLeft, tabRight;
switch (_currentTextDirection!) { (tabLeft, tabRight) = switch (_currentTextDirection!) {
case TextDirection.rtl: TextDirection.rtl => (_currentTabOffsets![tabIndex + 1], _currentTabOffsets![tabIndex]),
tabLeft = _currentTabOffsets![tabIndex + 1]; TextDirection.ltr => (_currentTabOffsets![tabIndex], _currentTabOffsets![tabIndex + 1]),
tabRight = _currentTabOffsets![tabIndex]; };
case TextDirection.ltr:
tabLeft = _currentTabOffsets![tabIndex];
tabRight = _currentTabOffsets![tabIndex + 1];
}
if (indicatorSize == TabBarIndicatorSize.label) { if (indicatorSize == TabBarIndicatorSize.label) {
final double tabWidth = tabKeys[tabIndex].currentContext!.size!.width; final double tabWidth = tabKeys[tabIndex].currentContext!.size!.width;
......
...@@ -1092,12 +1092,10 @@ class _TextFieldState extends State<TextField> with RestorationMixin implements ...@@ -1092,12 +1092,10 @@ class _TextFieldState extends State<TextField> with RestorationMixin implements
bool get _canRequestFocus { bool get _canRequestFocus {
final NavigationMode mode = MediaQuery.maybeNavigationModeOf(context) ?? NavigationMode.traditional; final NavigationMode mode = MediaQuery.maybeNavigationModeOf(context) ?? NavigationMode.traditional;
switch (mode) { return switch (mode) {
case NavigationMode.traditional: NavigationMode.traditional => widget.canRequestFocus && _isEnabled,
return widget.canRequestFocus && _isEnabled; NavigationMode.directional => true,
case NavigationMode.directional: };
return true;
}
} }
@override @override
......
...@@ -113,14 +113,11 @@ class MaterialTextSelectionControls extends TextSelectionControls { ...@@ -113,14 +113,11 @@ class MaterialTextSelectionControls extends TextSelectionControls {
/// See [TextSelectionControls.getHandleAnchor]. /// See [TextSelectionControls.getHandleAnchor].
@override @override
Offset getHandleAnchor(TextSelectionHandleType type, double textLineHeight) { Offset getHandleAnchor(TextSelectionHandleType type, double textLineHeight) {
switch (type) { return switch (type) {
case TextSelectionHandleType.left: TextSelectionHandleType.collapsed => const Offset(_kHandleSize / 2, -4),
return const Offset(_kHandleSize, 0); TextSelectionHandleType.left => const Offset(_kHandleSize, 0),
case TextSelectionHandleType.right: TextSelectionHandleType.right => Offset.zero,
return Offset.zero; };
case TextSelectionHandleType.collapsed:
return const Offset(_kHandleSize / 2, -4);
}
} }
@Deprecated( @Deprecated(
......
...@@ -613,12 +613,10 @@ class _DayPeriodControl extends StatelessWidget { ...@@ -613,12 +613,10 @@ class _DayPeriodControl extends StatelessWidget {
case TimePickerEntryMode.dial: case TimePickerEntryMode.dial:
case TimePickerEntryMode.dialOnly: case TimePickerEntryMode.dialOnly:
orientation = _TimePickerModel.orientationOf(context); orientation = _TimePickerModel.orientationOf(context);
switch (orientation) { dayPeriodSize = switch (orientation) {
case Orientation.portrait: Orientation.portrait => defaultTheme.dayPeriodPortraitSize,
dayPeriodSize = defaultTheme.dayPeriodPortraitSize; Orientation.landscape => defaultTheme.dayPeriodLandscapeSize,
case Orientation.landscape: };
dayPeriodSize = defaultTheme.dayPeriodLandscapeSize;
}
case TimePickerEntryMode.input: case TimePickerEntryMode.input:
case TimePickerEntryMode.inputOnly: case TimePickerEntryMode.inputOnly:
orientation = Orientation.portrait; orientation = Orientation.portrait;
...@@ -843,20 +841,12 @@ class _RenderInputPadding extends RenderShiftedBox { ...@@ -843,20 +841,12 @@ class _RenderInputPadding extends RenderShiftedBox {
} }
Offset newPosition = child!.size.center(Offset.zero); Offset newPosition = child!.size.center(Offset.zero);
switch (orientation) { newPosition += switch (orientation) {
case Orientation.portrait: Orientation.portrait when position.dy > newPosition.dy => const Offset(0, 1),
if (position.dy > newPosition.dy) { Orientation.landscape when position.dx > newPosition.dx => const Offset(1, 0),
newPosition += const Offset(0, 1); Orientation.portrait => const Offset(0, -1),
} else { Orientation.landscape => const Offset(-1, 0),
newPosition += const Offset(0, -1); };
}
case Orientation.landscape:
if (position.dx > newPosition.dx) {
newPosition += const Offset(1, 0);
} else {
newPosition += const Offset(-1, 0);
}
}
return result.addWithRawTransform( return result.addWithRawTransform(
transform: MatrixUtils.forceToPoint(newPosition), transform: MatrixUtils.forceToPoint(newPosition),
...@@ -1159,22 +1149,15 @@ class _DialState extends State<_Dial> with SingleTickerProviderStateMixin { ...@@ -1159,22 +1149,15 @@ class _DialState extends State<_Dial> with SingleTickerProviderStateMixin {
} }
double _getThetaForTime(TimeOfDay time) { double _getThetaForTime(TimeOfDay time) {
final int hoursFactor; final int hoursFactor = switch (widget.hourDialType) {
switch (widget.hourDialType) { _HourDialType.twentyFourHour => TimeOfDay.hoursPerDay,
case _HourDialType.twentyFourHour: _HourDialType.twentyFourHourDoubleRing => TimeOfDay.hoursPerPeriod,
hoursFactor = TimeOfDay.hoursPerDay; _HourDialType.twelveHour => TimeOfDay.hoursPerPeriod,
case _HourDialType.twentyFourHourDoubleRing: };
hoursFactor = TimeOfDay.hoursPerPeriod; final double fraction = switch (widget.hourMinuteMode) {
case _HourDialType.twelveHour: _HourMinuteMode.hour => (time.hour / hoursFactor) % hoursFactor,
hoursFactor = TimeOfDay.hoursPerPeriod; _HourMinuteMode.minute => (time.minute / TimeOfDay.minutesPerHour) % TimeOfDay.minutesPerHour,
} };
final double fraction;
switch (widget.hourMinuteMode) {
case _HourMinuteMode.hour:
fraction = (time.hour / hoursFactor) % hoursFactor;
case _HourMinuteMode.minute:
fraction = (time.minute / TimeOfDay.minutesPerHour) % TimeOfDay.minutesPerHour;
}
return (math.pi / 2 - fraction * _kTwoPi) % _kTwoPi; return (math.pi / 2 - fraction * _kTwoPi) % _kTwoPi;
} }
...@@ -1302,12 +1285,10 @@ class _DialState extends State<_Dial> with SingleTickerProviderStateMixin { ...@@ -1302,12 +1285,10 @@ class _DialState extends State<_Dial> with SingleTickerProviderStateMixin {
final TimeOfDay time; final TimeOfDay time;
TimeOfDay getAmPmTime() { TimeOfDay getAmPmTime() {
switch (widget.selectedTime.period) { return switch (widget.selectedTime.period) {
case DayPeriod.am: DayPeriod.am => TimeOfDay(hour: hour, minute: widget.selectedTime.minute),
return TimeOfDay(hour: hour, minute: widget.selectedTime.minute); DayPeriod.pm => TimeOfDay(hour: hour + TimeOfDay.hoursPerPeriod, minute: widget.selectedTime.minute),
case DayPeriod.pm: };
return TimeOfDay(hour: hour + TimeOfDay.hoursPerPeriod, minute: widget.selectedTime.minute);
}
} }
switch (widget.hourMinuteMode) { switch (widget.hourMinuteMode) {
...@@ -2317,12 +2298,10 @@ class _TimePickerDialogState extends State<TimePickerDialog> with RestorationMix ...@@ -2317,12 +2298,10 @@ class _TimePickerDialogState extends State<TimePickerDialog> with RestorationMix
switch (_entryMode.value) { switch (_entryMode.value) {
case TimePickerEntryMode.dial: case TimePickerEntryMode.dial:
case TimePickerEntryMode.dialOnly: case TimePickerEntryMode.dialOnly:
switch (orientation) { return switch (orientation) {
case Orientation.portrait: Orientation.portrait => _kTimePickerMinPortraitSize,
return _kTimePickerMinPortraitSize; Orientation.landscape => _kTimePickerMinLandscapeSize,
case Orientation.landscape: };
return _kTimePickerMinLandscapeSize;
}
case TimePickerEntryMode.input: case TimePickerEntryMode.input:
case TimePickerEntryMode.inputOnly: case TimePickerEntryMode.inputOnly:
final MaterialLocalizations localizations = MaterialLocalizations.of(context); final MaterialLocalizations localizations = MaterialLocalizations.of(context);
...@@ -2444,14 +2423,11 @@ class _TimePickerDialogState extends State<TimePickerDialog> with RestorationMix ...@@ -2444,14 +2423,11 @@ class _TimePickerDialogState extends State<TimePickerDialog> with RestorationMix
), ),
); );
final Offset tapTargetSizeOffset; final Offset tapTargetSizeOffset = switch (theme.materialTapTargetSize) {
switch (theme.materialTapTargetSize) { MaterialTapTargetSize.padded => Offset.zero,
case MaterialTapTargetSize.padded: // _dialogSize returns "padded" sizes.
tapTargetSizeOffset = Offset.zero; MaterialTapTargetSize.shrinkWrap => const Offset(0, -12),
case MaterialTapTargetSize.shrinkWrap: };
// _dialogSize returns "padded" sizes.
tapTargetSizeOffset = const Offset(0, -12);
}
final Size dialogSize = _dialogSize(context, useMaterial3: theme.useMaterial3) + tapTargetSizeOffset; final Size dialogSize = _dialogSize(context, useMaterial3: theme.useMaterial3) + tapTargetSizeOffset;
final Size minDialogSize = _minDialogSize(context, useMaterial3: theme.useMaterial3) + tapTargetSizeOffset; final Size minDialogSize = _minDialogSize(context, useMaterial3: theme.useMaterial3) + tapTargetSizeOffset;
return Dialog( return Dialog(
...@@ -2794,18 +2770,10 @@ class _TimePickerState extends State<_TimePicker> with RestorationMixin { ...@@ -2794,18 +2770,10 @@ class _TimePickerState extends State<_TimePicker> with RestorationMixin {
? localizations.timePickerDialHelpText ? localizations.timePickerDialHelpText
: localizations.timePickerDialHelpText.toUpperCase()); : localizations.timePickerDialHelpText.toUpperCase());
final EdgeInsetsGeometry dialPadding; final EdgeInsetsGeometry dialPadding = switch (orientation) {
switch (orientation) { Orientation.portrait => const EdgeInsets.only(left: 12, right: 12, top: 36),
case Orientation.portrait: Orientation.landscape => const EdgeInsetsDirectional.only(start: 64),
dialPadding = const EdgeInsets.only(left: 12, right: 12, top: 36); };
case Orientation.landscape:
switch (theme.materialTapTargetSize) {
case MaterialTapTargetSize.padded:
dialPadding = const EdgeInsetsDirectional.only(start: 64);
case MaterialTapTargetSize.shrinkWrap:
dialPadding = const EdgeInsetsDirectional.only(start: 64);
}
}
final Widget dial = Padding( final Widget dial = Padding(
padding: dialPadding, padding: dialPadding,
child: ExcludeSemantics( child: ExcludeSemantics(
......
...@@ -1213,19 +1213,15 @@ class _SelectToggleButtonRenderObject extends RenderShiftedBox { ...@@ -1213,19 +1213,15 @@ class _SelectToggleButtonRenderObject extends RenderShiftedBox {
} }
final BoxParentData childParentData = child!.parentData! as BoxParentData; final BoxParentData childParentData = child!.parentData! as BoxParentData;
if (direction == Axis.horizontal) { if (direction == Axis.horizontal) {
switch (textDirection) { childParentData.offset = switch (textDirection) {
case TextDirection.ltr: TextDirection.ltr => Offset(leadingBorderSide.width, borderSide.width),
childParentData.offset = Offset(leadingBorderSide.width, borderSide.width); TextDirection.rtl => Offset(trailingBorderSide.width, borderSide.width),
case TextDirection.rtl: };
childParentData.offset = Offset(trailingBorderSide.width, borderSide.width);
}
} else { } else {
switch (verticalDirection) { childParentData.offset = switch (verticalDirection) {
case VerticalDirection.down: VerticalDirection.down => Offset(borderSide.width, leadingBorderSide.width),
childParentData.offset = Offset(borderSide.width, leadingBorderSide.width); VerticalDirection.up => Offset(borderSide.width, trailingBorderSide.width),
case VerticalDirection.up: };
childParentData.offset = Offset(borderSide.width, trailingBorderSide.width);
}
} }
} }
......
...@@ -292,14 +292,11 @@ class Typography with Diagnosticable { ...@@ -292,14 +292,11 @@ class Typography with Diagnosticable {
/// Returns one of [englishLike], [dense], or [tall]. /// Returns one of [englishLike], [dense], or [tall].
TextTheme geometryThemeFor(ScriptCategory category) { TextTheme geometryThemeFor(ScriptCategory category) {
switch (category) { return switch (category) {
case ScriptCategory.englishLike: ScriptCategory.englishLike => englishLike,
return englishLike; ScriptCategory.dense => dense,
case ScriptCategory.dense: ScriptCategory.tall => tall,
return dense; };
case ScriptCategory.tall:
return tall;
}
} }
/// Creates a copy of this [Typography] with the given fields /// Creates a copy of this [Typography] with the given fields
......
...@@ -253,32 +253,26 @@ class _AccountDetailsLayout extends MultiChildLayoutDelegate { ...@@ -253,32 +253,26 @@ class _AccountDetailsLayout extends MultiChildLayoutDelegate {
bool shouldRelayout(MultiChildLayoutDelegate oldDelegate) => true; bool shouldRelayout(MultiChildLayoutDelegate oldDelegate) => true;
Offset _offsetForIcon(Size size, Size iconSize) { Offset _offsetForIcon(Size size, Size iconSize) {
switch (textDirection) { return switch (textDirection) {
case TextDirection.ltr: TextDirection.ltr => Offset(size.width - iconSize.width, size.height - iconSize.height),
return Offset(size.width - iconSize.width, size.height - iconSize.height); TextDirection.rtl => Offset(0.0, size.height - iconSize.height),
case TextDirection.rtl: };
return Offset(0.0, size.height - iconSize.height);
}
} }
Offset _offsetForBottomLine(Size size, Size iconSize, Size bottomLineSize) { Offset _offsetForBottomLine(Size size, Size iconSize, Size bottomLineSize) {
final double y = size.height - 0.5 * iconSize.height - 0.5 * bottomLineSize.height; final double y = size.height - 0.5 * iconSize.height - 0.5 * bottomLineSize.height;
switch (textDirection) { return switch (textDirection) {
case TextDirection.ltr: TextDirection.ltr => Offset(0.0, y),
return Offset(0.0, y); TextDirection.rtl => Offset(size.width - bottomLineSize.width, y),
case TextDirection.rtl: };
return Offset(size.width - bottomLineSize.width, y);
}
} }
Offset _offsetForName(Size size, Size nameSize, Offset bottomLineOffset) { Offset _offsetForName(Size size, Size nameSize, Offset bottomLineOffset) {
final double y = bottomLineOffset.dy - nameSize.height; final double y = bottomLineOffset.dy - nameSize.height;
switch (textDirection) { return switch (textDirection) {
case TextDirection.ltr: TextDirection.ltr => Offset(0.0, y),
return Offset(0.0, y); TextDirection.rtl => Offset(size.width - nameSize.width, y),
case TextDirection.rtl: };
return Offset(size.width - nameSize.width, y);
}
} }
} }
......
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