if chains → switch expressions (#147793)
Previous "if-chains" pull requests: - https://github.com/flutter/flutter/pull/144905 - https://github.com/flutter/flutter/pull/144977 - https://github.com/flutter/flutter/pull/145194 - https://github.com/flutter/flutter/pull/146293 - https://github.com/flutter/flutter/pull/147472 <br> I think this one should be enough to wrap things up! fixes https://github.com/flutter/flutter/issues/144903 --------- Co-authored-by: Victor Sanni <victorsanniay@gmail.com>
This commit is contained in:
@@ -131,12 +131,11 @@ abstract class DeferredComponentsValidator {
|
||||
if (line.startsWith('Only in android')) {
|
||||
continue;
|
||||
}
|
||||
TerminalColor color = TerminalColor.grey;
|
||||
if (line.startsWith('+')) {
|
||||
color = TerminalColor.green;
|
||||
} else if (line.startsWith('-')) {
|
||||
color = TerminalColor.red;
|
||||
}
|
||||
final TerminalColor color = switch (line[0]) {
|
||||
'+' => TerminalColor.green,
|
||||
'-' => TerminalColor.red,
|
||||
_ => TerminalColor.grey,
|
||||
};
|
||||
logger.printStatus(line, color: color);
|
||||
}
|
||||
logger.printStatus('');
|
||||
|
||||
@@ -115,18 +115,15 @@ class MultiRootFileSystem extends ForwardingFileSystem {
|
||||
/// If the path is a multiroot uri, resolve to the actual path of the
|
||||
/// underlying file system. Otherwise, return as is.
|
||||
dynamic _resolve(dynamic path) {
|
||||
Uri uri;
|
||||
if (path == null) {
|
||||
return null;
|
||||
} else if (path is String) {
|
||||
uri = Uri.parse(path);
|
||||
} else if (path is Uri) {
|
||||
uri = path;
|
||||
} else if (path is FileSystemEntity) {
|
||||
uri = path.uri;
|
||||
} else {
|
||||
throw ArgumentError('Invalid type for "path": ${(path as Object?)?.runtimeType}');
|
||||
}
|
||||
final Uri uri = switch (path) {
|
||||
String() => Uri.parse(path),
|
||||
Uri() => path,
|
||||
FileSystemEntity() => path.uri,
|
||||
_ => throw ArgumentError('Invalid type for "path": ${(path as Object?)?.runtimeType}'),
|
||||
};
|
||||
|
||||
if (!uri.hasScheme || uri.scheme != _scheme) {
|
||||
return path;
|
||||
|
||||
@@ -666,11 +666,10 @@ abstract class _BuildIOSSubCommand extends BuildSubCommand {
|
||||
|
||||
final String logTarget = environmentType == EnvironmentType.simulator ? 'simulator' : 'device';
|
||||
final String typeName = globals.artifacts!.getEngineType(TargetPlatform.ios, buildInfo.mode);
|
||||
if (xcodeBuildAction == XcodeBuildAction.build) {
|
||||
globals.printStatus('Building $app for $logTarget ($typeName)...');
|
||||
} else {
|
||||
globals.printStatus('Archiving $app...');
|
||||
}
|
||||
globals.printStatus(switch (xcodeBuildAction) {
|
||||
XcodeBuildAction.build => 'Building $app for $logTarget ($typeName)...',
|
||||
XcodeBuildAction.archive => 'Archiving $app...',
|
||||
});
|
||||
final XcodeBuildResult result = await buildXcodeProject(
|
||||
app: app,
|
||||
buildInfo: buildInfo,
|
||||
|
||||
@@ -429,22 +429,17 @@ end
|
||||
Directory simulatorBuildOutput,
|
||||
) async {
|
||||
const String appFrameworkName = 'App.framework';
|
||||
|
||||
final Status status = globals.logger.startProgress(
|
||||
' ├─Building App.xcframework...',
|
||||
);
|
||||
final List<EnvironmentType> environmentTypes = <EnvironmentType>[
|
||||
EnvironmentType.physical,
|
||||
EnvironmentType.simulator,
|
||||
];
|
||||
final List<Directory> frameworks = <Directory>[];
|
||||
|
||||
try {
|
||||
for (final EnvironmentType sdkType in environmentTypes) {
|
||||
final Directory outputBuildDirectory =
|
||||
sdkType == EnvironmentType.physical
|
||||
? iPhoneBuildOutput
|
||||
: simulatorBuildOutput;
|
||||
for (final EnvironmentType sdkType in EnvironmentType.values) {
|
||||
final Directory outputBuildDirectory = switch (sdkType) {
|
||||
EnvironmentType.physical => iPhoneBuildOutput,
|
||||
EnvironmentType.simulator => simulatorBuildOutput,
|
||||
};
|
||||
frameworks.add(outputBuildDirectory.childDirectory(appFrameworkName));
|
||||
final Environment environment = Environment(
|
||||
projectDir: globals.fs.currentDirectory,
|
||||
|
||||
@@ -1429,16 +1429,12 @@ Map<String, Object?> _operationResultToMap(OperationResult result) {
|
||||
}
|
||||
|
||||
Object? _toJsonable(Object? obj) {
|
||||
if (obj is String || obj is int || obj is bool || obj is Map<Object?, Object?> || obj is List<Object?> || obj == null) {
|
||||
return obj;
|
||||
}
|
||||
if (obj is OperationResult) {
|
||||
return _operationResultToMap(obj);
|
||||
}
|
||||
if (obj is ToolExit) {
|
||||
return obj.message;
|
||||
}
|
||||
return '$obj';
|
||||
return switch (obj) {
|
||||
String() || int() || bool() || Map<Object?, Object?>() || List<Object?>() || null => obj,
|
||||
OperationResult() => _operationResultToMap(obj),
|
||||
ToolExit() => obj.message,
|
||||
_ => obj.toString(),
|
||||
};
|
||||
}
|
||||
|
||||
class NotifyingLogger extends DelegatingLogger {
|
||||
|
||||
@@ -942,12 +942,11 @@ enum ImpellerStatus {
|
||||
|
||||
const ImpellerStatus._(this.asBool);
|
||||
|
||||
factory ImpellerStatus.fromBool(bool? b) {
|
||||
if (b == null) {
|
||||
return platformDefault;
|
||||
}
|
||||
return b ? enabled : disabled;
|
||||
}
|
||||
factory ImpellerStatus.fromBool(bool? b) => switch (b) {
|
||||
true => enabled,
|
||||
false => disabled,
|
||||
null => platformDefault,
|
||||
};
|
||||
|
||||
final bool? asBool;
|
||||
}
|
||||
|
||||
@@ -439,15 +439,11 @@ class IOSCoreDevice {
|
||||
String? get udid => hardwareProperties?.udid;
|
||||
|
||||
DeviceConnectionInterface? get connectionInterface {
|
||||
final String? transportType = connectionProperties?.transportType;
|
||||
if (transportType != null) {
|
||||
if (transportType.toLowerCase() == 'localnetwork') {
|
||||
return DeviceConnectionInterface.wireless;
|
||||
} else if (transportType.toLowerCase() == 'wired') {
|
||||
return DeviceConnectionInterface.attached;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
return switch (connectionProperties?.transportType?.toLowerCase()) {
|
||||
'localnetwork' => DeviceConnectionInterface.wireless,
|
||||
'wired' => DeviceConnectionInterface.attached,
|
||||
_ => null,
|
||||
};
|
||||
}
|
||||
|
||||
@visibleForTesting
|
||||
|
||||
@@ -96,16 +96,12 @@ class Node {
|
||||
// Token constructors.
|
||||
Node.openBrace(this.positionInMessage): type = ST.openBrace, value = '{';
|
||||
Node.closeBrace(this.positionInMessage): type = ST.closeBrace, value = '}';
|
||||
Node.brace(this.positionInMessage, String this.value) {
|
||||
if (value == '{') {
|
||||
type = ST.openBrace;
|
||||
} else if (value == '}') {
|
||||
type = ST.closeBrace;
|
||||
} else {
|
||||
// We should never arrive here.
|
||||
throw L10nException('Provided value $value is not a brace.');
|
||||
}
|
||||
}
|
||||
Node.brace(this.positionInMessage, String this.value)
|
||||
: type = switch (value) {
|
||||
'{' => ST.openBrace,
|
||||
'}' => ST.closeBrace,
|
||||
_ => throw L10nException('Provided value $value is not a brace.')
|
||||
};
|
||||
Node.equalSign(this.positionInMessage): type = ST.equalSign, value = '=';
|
||||
Node.comma(this.positionInMessage): type = ST.comma, value = ',';
|
||||
Node.string(this.positionInMessage, String this.value): type = ST.string;
|
||||
|
||||
@@ -914,12 +914,10 @@ abstract class ResidentHandlers {
|
||||
final Brightness? current = await flutterDevices.first!.vmService!.flutterBrightnessOverride(
|
||||
isolateId: views.first.uiIsolate!.id!,
|
||||
);
|
||||
Brightness next;
|
||||
if (current == Brightness.light) {
|
||||
next = Brightness.dark;
|
||||
} else {
|
||||
next = Brightness.light;
|
||||
}
|
||||
final Brightness next = switch (current) {
|
||||
Brightness.light => Brightness.dark,
|
||||
Brightness.dark || null => Brightness.light,
|
||||
};
|
||||
for (final FlutterDevice? device in flutterDevices) {
|
||||
final List<FlutterView> views = await device!.vmService!.getFlutterViews();
|
||||
for (final FlutterView view in views) {
|
||||
|
||||
@@ -772,15 +772,14 @@ abstract class FlutterCommand extends Command<void> {
|
||||
return null;
|
||||
}();
|
||||
|
||||
DeviceConnectionInterface? get deviceConnectionInterface {
|
||||
DeviceConnectionInterface? get deviceConnectionInterface {
|
||||
if ((argResults?.options.contains(FlutterOptions.kDeviceConnection) ?? false)
|
||||
&& (argResults?.wasParsed(FlutterOptions.kDeviceConnection) ?? false)) {
|
||||
final String? connectionType = stringArg(FlutterOptions.kDeviceConnection);
|
||||
if (connectionType == 'attached') {
|
||||
return DeviceConnectionInterface.attached;
|
||||
} else if (connectionType == 'wireless') {
|
||||
return DeviceConnectionInterface.wireless;
|
||||
}
|
||||
return switch (stringArg(FlutterOptions.kDeviceConnection)) {
|
||||
'attached' => DeviceConnectionInterface.attached,
|
||||
'wireless' => DeviceConnectionInterface.wireless,
|
||||
_ => null,
|
||||
};
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -290,13 +290,11 @@ class FakeDeviceManager implements DeviceManager {
|
||||
Device? getSingleEphemeralDevice(List<Device> devices) => null;
|
||||
|
||||
List<Device> filteredDevices(DeviceDiscoveryFilter? filter) {
|
||||
if (filter?.deviceConnectionInterface == DeviceConnectionInterface.attached) {
|
||||
return attachedDevices;
|
||||
}
|
||||
if (filter?.deviceConnectionInterface == DeviceConnectionInterface.wireless) {
|
||||
return wirelessDevices;
|
||||
}
|
||||
return attachedDevices + wirelessDevices;
|
||||
return switch (filter?.deviceConnectionInterface) {
|
||||
DeviceConnectionInterface.attached => attachedDevices,
|
||||
DeviceConnectionInterface.wireless => wirelessDevices,
|
||||
null => attachedDevices + wirelessDevices,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user