Unverified Commit 26e379e0 authored by Nate's avatar Nate Committed by GitHub

Refactoring `if` chains into `switch` statements (#144905)

Based on issue #144903, this PR aims to bring the codebase more in line with the [Flutter repo style guide](https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo#avoid-using-if-chains-or--or--with-enum-values):

> #### Avoid using `if` chains or `?:` or `==` with enum values

<br>

This change unfortunately increases the total line length, but it also improves readability.
parent 187ec75e
...@@ -40,14 +40,15 @@ class NavigationIconView { ...@@ -40,14 +40,15 @@ class NavigationIconView {
FadeTransition transition(BottomNavigationBarType type, BuildContext context) { FadeTransition transition(BottomNavigationBarType type, BuildContext context) {
Color? iconColor; Color? iconColor;
if (type == BottomNavigationBarType.shifting) { switch (type) {
case BottomNavigationBarType.shifting:
iconColor = _color; iconColor = _color;
} else { case BottomNavigationBarType.fixed:
final ThemeData theme = Theme.of(context); final ThemeData theme = Theme.of(context);
final ColorScheme colorScheme = theme.colorScheme; iconColor = switch (theme.brightness) {
iconColor = theme.brightness == Brightness.light Brightness.light => theme.colorScheme.primary,
? colorScheme.primary Brightness.dark => theme.colorScheme.secondary,
: colorScheme.secondary; };
} }
return FadeTransition( return FadeTransition(
......
...@@ -37,13 +37,16 @@ class _MarkerPainter extends CustomPainter { ...@@ -37,13 +37,16 @@ class _MarkerPainter extends CustomPainter {
..color = const Color(0xFFFFFFFF) ..color = const Color(0xFFFFFFFF)
..style = PaintingStyle.stroke ..style = PaintingStyle.stroke
..strokeWidth = 1.0; ..strokeWidth = 1.0;
if (type == MarkerType.topLeft) {
switch (type) {
case MarkerType.topLeft:
canvas.drawLine(Offset(r, r), Offset(r + r - 1.0, r), paint); canvas.drawLine(Offset(r, r), Offset(r + r - 1.0, r), paint);
canvas.drawLine(Offset(r, r), Offset(r, r + r - 1.0), paint); canvas.drawLine(Offset(r, r), Offset(r, r + r - 1.0), paint);
} case MarkerType.bottomRight:
if (type == MarkerType.bottomRight) {
canvas.drawLine(Offset(r, r), Offset(1.0, r), paint); canvas.drawLine(Offset(r, r), Offset(1.0, r), paint);
canvas.drawLine(Offset(r, r), Offset(r, 1.0), paint); canvas.drawLine(Offset(r, r), Offset(r, 1.0), paint);
case MarkerType.touch:
break;
} }
} }
......
...@@ -41,10 +41,12 @@ class _BottomAppBarDemoState extends State<BottomAppBarDemo> { ...@@ -41,10 +41,12 @@ class _BottomAppBarDemoState extends State<BottomAppBarDemo> {
_isVisible ? FloatingActionButtonLocation.endContained : FloatingActionButtonLocation.endFloat; _isVisible ? FloatingActionButtonLocation.endContained : FloatingActionButtonLocation.endFloat;
void _listen() { void _listen() {
final ScrollDirection direction = _controller.position.userScrollDirection; switch (_controller.position.userScrollDirection) {
if (direction == ScrollDirection.forward) { case ScrollDirection.idle:
break;
case ScrollDirection.forward:
_show(); _show();
} else if (direction == ScrollDirection.reverse) { case ScrollDirection.reverse:
_hide(); _hide();
} }
} }
......
...@@ -1021,11 +1021,13 @@ class _CupertinoDatePickerDateTimeState extends State<CupertinoDatePicker> { ...@@ -1021,11 +1021,13 @@ class _CupertinoDatePickerDateTimeState extends State<CupertinoDatePicker> {
// Adds am/pm column if the picker is not using 24h format. // Adds am/pm column if the picker is not using 24h format.
if (!widget.use24hFormat) { if (!widget.use24hFormat) {
if (localizations.datePickerDateTimeOrder == DatePickerDateTimeOrder.date_time_dayPeriod switch (localizations.datePickerDateTimeOrder) {
|| localizations.datePickerDateTimeOrder == DatePickerDateTimeOrder.time_dayPeriod_date) { case DatePickerDateTimeOrder.date_time_dayPeriod:
case DatePickerDateTimeOrder.time_dayPeriod_date:
pickerBuilders.add(_buildAmPmPicker); pickerBuilders.add(_buildAmPmPicker);
columnWidths.add(_getEstimatedColumnWidth(_PickerColumnType.dayPeriod)); columnWidths.add(_getEstimatedColumnWidth(_PickerColumnType.dayPeriod));
} else { case DatePickerDateTimeOrder.date_dayPeriod_time:
case DatePickerDateTimeOrder.dayPeriod_time_date:
pickerBuilders.insert(0, _buildAmPmPicker); pickerBuilders.insert(0, _buildAmPmPicker);
columnWidths.insert(0, _getEstimatedColumnWidth(_PickerColumnType.dayPeriod)); columnWidths.insert(0, _getEstimatedColumnWidth(_PickerColumnType.dayPeriod));
} }
...@@ -1033,11 +1035,13 @@ class _CupertinoDatePickerDateTimeState extends State<CupertinoDatePicker> { ...@@ -1033,11 +1035,13 @@ class _CupertinoDatePickerDateTimeState extends State<CupertinoDatePicker> {
// Adds medium date column if the picker's mode is date and time. // Adds medium date column if the picker's mode is date and time.
if (widget.mode == CupertinoDatePickerMode.dateAndTime) { if (widget.mode == CupertinoDatePickerMode.dateAndTime) {
if (localizations.datePickerDateTimeOrder == DatePickerDateTimeOrder.time_dayPeriod_date switch (localizations.datePickerDateTimeOrder) {
|| localizations.datePickerDateTimeOrder == DatePickerDateTimeOrder.dayPeriod_time_date) { case DatePickerDateTimeOrder.time_dayPeriod_date:
case DatePickerDateTimeOrder.dayPeriod_time_date:
pickerBuilders.add(_buildMediumDatePicker); pickerBuilders.add(_buildMediumDatePicker);
columnWidths.add(_getEstimatedColumnWidth(_PickerColumnType.date)); columnWidths.add(_getEstimatedColumnWidth(_PickerColumnType.date));
} else { case DatePickerDateTimeOrder.date_time_dayPeriod:
case DatePickerDateTimeOrder.date_dayPeriod_time:
pickerBuilders.insert(0, _buildMediumDatePicker); pickerBuilders.insert(0, _buildMediumDatePicker);
columnWidths.insert(0, _getEstimatedColumnWidth(_PickerColumnType.date)); columnWidths.insert(0, _getEstimatedColumnWidth(_PickerColumnType.date));
} }
......
...@@ -210,8 +210,9 @@ class CupertinoFormSection extends StatelessWidget { ...@@ -210,8 +210,9 @@ class CupertinoFormSection extends StatelessWidget {
), ),
child: footer!); child: footer!);
return _type == CupertinoListSectionType.base switch (_type) {
? CupertinoListSection( case CupertinoListSectionType.base:
return CupertinoListSection(
header: headerWidget, header: headerWidget,
footer: footerWidget, footer: footerWidget,
margin: margin, margin: margin,
...@@ -219,8 +220,10 @@ class CupertinoFormSection extends StatelessWidget { ...@@ -219,8 +220,10 @@ class CupertinoFormSection extends StatelessWidget {
decoration: decoration, decoration: decoration,
clipBehavior: clipBehavior, clipBehavior: clipBehavior,
hasLeading: false, hasLeading: false,
children: children) children: children,
: CupertinoListSection.insetGrouped( );
case CupertinoListSectionType.insetGrouped:
return CupertinoListSection.insetGrouped(
header: headerWidget, header: headerWidget,
footer: footerWidget, footer: footerWidget,
margin: margin, margin: margin,
...@@ -228,6 +231,8 @@ class CupertinoFormSection extends StatelessWidget { ...@@ -228,6 +231,8 @@ class CupertinoFormSection extends StatelessWidget {
decoration: decoration, decoration: decoration,
clipBehavior: clipBehavior, clipBehavior: clipBehavior,
hasLeading: false, hasLeading: false,
children: children); children: children,
);
}
} }
} }
...@@ -222,22 +222,23 @@ class GestureArenaManager { ...@@ -222,22 +222,23 @@ class GestureArenaManager {
if (state == null) { if (state == null) {
return; // This arena has already resolved. return; // This arena has already resolved.
} }
assert(_debugLogDiagnostic(pointer, '${ disposition == GestureDisposition.accepted ? "Accepting" : "Rejecting" }: $member'));
assert(state.members.contains(member)); assert(state.members.contains(member));
if (disposition == GestureDisposition.rejected) { switch (disposition) {
state.members.remove(member); case GestureDisposition.accepted:
member.rejectGesture(pointer); assert(_debugLogDiagnostic(pointer, 'Accepting: $member'));
if (!state.isOpen) {
_tryToResolveArena(pointer, state);
}
} else {
assert(disposition == GestureDisposition.accepted);
if (state.isOpen) { if (state.isOpen) {
state.eagerWinner ??= member; state.eagerWinner ??= member;
} else { } else {
assert(_debugLogDiagnostic(pointer, 'Self-declared winner: $member')); assert(_debugLogDiagnostic(pointer, 'Self-declared winner: $member'));
_resolveInFavorOf(pointer, state, member); _resolveInFavorOf(pointer, state, member);
} }
case GestureDisposition.rejected:
assert(_debugLogDiagnostic(pointer, 'Rejecting: $member'));
state.members.remove(member);
member.rejectGesture(pointer);
if (!state.isOpen) {
_tryToResolveArena(pointer, state);
}
} }
} }
......
...@@ -349,7 +349,8 @@ abstract class DragGestureRecognizer extends OneSequenceGestureRecognizer { ...@@ -349,7 +349,8 @@ abstract class DragGestureRecognizer extends OneSequenceGestureRecognizer {
void _addPointer(PointerEvent event) { void _addPointer(PointerEvent event) {
_velocityTrackers[event.pointer] = velocityTrackerBuilder(event); _velocityTrackers[event.pointer] = velocityTrackerBuilder(event);
if (_state == _DragState.ready) { switch (_state) {
case _DragState.ready:
_state = _DragState.possible; _state = _DragState.possible;
_initialPosition = OffsetPair(global: event.position, local: event.localPosition); _initialPosition = OffsetPair(global: event.position, local: event.localPosition);
_finalPosition = _initialPosition; _finalPosition = _initialPosition;
...@@ -358,7 +359,9 @@ abstract class DragGestureRecognizer extends OneSequenceGestureRecognizer { ...@@ -358,7 +359,9 @@ abstract class DragGestureRecognizer extends OneSequenceGestureRecognizer {
_lastPendingEventTimestamp = event.timeStamp; _lastPendingEventTimestamp = event.timeStamp;
_lastTransform = event.transform; _lastTransform = event.transform;
_checkDown(); _checkDown();
} else if (_state == _DragState.accepted) { case _DragState.possible:
break;
case _DragState.accepted:
resolve(GestureDisposition.accepted); resolve(GestureDisposition.accepted);
} }
} }
...@@ -421,15 +424,8 @@ abstract class DragGestureRecognizer extends OneSequenceGestureRecognizer { ...@@ -421,15 +424,8 @@ abstract class DragGestureRecognizer extends OneSequenceGestureRecognizer {
final Offset position = (event is PointerMoveEvent) ? event.position : (event.position + (event as PointerPanZoomUpdateEvent).pan); final Offset position = (event is PointerMoveEvent) ? event.position : (event.position + (event as PointerPanZoomUpdateEvent).pan);
final Offset localPosition = (event is PointerMoveEvent) ? event.localPosition : (event.localPosition + (event as PointerPanZoomUpdateEvent).localPan); final Offset localPosition = (event is PointerMoveEvent) ? event.localPosition : (event.localPosition + (event as PointerPanZoomUpdateEvent).localPan);
_finalPosition = OffsetPair(local: localPosition, global: position); _finalPosition = OffsetPair(local: localPosition, global: position);
if (_state == _DragState.accepted) { switch (_state) {
_checkUpdate( case _DragState.ready || _DragState.possible:
sourceTimeStamp: event.timeStamp,
delta: _getDeltaForDetails(localDelta),
primaryDelta: _getPrimaryValueFromOffset(localDelta),
globalPosition: position,
localPosition: localPosition,
);
} else {
_pendingDragOffset += OffsetPair(local: localDelta, global: delta); _pendingDragOffset += OffsetPair(local: localDelta, global: delta);
_lastPendingEventTimestamp = event.timeStamp; _lastPendingEventTimestamp = event.timeStamp;
_lastTransform = event.transform; _lastTransform = event.transform;
...@@ -448,9 +444,17 @@ abstract class DragGestureRecognizer extends OneSequenceGestureRecognizer { ...@@ -448,9 +444,17 @@ abstract class DragGestureRecognizer extends OneSequenceGestureRecognizer {
resolve(GestureDisposition.accepted); resolve(GestureDisposition.accepted);
} }
} }
case _DragState.accepted:
_checkUpdate(
sourceTimeStamp: event.timeStamp,
delta: _getDeltaForDetails(localDelta),
primaryDelta: _getPrimaryValueFromOffset(localDelta),
globalPosition: position,
localPosition: localPosition,
);
} }
} }
if (event is PointerUpEvent || event is PointerCancelEvent || event is PointerPanZoomEndEvent) { if (event case PointerUpEvent() || PointerCancelEvent() || PointerPanZoomEndEvent()) {
_giveUpPointer(event.pointer); _giveUpPointer(event.pointer);
} }
} }
......
...@@ -1152,9 +1152,10 @@ class _MasterDetailFlowState extends State<_MasterDetailFlow> implements _PageOp ...@@ -1152,9 +1152,10 @@ class _MasterDetailFlowState extends State<_MasterDetailFlow> implements _PageOp
@override @override
void openDetailPage(Object arguments) { void openDetailPage(Object arguments) {
_cachedDetailArguments = arguments; _cachedDetailArguments = arguments;
if (_builtLayout == _LayoutMode.nested) { switch (_builtLayout) {
case _LayoutMode.nested:
_navigatorKey.currentState!.pushNamed(_navDetail, arguments: arguments); _navigatorKey.currentState!.pushNamed(_navDetail, arguments: arguments);
} else { case _LayoutMode.lateral || null:
focus = _Focus.detail; focus = _Focus.detail;
} }
} }
......
...@@ -455,19 +455,35 @@ class ToggleButtons extends StatelessWidget { ...@@ -455,19 +455,35 @@ class ToggleButtons extends StatelessWidget {
// Determines if this is the first child that is being laid out // Determines if this is the first child that is being laid out
// by the render object, _not_ the order of the children in its list. // by the render object, _not_ the order of the children in its list.
bool _isFirstButton(int index, int length, TextDirection textDirection) { bool _isFirstButton(int index, int length, TextDirection textDirection) {
return index == 0 && ((direction == Axis.horizontal && textDirection == TextDirection.ltr) || switch (direction) {
(direction == Axis.vertical && verticalDirection == VerticalDirection.down)) case Axis.horizontal:
|| index == length - 1 && ((direction == Axis.horizontal && textDirection == TextDirection.rtl) || return switch (textDirection) {
(direction == Axis.vertical && verticalDirection == VerticalDirection.up)); TextDirection.rtl => index == length - 1,
TextDirection.ltr => index == 0,
};
case Axis.vertical:
return switch (verticalDirection) {
VerticalDirection.up => index == length - 1,
VerticalDirection.down => index == 0,
};
}
} }
// Determines if this is the last child that is being laid out // Determines if this is the last child that is being laid out
// by the render object, _not_ the order of the children in its list. // by the render object, _not_ the order of the children in its list.
bool _isLastButton(int index, int length, TextDirection textDirection) { bool _isLastButton(int index, int length, TextDirection textDirection) {
return index == length - 1 && ((direction == Axis.horizontal && textDirection == TextDirection.ltr) || switch (direction) {
(direction == Axis.vertical && verticalDirection == VerticalDirection.down)) case Axis.horizontal:
|| index == 0 && ((direction == Axis.horizontal && textDirection == TextDirection.rtl) || return switch (textDirection) {
(direction == Axis.vertical && verticalDirection == VerticalDirection.up)); TextDirection.rtl => index == 0,
TextDirection.ltr => index == length - 1,
};
case Axis.vertical:
return switch (verticalDirection) {
VerticalDirection.up => index == 0,
VerticalDirection.down => index == length - 1,
};
}
} }
BorderRadius _getEdgeBorderRadius( BorderRadius _getEdgeBorderRadius(
......
...@@ -1795,11 +1795,12 @@ class TextInput { ...@@ -1795,11 +1795,12 @@ class TextInput {
Future<dynamic> _handleTextInputInvocation(MethodCall methodCall) async { Future<dynamic> _handleTextInputInvocation(MethodCall methodCall) async {
final String method = methodCall.method; final String method = methodCall.method;
if (method == 'TextInputClient.focusElement') { switch (methodCall.method) {
case 'TextInputClient.focusElement':
final List<dynamic> args = methodCall.arguments as List<dynamic>; final List<dynamic> args = methodCall.arguments as List<dynamic>;
_scribbleClients[args[0]]?.onScribbleFocus(Offset((args[1] as num).toDouble(), (args[2] as num).toDouble())); _scribbleClients[args[0]]?.onScribbleFocus(Offset((args[1] as num).toDouble(), (args[2] as num).toDouble()));
return; return;
} else if (method == 'TextInputClient.requestElementsInRect') { case 'TextInputClient.requestElementsInRect':
final List<double> args = (methodCall.arguments as List<dynamic>).cast<num>().map<double>((num value) => value.toDouble()).toList(); final List<double> args = (methodCall.arguments as List<dynamic>).cast<num>().map<double>((num value) => value.toDouble()).toList();
return _scribbleClients.keys.where((String elementIdentifier) { return _scribbleClients.keys.where((String elementIdentifier) {
final Rect rect = Rect.fromLTWH(args[0], args[1], args[2], args[3]); final Rect rect = Rect.fromLTWH(args[0], args[1], args[2], args[3]);
...@@ -1812,10 +1813,10 @@ class TextInput { ...@@ -1812,10 +1813,10 @@ class TextInput {
final Rect bounds = _scribbleClients[elementIdentifier]!.bounds; final Rect bounds = _scribbleClients[elementIdentifier]!.bounds;
return <dynamic>[elementIdentifier, ...<dynamic>[bounds.left, bounds.top, bounds.width, bounds.height]]; return <dynamic>[elementIdentifier, ...<dynamic>[bounds.left, bounds.top, bounds.width, bounds.height]];
}).toList(); }).toList();
} else if (method == 'TextInputClient.scribbleInteractionBegan') { case 'TextInputClient.scribbleInteractionBegan':
_scribbleInProgress = true; _scribbleInProgress = true;
return; return;
} else if (method == 'TextInputClient.scribbleInteractionFinished') { case 'TextInputClient.scribbleInteractionFinished':
_scribbleInProgress = false; _scribbleInProgress = false;
return; return;
} }
......
...@@ -871,7 +871,8 @@ class _InteractiveViewerState extends State<InteractiveViewer> with TickerProvid ...@@ -871,7 +871,8 @@ class _InteractiveViewerState extends State<InteractiveViewer> with TickerProvid
return; return;
} }
if (_gestureType == _GestureType.pan) { switch (_gestureType) {
case _GestureType.pan:
if (details.velocity.pixelsPerSecond.distance < kMinFlingVelocity) { if (details.velocity.pixelsPerSecond.distance < kMinFlingVelocity) {
_currentAxis = null; _currentAxis = null;
return; return;
...@@ -902,7 +903,7 @@ class _InteractiveViewerState extends State<InteractiveViewer> with TickerProvid ...@@ -902,7 +903,7 @@ class _InteractiveViewerState extends State<InteractiveViewer> with TickerProvid
_controller.duration = Duration(milliseconds: (tFinal * 1000).round()); _controller.duration = Duration(milliseconds: (tFinal * 1000).round());
_animation!.addListener(_onAnimate); _animation!.addListener(_onAnimate);
_controller.forward(); _controller.forward();
} else if (_gestureType == _GestureType.scale) { case _GestureType.scale:
if (details.scaleVelocity.abs() < 0.1) { if (details.scaleVelocity.abs() < 0.1) {
_currentAxis = null; _currentAxis = null;
return; return;
...@@ -924,6 +925,8 @@ class _InteractiveViewerState extends State<InteractiveViewer> with TickerProvid ...@@ -924,6 +925,8 @@ class _InteractiveViewerState extends State<InteractiveViewer> with TickerProvid
_scaleController.duration = Duration(milliseconds: (tFinal * 1000).round()); _scaleController.duration = Duration(milliseconds: (tFinal * 1000).round());
_scaleAnimation!.addListener(_onScaleAnimate); _scaleAnimation!.addListener(_onScaleAnimate);
_scaleController.forward(); _scaleController.forward();
case _GestureType.rotate || null:
break;
} }
} }
......
...@@ -14,10 +14,11 @@ enum RadiusType { ...@@ -14,10 +14,11 @@ enum RadiusType {
void matches(BorderRadius? borderRadius, RadiusType top, RadiusType bottom) { void matches(BorderRadius? borderRadius, RadiusType top, RadiusType bottom) {
final Radius cardRadius = kMaterialEdges[MaterialType.card]!.topLeft; final Radius cardRadius = kMaterialEdges[MaterialType.card]!.topLeft;
if (top == RadiusType.Sharp) { switch (top) {
case RadiusType.Sharp:
expect(borderRadius?.topLeft, equals(Radius.zero)); expect(borderRadius?.topLeft, equals(Radius.zero));
expect(borderRadius?.topRight, equals(Radius.zero)); expect(borderRadius?.topRight, equals(Radius.zero));
} else if (top == RadiusType.Shifting) { case RadiusType.Shifting:
expect(borderRadius?.topLeft.x, greaterThan(0.0)); expect(borderRadius?.topLeft.x, greaterThan(0.0));
expect(borderRadius?.topLeft.x, lessThan(cardRadius.x)); expect(borderRadius?.topLeft.x, lessThan(cardRadius.x));
expect(borderRadius?.topLeft.y, greaterThan(0.0)); expect(borderRadius?.topLeft.y, greaterThan(0.0));
...@@ -26,15 +27,16 @@ void matches(BorderRadius? borderRadius, RadiusType top, RadiusType bottom) { ...@@ -26,15 +27,16 @@ void matches(BorderRadius? borderRadius, RadiusType top, RadiusType bottom) {
expect(borderRadius?.topRight.x, lessThan(cardRadius.x)); expect(borderRadius?.topRight.x, lessThan(cardRadius.x));
expect(borderRadius?.topRight.y, greaterThan(0.0)); expect(borderRadius?.topRight.y, greaterThan(0.0));
expect(borderRadius?.topRight.y, lessThan(cardRadius.y)); expect(borderRadius?.topRight.y, lessThan(cardRadius.y));
} else { case RadiusType.Round:
expect(borderRadius?.topLeft, equals(cardRadius)); expect(borderRadius?.topLeft, equals(cardRadius));
expect(borderRadius?.topRight, equals(cardRadius)); expect(borderRadius?.topRight, equals(cardRadius));
} }
if (bottom == RadiusType.Sharp) { switch (bottom) {
case RadiusType.Sharp:
expect(borderRadius?.bottomLeft, equals(Radius.zero)); expect(borderRadius?.bottomLeft, equals(Radius.zero));
expect(borderRadius?.bottomRight, equals(Radius.zero)); expect(borderRadius?.bottomRight, equals(Radius.zero));
} else if (bottom == RadiusType.Shifting) { case RadiusType.Shifting:
expect(borderRadius?.bottomLeft.x, greaterThan(0.0)); expect(borderRadius?.bottomLeft.x, greaterThan(0.0));
expect(borderRadius?.bottomLeft.x, lessThan(cardRadius.x)); expect(borderRadius?.bottomLeft.x, lessThan(cardRadius.x));
expect(borderRadius?.bottomLeft.y, greaterThan(0.0)); expect(borderRadius?.bottomLeft.y, greaterThan(0.0));
...@@ -43,7 +45,7 @@ void matches(BorderRadius? borderRadius, RadiusType top, RadiusType bottom) { ...@@ -43,7 +45,7 @@ void matches(BorderRadius? borderRadius, RadiusType top, RadiusType bottom) {
expect(borderRadius?.bottomRight.x, lessThan(cardRadius.x)); expect(borderRadius?.bottomRight.x, lessThan(cardRadius.x));
expect(borderRadius?.bottomRight.y, greaterThan(0.0)); expect(borderRadius?.bottomRight.y, greaterThan(0.0));
expect(borderRadius?.bottomRight.y, lessThan(cardRadius.y)); expect(borderRadius?.bottomRight.y, lessThan(cardRadius.y));
} else { case RadiusType.Round:
expect(borderRadius?.bottomLeft, equals(cardRadius)); expect(borderRadius?.bottomLeft, equals(cardRadius));
expect(borderRadius?.bottomRight, equals(cardRadius)); expect(borderRadius?.bottomRight, equals(cardRadius));
} }
......
...@@ -221,25 +221,25 @@ class MacOSTestTextInputKeyHandler extends TestTextInputKeyHandler { ...@@ -221,25 +221,25 @@ class MacOSTestTextInputKeyHandler extends TestTextInputKeyHandler {
@override @override
Future<void> handleKeyDownEvent(LogicalKeyboardKey key) async { Future<void> handleKeyDownEvent(LogicalKeyboardKey key) async {
if (key == LogicalKeyboardKey.shift || switch (key) {
key == LogicalKeyboardKey.shiftLeft || case LogicalKeyboardKey.shift:
key == LogicalKeyboardKey.shiftRight) { case LogicalKeyboardKey.shiftLeft:
case LogicalKeyboardKey.shiftRight:
_shift = true; _shift = true;
} else if (key == LogicalKeyboardKey.alt || case LogicalKeyboardKey.alt:
key == LogicalKeyboardKey.altLeft || case LogicalKeyboardKey.altLeft:
key == LogicalKeyboardKey.altRight) { case LogicalKeyboardKey.altRight:
_alt = true; _alt = true;
} else if (key == LogicalKeyboardKey.meta || case LogicalKeyboardKey.meta:
key == LogicalKeyboardKey.metaLeft || case LogicalKeyboardKey.metaLeft:
key == LogicalKeyboardKey.metaRight) { case LogicalKeyboardKey.metaRight:
_meta = true; _meta = true;
} else if (key == LogicalKeyboardKey.control || case LogicalKeyboardKey.control:
key == LogicalKeyboardKey.controlLeft || case LogicalKeyboardKey.controlLeft:
key == LogicalKeyboardKey.controlRight) { case LogicalKeyboardKey.controlRight:
_control = true; _control = true;
} else { default:
for (final MapEntry<SingleActivator, List<String>> entry for (final MapEntry<SingleActivator, List<String>> entry in _macOSActivatorToSelectors.entries) {
in _macOSActivatorToSelectors.entries) {
final SingleActivator activator = entry.key; final SingleActivator activator = entry.key;
if (activator.triggers.first == key && if (activator.triggers.first == key &&
activator.shift == _shift && activator.shift == _shift &&
...@@ -255,21 +255,22 @@ class MacOSTestTextInputKeyHandler extends TestTextInputKeyHandler { ...@@ -255,21 +255,22 @@ class MacOSTestTextInputKeyHandler extends TestTextInputKeyHandler {
@override @override
Future<void> handleKeyUpEvent(LogicalKeyboardKey key) async { Future<void> handleKeyUpEvent(LogicalKeyboardKey key) async {
if (key == LogicalKeyboardKey.shift || switch (key) {
key == LogicalKeyboardKey.shiftLeft || case LogicalKeyboardKey.shift:
key == LogicalKeyboardKey.shiftRight) { case LogicalKeyboardKey.shiftLeft:
case LogicalKeyboardKey.shiftRight:
_shift = false; _shift = false;
} else if (key == LogicalKeyboardKey.alt || case LogicalKeyboardKey.alt:
key == LogicalKeyboardKey.altLeft || case LogicalKeyboardKey.altLeft:
key == LogicalKeyboardKey.altRight) { case LogicalKeyboardKey.altRight:
_alt = false; _alt = false;
} else if (key == LogicalKeyboardKey.meta || case LogicalKeyboardKey.meta:
key == LogicalKeyboardKey.metaLeft || case LogicalKeyboardKey.metaLeft:
key == LogicalKeyboardKey.metaRight) { case LogicalKeyboardKey.metaRight:
_meta = false; _meta = false;
} else if (key == LogicalKeyboardKey.control || case LogicalKeyboardKey.control:
key == LogicalKeyboardKey.controlLeft || case LogicalKeyboardKey.controlLeft:
key == LogicalKeyboardKey.controlRight) { case LogicalKeyboardKey.controlRight:
_control = false; _control = false;
} }
} }
......
...@@ -165,14 +165,15 @@ class AndroidDevices extends PollingDeviceDiscovery { ...@@ -165,14 +165,15 @@ class AndroidDevices extends PollingDeviceDiscovery {
info['model'] = cleanAdbDeviceName(model); info['model'] = cleanAdbDeviceName(model);
} }
if (deviceState == 'unauthorized') { switch (deviceState) {
case 'unauthorized':
diagnostics?.add( diagnostics?.add(
'Device $deviceID is not authorized.\n' 'Device $deviceID is not authorized.\n'
'You might need to check your device for an authorization dialog.' 'You might need to check your device for an authorization dialog.'
); );
} else if (deviceState == 'offline') { case 'offline':
diagnostics?.add('Device $deviceID is offline.'); diagnostics?.add('Device $deviceID is offline.');
} else { default:
devices?.add(AndroidDevice( devices?.add(AndroidDevice(
deviceID, deviceID,
productID: info['product'], productID: info['product'],
......
...@@ -866,9 +866,10 @@ void _printWarningDisabledPlatform(List<String> platforms) { ...@@ -866,9 +866,10 @@ void _printWarningDisabledPlatform(List<String> platforms) {
final List<String> web = <String>[]; final List<String> web = <String>[];
for (final String platform in platforms) { for (final String platform in platforms) {
if (platform == 'web') { switch (platform) {
case 'web':
web.add(platform); web.add(platform);
} else if (platform == 'macos' || platform == 'windows' || platform == 'linux') { case 'macos' || 'windows' || 'linux':
desktop.add(platform); desktop.add(platform);
} }
} }
......
...@@ -152,11 +152,12 @@ class AnalysisServer { ...@@ -152,11 +152,12 @@ class AnalysisServer {
} }
if (paramsMap != null) { if (paramsMap != null) {
if (event == 'server.status') { switch (event) {
case 'server.status':
_handleStatus(paramsMap); _handleStatus(paramsMap);
} else if (event == 'analysis.errors') { case 'analysis.errors':
_handleAnalysisIssues(paramsMap); _handleAnalysisIssues(paramsMap);
} else if (event == 'server.error') { case 'server.error':
_handleServerError(paramsMap); _handleServerError(paramsMap);
} }
} }
......
...@@ -120,18 +120,22 @@ class FlutterDevice { ...@@ -120,18 +120,22 @@ class FlutterDevice {
// TODO(zanderso): consistently provide these flags across platforms. // TODO(zanderso): consistently provide these flags across platforms.
final String platformDillName; final String platformDillName;
final List<String> extraFrontEndOptions = List<String>.of(buildInfo.extraFrontEndOptions); final List<String> extraFrontEndOptions = List<String>.of(buildInfo.extraFrontEndOptions);
if (buildInfo.nullSafetyMode == NullSafetyMode.unsound) { switch (buildInfo.nullSafetyMode) {
case NullSafetyMode.unsound:
platformDillName = 'ddc_outline.dill'; platformDillName = 'ddc_outline.dill';
if (!extraFrontEndOptions.contains('--no-sound-null-safety')) { if (!extraFrontEndOptions.contains('--no-sound-null-safety')) {
extraFrontEndOptions.add('--no-sound-null-safety'); extraFrontEndOptions.add('--no-sound-null-safety');
} }
} else if (buildInfo.nullSafetyMode == NullSafetyMode.sound) { case NullSafetyMode.sound:
platformDillName = 'ddc_outline_sound.dill'; platformDillName = 'ddc_outline_sound.dill';
if (!extraFrontEndOptions.contains('--sound-null-safety')) { if (!extraFrontEndOptions.contains('--sound-null-safety')) {
extraFrontEndOptions.add('--sound-null-safety'); extraFrontEndOptions.add('--sound-null-safety');
} }
} else { case NullSafetyMode.autodetect:
throw StateError('Expected buildInfo.nullSafetyMode to be one of unsound or sound, got ${buildInfo.nullSafetyMode}'); throw StateError(
'Expected buildInfo.nullSafetyMode to be one of unsound or sound, '
'got NullSafetyMode.autodetect',
);
} }
final String platformDillPath = globals.fs.path.join( final String platformDillPath = globals.fs.path.join(
......
...@@ -146,16 +146,17 @@ class HotRunner extends ResidentRunner { ...@@ -146,16 +146,17 @@ class HotRunner extends ResidentRunner {
return; return;
} }
if (flutterDevices.length == 1) { switch (flutterDevices.length) {
case 1:
final Device device = flutterDevices.first.device!; final Device device = flutterDevices.first.device!;
_targetPlatform = getNameForTargetPlatform(await device.targetPlatform); _targetPlatform = getNameForTargetPlatform(await device.targetPlatform);
_sdkName = await device.sdkNameAndVersion; _sdkName = await device.sdkNameAndVersion;
_emulator = await device.isLocalEmulator; _emulator = await device.isLocalEmulator;
} else if (flutterDevices.length > 1) { case > 1:
_targetPlatform = 'multiple'; _targetPlatform = 'multiple';
_sdkName = 'multiple'; _sdkName = 'multiple';
_emulator = false; _emulator = false;
} else { default:
_targetPlatform = 'unknown'; _targetPlatform = 'unknown';
_sdkName = 'unknown'; _sdkName = 'unknown';
_emulator = false; _emulator = false;
......
...@@ -57,12 +57,13 @@ class WebTestCompiler { ...@@ -57,12 +57,13 @@ class WebTestCompiler {
// TODO(zanderso): to support autodetect this would need to partition the source code into // TODO(zanderso): to support autodetect this would need to partition the source code into
// a sound and unsound set and perform separate compilations // a sound and unsound set and perform separate compilations
final List<String> extraFrontEndOptions = List<String>.of(buildInfo.extraFrontEndOptions); final List<String> extraFrontEndOptions = List<String>.of(buildInfo.extraFrontEndOptions);
if (buildInfo.nullSafetyMode == NullSafetyMode.unsound || buildInfo.nullSafetyMode == NullSafetyMode.autodetect) { switch (buildInfo.nullSafetyMode) {
case NullSafetyMode.unsound || NullSafetyMode.autodetect:
platformDillName = 'ddc_outline.dill'; platformDillName = 'ddc_outline.dill';
if (!extraFrontEndOptions.contains('--no-sound-null-safety')) { if (!extraFrontEndOptions.contains('--no-sound-null-safety')) {
extraFrontEndOptions.add('--no-sound-null-safety'); extraFrontEndOptions.add('--no-sound-null-safety');
} }
} else if (buildInfo.nullSafetyMode == NullSafetyMode.sound) { case NullSafetyMode.sound:
languageVersion = currentLanguageVersion(_fileSystem, Cache.flutterRoot!); languageVersion = currentLanguageVersion(_fileSystem, Cache.flutterRoot!);
platformDillName = 'ddc_outline_sound.dill'; platformDillName = 'ddc_outline_sound.dill';
if (!extraFrontEndOptions.contains('--sound-null-safety')) { if (!extraFrontEndOptions.contains('--sound-null-safety')) {
......
...@@ -147,11 +147,12 @@ void main() { ...@@ -147,11 +147,12 @@ void main() {
// shadow the exception we would have gotten. // shadow the exception we would have gotten.
expect(stdout, isNot(contains('EXCEPTION CAUGHT BY WIDGETS LIBRARY'))); expect(stdout, isNot(contains('EXCEPTION CAUGHT BY WIDGETS LIBRARY')));
if (device == 'macos') { switch (device) {
case 'macos':
expectDylibIsBundledMacOS(exampleDirectory, buildMode); expectDylibIsBundledMacOS(exampleDirectory, buildMode);
} else if (device == 'linux') { case 'linux':
expectDylibIsBundledLinux(exampleDirectory, buildMode); expectDylibIsBundledLinux(exampleDirectory, buildMode);
} else if (device == 'windows') { case 'windows':
expectDylibIsBundledWindows(exampleDirectory, buildMode); expectDylibIsBundledWindows(exampleDirectory, buildMode);
} }
if (device == hostOs) { if (device == hostOs) {
...@@ -203,15 +204,16 @@ void main() { ...@@ -203,15 +204,16 @@ void main() {
throw Exception('flutter build failed: ${result.exitCode}\n${result.stderr}\n${result.stdout}'); throw Exception('flutter build failed: ${result.exitCode}\n${result.stderr}\n${result.stdout}');
} }
if (buildSubcommand == 'macos') { switch (buildSubcommand) {
case 'macos':
expectDylibIsBundledMacOS(exampleDirectory, buildMode); expectDylibIsBundledMacOS(exampleDirectory, buildMode);
} else if (buildSubcommand == 'ios') { case 'ios':
expectDylibIsBundledIos(exampleDirectory, buildMode); expectDylibIsBundledIos(exampleDirectory, buildMode);
} else if (buildSubcommand == 'linux') { case 'linux':
expectDylibIsBundledLinux(exampleDirectory, buildMode); expectDylibIsBundledLinux(exampleDirectory, buildMode);
} else if (buildSubcommand == 'windows') { case 'windows':
expectDylibIsBundledWindows(exampleDirectory, buildMode); expectDylibIsBundledWindows(exampleDirectory, buildMode);
} else if (buildSubcommand == 'apk') { case 'apk':
expectDylibIsBundledAndroid(exampleDirectory, buildMode); expectDylibIsBundledAndroid(exampleDirectory, buildMode);
} }
expectCCompilerIsConfigured(exampleDirectory); expectCCompilerIsConfigured(exampleDirectory);
......
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