Prefer ephemeral devices from command line run (#34802)

This commit is contained in:
Jonah Williams
2019-06-20 14:33:58 -07:00
committed by GitHub
parent 4c56b66fce
commit 25a3121dfd
2 changed files with 73 additions and 5 deletions

View File

@@ -517,12 +517,8 @@ abstract class FlutterCommand extends Command<void> {
}
devices = devices.where((Device device) => device.isSupported()).toList();
// If the user has not specified all devices and has multiple connected
// then filter then list by those supported in the current project. If
// this ends up with a single device we can proceed as normal.
if (devices.length > 1 && !deviceManager.hasSpecifiedAllDevices && !deviceManager.hasSpecifiedDeviceId) {
final FlutterProject flutterProject = FlutterProject.current();
devices.removeWhere((Device device) => !device.isSupportedForProject(flutterProject));
devices = filterDevices(devices);
}
if (devices.isEmpty) {
@@ -698,3 +694,24 @@ abstract class FastFlutterCommand extends FlutterCommand {
);
}
}
// If the user has not specified all devices and has multiple connected
// then filter the list by those supported in the current project and
// remove non-ephemeral device types. If this ends up with a single
// device we can proceed as normal.
@visibleForTesting
List<Device> filterDevices(List<Device> devices) {
final FlutterProject flutterProject = FlutterProject.current();
devices = devices
.where((Device device) => device.isSupportedForProject(flutterProject))
.toList();
// Note: ephemeral is nullable for device types where this is not well
// defined.
if (devices.any((Device device) => device.ephemeral == true)) {
devices = devices
.where((Device device) => device.ephemeral == true)
.toList();
}
return devices;
}