flutter/lib/src/: refactoring if-chains into switch expressions (#147472)

Cleans up some code by porting if chains to switch statements.
This commit is contained in:
Nate
2024-05-01 13:58:35 -06:00
committed by GitHub
parent 5a41e1edac
commit 586e1fce1b
25 changed files with 196 additions and 276 deletions

View File

@@ -886,13 +886,11 @@ class _InterpolationSimulation extends Simulation {
@override
double x(double timeInSeconds) {
final double t = clampDouble(timeInSeconds / _durationInSeconds, 0.0, 1.0);
if (t == 0.0) {
return _begin;
} else if (t == 1.0) {
return _end;
} else {
return _begin + (_end - _begin) * _curve.transform(t);
}
return switch (t) {
0.0 => _begin,
1.0 => _end,
_ => _begin + (_end - _begin) * _curve.transform(t),
};
}
@override

View File

@@ -1298,15 +1298,14 @@ class _ContextMenuRouteStaticState extends State<_ContextMenuRouteStatic> with T
child: AnimatedBuilder(
animation: _moveController,
builder: _buildAnimation,
child: widget.orientation == Orientation.portrait
? Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: children,
)
: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: children,
),
child: Flex(
direction: switch (widget.orientation) {
Orientation.portrait => Axis.vertical,
Orientation.landscape => Axis.horizontal,
},
crossAxisAlignment: CrossAxisAlignment.start,
children: children,
),
),
),
),

View File

