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