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