@@ -251,37 +251,20 @@ class _CupertinoListTileState extends State<CupertinoListTile> {
@override
Widget build(BuildContext context) {
final TextStyle titleTextStyle =
widget._type == _CupertinoListTileType.base || widget.subtitle == null
? CupertinoTheme.of(context).textTheme.textStyle
: CupertinoTheme.of(context).textTheme.textStyle.merge(
TextStyle(
fontWeight: FontWeight.w600,
fontSize: widget.leading == null ? _kNotchedTitleWithSubtitleFontSize : null,
),
);
final TextStyle subtitleTextStyle = widget._type == _CupertinoListTileType.base
? CupertinoTheme.of(context).textTheme.textStyle.merge(
TextStyle(
fontSize: _kSubtitleFontSize,
color: CupertinoColors.secondaryLabel.resolveFrom(context),
),
)
: CupertinoTheme.of(context).textTheme.textStyle.merge(
TextStyle(
fontSize: _kNotchedSubtitleFontSize,
color: CupertinoColors.secondaryLabel.resolveFrom(context),
),
);
final TextStyle? additionalInfoTextStyle = widget.additionalInfo != null
? CupertinoTheme.of(context).textTheme.textStyle.merge(
TextStyle(color: CupertinoColors.secondaryLabel.resolveFrom(context)))
: null;
final TextStyle textStyle = CupertinoTheme.of(context).textTheme.textStyle;
final TextStyle coloredStyle = textStyle.copyWith(
color: CupertinoColors.secondaryLabel.resolveFrom(context),
);
final bool baseType = switch (widget._type) {
_CupertinoListTileType.base => true,
_CupertinoListTileType.notched => false,
};
final Widget title = DefaultTextStyle(
style: titleTextStyle,
style: baseType || widget.subtitle == null ? textStyle : textStyle.copyWith(
fontWeight: FontWeight.w600,
fontSize: widget.leading == null ? _kNotchedTitleWithSubtitleFontSize : null,
),
maxLines: 1,
overflow: TextOverflow.ellipsis,
child: widget.title,
@@ -294,25 +277,6 @@ class _CupertinoListTileState extends State<CupertinoListTile> {
_CupertinoListTileType.notched => _kNotchedPaddingWithoutLeading,
};
Widget? subtitle;
if (widget.subtitle != null) {
subtitle = DefaultTextStyle(
style: subtitleTextStyle,
maxLines: 1,
overflow: TextOverflow.ellipsis,
child: widget.subtitle!,
);
}
Widget? additionalInfo;
if (widget.additionalInfo != null) {
additionalInfo = DefaultTextStyle(
style: additionalInfoTextStyle!,
maxLines: 1,
child: widget.additionalInfo!,
);
}
// The color for default state tile is set to either what user provided or
// null and it will resolve to the correct color provided by context. But if
// the tile was tapped, it is set to what user provided or if null to the
@@ -323,7 +287,7 @@ class _CupertinoListTileState extends State<CupertinoListTile> {
}
final double minHeight = switch (widget._type) {
_CupertinoListTileType.base when subtitle != null => _kMinHeightWithSubtitle,
_CupertinoListTileType.base when widget.subtitle != null => _kMinHeightWithSubtitle,
_CupertinoListTileType.notched when widget.leading != null => _kNotchedMinHeight,
_CupertinoListTileType.base => _kMinHeight,
_CupertinoListTileType.notched => _kNotchedMinHeightWithoutLeading,
@@ -336,13 +300,10 @@ class _CupertinoListTileState extends State<CupertinoListTile> {
padding: padding,
child: Row(
children: <Widget>[
if (widget.leading != null) ...<Widget>[
SizedBox(
width: widget.leadingSize,
height: widget.leadingSize,
child: Center(
child: widget.leading,
),
if (widget.leading case final Widget leading) ...<Widget>[
SizedBox.square(
dimension: widget.leadingSize,
child: Center(child: leading),
),
SizedBox(width: widget.leadingToTitle),
] else
@@ -353,15 +314,28 @@ class _CupertinoListTileState extends State<CupertinoListTile> {
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
title,
if (subtitle != null) ...<Widget>[
if (widget.subtitle case final Widget subtitle) ...<Widget>[
const SizedBox(height: _kNotchedTitleToSubtitle),
subtitle,
DefaultTextStyle(
style: coloredStyle.copyWith(
fontSize: baseType
? _kSubtitleFontSize
: _kNotchedSubtitleFontSize,
),
maxLines: 1,
overflow: TextOverflow.ellipsis,
child: subtitle,
),
],
],
),
),
if (additionalInfo != null) ...<Widget>[
additionalInfo,
if (widget.additionalInfo case final Widget additionalInfo) ...<Widget>[
DefaultTextStyle(
style: coloredStyle,
maxLines: 1,
child: additionalInfo,
),
if (widget.trailing != null)
const SizedBox(width: _kAdditionalInfoToTrailing),
],

View File

@@ -718,17 +718,17 @@ class _CupertinoBackGestureDetectorState<T> extends State<_CupertinoBackGestureD
assert(debugCheckHasDirectionality(context));
// For devices with notches, the drag area needs to be larger on the side
// that has the notch.
double dragAreaWidth = Directionality.of(context) == TextDirection.ltr ?
MediaQuery.paddingOf(context).left :
MediaQuery.paddingOf(context).right;
dragAreaWidth = max(dragAreaWidth, _kBackGestureWidth);
final double dragAreaWidth = switch (Directionality.of(context)) {
TextDirection.rtl => MediaQuery.paddingOf(context).right,
TextDirection.ltr => MediaQuery.paddingOf(context).left,
};
return Stack(
fit: StackFit.passthrough,
children: <Widget>[
widget.child,
PositionedDirectional(
start: 0.0,
width: dragAreaWidth,
width: max(dragAreaWidth, _kBackGestureWidth),
top: 0.0,
bottom: 0.0,
child: Listener(

View File

@@ -607,14 +607,12 @@ abstract class DragGestureRecognizer extends OneSequenceGestureRecognizer {
event is PointerMoveEvent ||
event is PointerPanZoomStartEvent ||
event is PointerPanZoomUpdateEvent)) {
final VelocityTracker tracker = _velocityTrackers[event.pointer]!;
if (event is PointerPanZoomStartEvent) {
tracker.addPosition(event.timeStamp, Offset.zero);
} else if (event is PointerPanZoomUpdateEvent) {
tracker.addPosition(event.timeStamp, event.pan);
} else {
tracker.addPosition(event.timeStamp, event.localPosition);
}
final Offset position = switch (event) {
PointerPanZoomStartEvent() => Offset.zero,
PointerPanZoomUpdateEvent() => event.pan,
_ => event.localPosition,
};
_velocityTrackers[event.pointer]!.addPosition(event.timeStamp, position);
}
if (event is PointerMoveEvent && event.buttons != _initialButtons) {
_giveUpPointer(event.pointer);

View File

@@ -325,10 +325,10 @@ class _CalendarDatePickerState extends State<CalendarDatePicker> {
_DatePickerModeToggleButton(
mode: _mode,
title: _localizations.formatMonthYear(_currentDisplayedMonthDate),
onTitlePressed: () {
// Toggle the day/year mode.
_handleModeChanged(_mode == DatePickerMode.day ? DatePickerMode.year : DatePickerMode.day);
},
onTitlePressed: () => _handleModeChanged(switch (_mode) {
DatePickerMode.day => DatePickerMode.year,
DatePickerMode.year => DatePickerMode.day,
}),
),
],
);

View File

@@ -765,10 +765,10 @@ class _CheckboxPainter extends ToggleablePainter {
final Paint strokePaint = _createStrokePaint();
final Offset origin = size / 2.0 - const Size.square(_kEdgeSize) / 2.0 as Offset;
final AnimationStatus status = position.status;
final double tNormalized = status == AnimationStatus.forward || status == AnimationStatus.completed
? position.value
: 1.0 - position.value;
final double tNormalized = switch (position.status) {
AnimationStatus.forward || AnimationStatus.completed => position.value,
AnimationStatus.reverse || AnimationStatus.dismissed => 1.0 - position.value,
};
// Four cases: false to null, false to true, null to false, true to false
if (previousValue == false || value == false) {

View File

@@ -2824,11 +2824,10 @@ class _InputDateRangePickerDialog extends StatelessWidget {
if (start == null || end == null) {
return localizations.unspecifiedDateRange;
}
if (Directionality.of(context) == TextDirection.ltr) {
return '$startText – $endText';
} else {
return '$endText – $startText';
}
return switch (Directionality.of(context)) {
TextDirection.rtl => '$endText – $startText',
TextDirection.ltr => '$startText – $endText',
};
}
@override

View File

@@ -970,16 +970,14 @@ class _IconButtonM3 extends ButtonStyleButton {
@override
ButtonStyle? themeStyleOf(BuildContext context) {
final IconThemeData iconTheme = IconTheme.of(context);
final bool isDark = Theme.of(context).brightness == Brightness.dark;
bool isIconThemeDefault(Color? color) {
if (isDark) {
return identical(color, kDefaultIconLightColor);
}
return identical(color, kDefaultIconDarkColor);
}
final bool isDefaultColor = isIconThemeDefault(iconTheme.color);
final bool isDefaultSize = iconTheme.size == const IconThemeData.fallback().size;
final bool isDefaultColor = identical(
iconTheme.color,
switch (Theme.of(context).brightness) {
Brightness.light => kDefaultIconDarkColor,
Brightness.dark => kDefaultIconLightColor,
},
);
final ButtonStyle iconThemeStyle = IconButton.styleFrom(
foregroundColor: isDefaultColor ? null : iconTheme.color,

View File

@@ -236,14 +236,12 @@ class Ink extends StatefulWidget {
final double? height;
EdgeInsetsGeometry get _paddingIncludingDecoration {
if (decoration == null) {
return padding ?? EdgeInsets.zero;
}
final EdgeInsetsGeometry decorationPadding = decoration!.padding;
if (padding == null) {
return decorationPadding;
}
return padding!.add(decorationPadding);
return switch ((padding, decoration?.padding)) {
(null, null) => EdgeInsets.zero,
(null, final EdgeInsetsGeometry padding) => padding,
(final EdgeInsetsGeometry padding, null) => padding,
_ => padding!.add(decoration!.padding),
};
}
@override

View File

@@ -287,13 +287,11 @@ class _Shaker extends AnimatedWidget {
double get translateX {
const double shakeDelta = 4.0;
final double t = animation.value;
if (t <= 0.25) {
return -t * shakeDelta;
} else if (t < 0.75) {
return (t - 0.5) * shakeDelta;
} else {
return (1.0 - t) * 4.0 * shakeDelta;
}
return shakeDelta * switch (t) {
<= 0.25 => -t,
< 0.75 => t - 0.5,
_ => (1.0 - t) * 4.0,
};
}
@override

View File

@@ -271,10 +271,10 @@ class _MaterialScrollbarState extends RawScrollbarState<_MaterialScrollbar> {
final Brightness brightness = _colorScheme.brightness;
return MaterialStateProperty.resolveWith((Set<MaterialState> states) {
if (showScrollbar && _trackVisibility.resolve(states)) {
return _scrollbarTheme.trackColor?.resolve(states)
?? (brightness == Brightness.light
? onSurface.withOpacity(0.03)
: onSurface.withOpacity(0.05));
return _scrollbarTheme.trackColor?.resolve(states) ?? switch (brightness) {
Brightness.light => onSurface.withOpacity(0.03),
Brightness.dark => onSurface.withOpacity(0.05),
};
}
return const Color(0x00000000);
});
@@ -285,10 +285,10 @@ class _MaterialScrollbarState extends RawScrollbarState<_MaterialScrollbar> {
final Brightness brightness = _colorScheme.brightness;
return MaterialStateProperty.resolveWith((Set<MaterialState> states) {
if (showScrollbar && _trackVisibility.resolve(states)) {
return _scrollbarTheme.trackBorderColor?.resolve(states)
?? (brightness == Brightness.light
? onSurface.withOpacity(0.1)
: onSurface.withOpacity(0.25));
return _scrollbarTheme.trackBorderColor?.resolve(states) ?? switch (brightness) {
Brightness.light => onSurface.withOpacity(0.1),
Brightness.dark => onSurface.withOpacity(0.25),
};
}
return const Color(0x00000000);
});

View File

@@ -1323,7 +1323,6 @@ class _SearchBarState extends State<SearchBar> {
Widget build(BuildContext context) {
final TextDirection textDirection = Directionality.of(context);
final ColorScheme colorScheme = Theme.of(context).colorScheme;
final IconThemeData iconTheme = IconTheme.of(context);
final SearchBarThemeData searchBarTheme = SearchBarTheme.of(context);
final SearchBarThemeData defaults = _SearchBarDefaultsM3(context);
@@ -1354,33 +1353,27 @@ class _SearchBarState extends State<SearchBar> {
?? searchBarTheme.textStyle?.resolve(states)
?? defaults.hintStyle?.resolve(states);
final bool isDark = Theme.of(context).brightness == Brightness.dark;
bool isIconThemeColorDefault(Color? color) {
if (isDark) {
return color == kDefaultIconLightColor;
}
return color == kDefaultIconDarkColor;
}
final Color defaultColor = switch (colorScheme.brightness) {
Brightness.light => kDefaultIconDarkColor,
Brightness.dark => kDefaultIconLightColor,
};
final IconThemeData? customTheme = switch (IconTheme.of(context)) {
final IconThemeData iconTheme when iconTheme.color != defaultColor => iconTheme,
_ => null,
};
Widget? leading;
if (widget.leading != null) {
leading = IconTheme.merge(
data: isIconThemeColorDefault(iconTheme.color)
? IconThemeData(color: colorScheme.onSurface)
: iconTheme,
data: customTheme ?? IconThemeData(color: colorScheme.onSurface),
child: widget.leading!,
);
}
List<Widget>? trailing;
if (widget.trailing != null) {
trailing = widget.trailing?.map((Widget trailing) => IconTheme.merge(
data: isIconThemeColorDefault(iconTheme.color)
? IconThemeData(color: colorScheme.onSurfaceVariant)
: iconTheme,
child: trailing,
)).toList();
}
final List<Widget>? trailing = widget.trailing?.map((Widget trailing) => IconTheme.merge(
data: customTheme ?? IconThemeData(color: colorScheme.onSurfaceVariant),
child: trailing,
)).toList();
return ConstrainedBox(
constraints: widget.constraints ?? searchBarTheme.constraints ?? defaults.constraints!,
@@ -1444,7 +1437,7 @@ class _SearchBarState extends State<SearchBar> {
),
),
),
if (trailing != null) ...trailing,
...?trailing,
],
),
),

View File

@@ -504,11 +504,10 @@ abstract final class MatrixUtils {
// Model matrix by first translating the object from the origin of the world
// by radius in the z axis and then rotating against the world.
result = result * ((
orientation == Axis.horizontal
? Matrix4.rotationY(angle)
: Matrix4.rotationX(angle)
) * Matrix4.translationValues(0.0, 0.0, radius)) as Matrix4;
result = result * (switch (orientation) {
Axis.horizontal => Matrix4.rotationY(angle),
Axis.vertical => Matrix4.rotationX(angle),
} * Matrix4.translationValues(0.0, 0.0, radius)) as Matrix4;
// Essentially perspective * view * model.
return result;

View File

@@ -184,22 +184,20 @@ class ShapeDecoration extends Decoration {
@override
ShapeDecoration? lerpFrom(Decoration? a, double t) {
if (a is BoxDecoration) {
return ShapeDecoration.lerp(ShapeDecoration.fromBoxDecoration(a), this, t);
} else if (a == null || a is ShapeDecoration) {
return ShapeDecoration.lerp(a as ShapeDecoration?, this, t);
}
return super.lerpFrom(a, t) as ShapeDecoration?;
return switch (a) {
BoxDecoration() => ShapeDecoration.lerp(ShapeDecoration.fromBoxDecoration(a), this, t),
ShapeDecoration? _ => ShapeDecoration.lerp(a, this, t),
_ => super.lerpFrom(a, t) as ShapeDecoration?,
};
}
@override
ShapeDecoration? lerpTo(Decoration? b, double t) {
if (b is BoxDecoration) {
return ShapeDecoration.lerp(this, ShapeDecoration.fromBoxDecoration(b), t);
} else if (b == null || b is ShapeDecoration) {
return ShapeDecoration.lerp(this, b as ShapeDecoration?, t);
}
return super.lerpTo(b, t) as ShapeDecoration?;
return switch (b) {
BoxDecoration() => ShapeDecoration.lerp(this, ShapeDecoration.fromBoxDecoration(b), t),
ShapeDecoration? _ => ShapeDecoration.lerp(this, b, t),
_ => super.lerpTo(b, t) as ShapeDecoration?,
};
}
/// Linearly interpolate between two shapes.

View File

@@ -680,10 +680,10 @@ class RenderFlex extends RenderBox with ContainerRenderObjectMixin<RenderBox, Fl
@override
double? computeDistanceToActualBaseline(TextBaseline baseline) {
if (_direction == Axis.horizontal) {
return defaultComputeDistanceToHighestActualBaseline(baseline);
}
return defaultComputeDistanceToFirstActualBaseline(baseline);
return switch (_direction) {
Axis.horizontal => defaultComputeDistanceToHighestActualBaseline(baseline),
Axis.vertical => defaultComputeDistanceToFirstActualBaseline(baseline),
};
}
static int _getFlex(RenderBox child) {

View File

@@ -3497,26 +3497,21 @@ class RenderRepaintBoundary extends RenderProxyBox {
bool inReleaseMode = true;
assert(() {
inReleaseMode = false;
if (debugSymmetricPaintCount + debugAsymmetricPaintCount == 0) {
final int totalPaints = debugSymmetricPaintCount + debugAsymmetricPaintCount;
if (totalPaints == 0) {
properties.add(MessageProperty('usefulness ratio', 'no metrics collected yet (never painted)'));
} else {
final double fraction = debugAsymmetricPaintCount / (debugSymmetricPaintCount + debugAsymmetricPaintCount);
final String diagnosis;
if (debugSymmetricPaintCount + debugAsymmetricPaintCount < 5) {
diagnosis = 'insufficient data to draw conclusion (less than five repaints)';
} else if (fraction > 0.9) {
diagnosis = 'this is an outstandingly useful repaint boundary and should definitely be kept';
} else if (fraction > 0.5) {
diagnosis = 'this is a useful repaint boundary and should be kept';
} else if (fraction > 0.30) {
diagnosis = 'this repaint boundary is probably useful, but maybe it would be more useful in tandem with adding more repaint boundaries elsewhere';
} else if (fraction > 0.1) {
diagnosis = 'this repaint boundary does sometimes show value, though currently not that often';
} else if (debugAsymmetricPaintCount == 0) {
diagnosis = 'this repaint boundary is astoundingly ineffectual and should be removed';
} else {
diagnosis = 'this repaint boundary is not very effective and should probably be removed';
}
final double fraction = debugAsymmetricPaintCount / totalPaints;
final String diagnosis = switch (fraction) {
_ when totalPaints < 5 => 'insufficient data to draw conclusion (less than five repaints)',
> 0.9 => 'this is an outstandingly useful repaint boundary and should definitely be kept',
> 0.5 => 'this is a useful repaint boundary and should be kept',
> 0.3 => 'this repaint boundary is probably useful, but maybe it would be more useful in tandem with adding more repaint boundaries elsewhere',
> 0.1 => 'this repaint boundary does sometimes show value, though currently not that often',
_ when debugAsymmetricPaintCount > 0 => 'this repaint boundary is not very effective and should probably be removed',
_ => 'this repaint boundary is astoundingly ineffectual and should be removed',
};
properties.add(PercentProperty('metrics', fraction, unit: 'useful', tooltip: '$debugSymmetricPaintCount bad vs $debugAsymmetricPaintCount good'));
properties.add(MessageProperty('diagnosis', diagnosis));
}

View File

@@ -2433,14 +2433,11 @@ class SizedBox extends SingleChildRenderObjectWidget {
@override
String toStringShort() {
final String type;
if (width == double.infinity && height == double.infinity) {
type = '${objectRuntimeType(this, 'SizedBox')}.expand';
} else if (width == 0.0 && height == 0.0) {
type = '${objectRuntimeType(this, 'SizedBox')}.shrink';
} else {
type = objectRuntimeType(this, 'SizedBox');
}
final String type = switch ((width, height)) {
(double.infinity, double.infinity) => '${objectRuntimeType(this, 'SizedBox')}.expand',
(0.0, 0.0) => '${objectRuntimeType(this, 'SizedBox')}.shrink',
_ => objectRuntimeType(this, 'SizedBox'),
};
return key == null ? type : '$type-$key';
}

View File

@@ -362,14 +362,11 @@ class Container extends StatelessWidget {
final Clip clipBehavior;
EdgeInsetsGeometry? get _paddingIncludingDecoration {
if (decoration == null) {
return padding;
}
final EdgeInsetsGeometry decorationPadding = decoration!.padding;
if (padding == null) {
return decorationPadding;
}
return padding!.add(decorationPadding);
return switch ((padding, decoration?.padding)) {
(null, final EdgeInsetsGeometry? padding) => padding,
(final EdgeInsetsGeometry? padding, null) => padding,
(_) => padding!.add(decoration!.padding),
};
}
@override

View File

@@ -217,16 +217,10 @@ class MagnifierController {
/// [AnimationStatus.completed] state, or in the [AnimationStatus.forward]
/// state.
bool get shown {
if (overlayEntry == null) {
return false;
}
if (animationController != null) {
return animationController!.status == AnimationStatus.completed ||
animationController!.status == AnimationStatus.forward;
}
return true;
return overlayEntry != null && switch (animationController?.status) {
AnimationStatus.forward || AnimationStatus.completed || null => true,
AnimationStatus.reverse || AnimationStatus.dismissed => false,
};
}
/// Displays the magnifier.

View File

@@ -152,16 +152,12 @@ class GlowingOverscrollIndicator extends StatefulWidget {
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties);
properties.add(EnumProperty<AxisDirection>('axisDirection', axisDirection));
final String showDescription;
if (showLeading && showTrailing) {
showDescription = 'both sides';
} else if (showLeading) {
showDescription = 'leading side only';
} else if (showTrailing) {
showDescription = 'trailing side only';
} else {
showDescription = 'neither side (!)';
}
final String showDescription = switch ((showLeading, showTrailing)) {
(true, true) => 'both sides',
(true, false) => 'leading side only',
(false, true) => 'trailing side only',
(false, false) => 'neither side (!)',
};
properties.add(MessageProperty('show', showDescription));
properties.add(ColorProperty('color', color, showName: false));
}

View File

@@ -1476,15 +1476,15 @@ class PlatformRouteInformationProvider extends RouteInformationProvider with Wid
@override
void routerReportsNewRouteInformation(RouteInformation routeInformation, {RouteInformationReportingType type = RouteInformationReportingType.none}) {
final bool replace =
type == RouteInformationReportingType.neglect ||
(type == RouteInformationReportingType.none &&
_equals(_valueInEngine.uri, routeInformation.uri));
SystemNavigator.selectMultiEntryHistory();
SystemNavigator.routeInformationUpdated(
uri: routeInformation.uri,
state: routeInformation.state,
replace: replace,
replace: switch (type) {
RouteInformationReportingType.neglect => true,
RouteInformationReportingType.navigate => false,
RouteInformationReportingType.none => _equals(_valueInEngine.uri, routeInformation.uri),
},
);
_value = routeInformation;
_valueInEngine = routeInformation;

View File

@@ -2906,12 +2906,10 @@ class TextSelectionGestureDetectorBuilder {
final Offset editableOffset = renderEditable.maxLines == 1
? Offset(renderEditable.offset.pixels - _dragStartViewportOffset, 0.0)
: Offset(0.0, renderEditable.offset.pixels - _dragStartViewportOffset);
final double effectiveScrollPosition = _scrollPosition - _dragStartScrollOffset;
final bool scrollingOnVerticalAxis = _scrollDirection == AxisDirection.up || _scrollDirection == AxisDirection.down;
final Offset scrollableOffset = Offset(
!scrollingOnVerticalAxis ? effectiveScrollPosition : 0.0,
scrollingOnVerticalAxis ? effectiveScrollPosition : 0.0,
);
final Offset scrollableOffset = switch (axisDirectionToAxis(_scrollDirection ?? AxisDirection.left)) {
Axis.horizontal => Offset(_scrollPosition - _dragStartScrollOffset, 0.0),
Axis.vertical => Offset(0.0, _scrollPosition - _dragStartScrollOffset),
};
final Offset dragStartGlobalPosition = details.globalPosition - details.offsetFromOrigin;
// Select word by word.

View File

@@ -255,18 +255,13 @@ mixin SingleTickerProviderStateMixin<T extends StatefulWidget> on State<T> imple
@override
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties);
String? tickerDescription;
if (_ticker != null) {
if (_ticker!.isActive && _ticker!.muted) {
tickerDescription = 'active but muted';
} else if (_ticker!.isActive) {
tickerDescription = 'active';
} else if (_ticker!.muted) {
tickerDescription = 'inactive and muted';
} else {
tickerDescription = 'inactive';
}
}
final String? tickerDescription = switch ((_ticker?.isActive, _ticker?.muted)) {
(true, true) => 'active but muted',
(true, _) => 'active',
(false, true) => 'inactive and muted',
(false, _) => 'inactive',
(null, _) => null,
};
properties.add(DiagnosticsProperty<Ticker>('ticker', _ticker, description: tickerDescription, showSeparator: false, defaultValue: null));
}
}

View File

@@ -1669,30 +1669,26 @@ mixin WidgetInspectorService {
List<Object?> _getParentChain(String? id, String groupName) {
final Object? value = toObject(id);
List<_DiagnosticsPathNode> path;
if (value is RenderObject) {
path = _getRenderObjectParentChain(value, groupName)!;
} else if (value is Element) {
path = _getElementParentChain(value, groupName);
} else {
throw FlutterError.fromParts(<DiagnosticsNode>[ErrorSummary('Cannot get parent chain for node of type ${value.runtimeType}')]);
}
return path.map<Object?>((_DiagnosticsPathNode node) => _pathNodeToJson(
node,
InspectorSerializationDelegate(groupName: groupName, service: this),
)).toList();
}
Map<String, Object?>? _pathNodeToJson(_DiagnosticsPathNode? pathNode, InspectorSerializationDelegate delegate) {
if (pathNode == null) {
return null;
}
return <String, Object?>{
'node': _nodeToJson(pathNode.node, delegate),
'children': _nodesToJson(pathNode.children, delegate, parent: pathNode.node),
'childIndex': pathNode.childIndex,
final List<_DiagnosticsPathNode> path = switch (value) {
RenderObject() => _getRenderObjectParentChain(value, groupName)!,
Element() => _getElementParentChain(value, groupName),
_ => throw FlutterError.fromParts(<DiagnosticsNode>[
ErrorSummary('Cannot get parent chain for node of type ${value.runtimeType}'),
]),
};
InspectorSerializationDelegate createDelegate() =>
InspectorSerializationDelegate(groupName: groupName, service: this);
return <Object?>[
for (final _DiagnosticsPathNode pathNode in path)
if (createDelegate() case final InspectorSerializationDelegate delegate)
<String, Object?>{
'node': _nodeToJson(pathNode.node, delegate),
'children': _nodesToJson(pathNode.children, delegate, parent: pathNode.node),
'childIndex': pathNode.childIndex,
},
];
}
List<Element> _getRawElementParentChain(Element element, { required int? numLocalParents }) {