Show unsupported devices when no supported devices are connected (#56531)

This commit is contained in:
JustWe
2020-06-04 07:14:38 +08:00
committed by GitHub
parent 91e7678f79
commit 6c8d7b00ff
6 changed files with 100 additions and 7 deletions

View File

@@ -237,6 +237,9 @@ class UserMessages {
"matching '$deviceId'";
String get flutterNoDevicesFound => 'No devices found';
String get flutterNoSupportedDevices => 'No supported devices connected.';
String flutterMissPlatformProjects(List<String> unsupportedDevicesType) =>
'If you would like your app to run on ${unsupportedDevicesType.join(' or ')}, consider running `flutter create .` to generate projects for these platforms.';
String get flutterFoundButUnsupportedDevices => 'The following devices were found, but are not supported by this project:';
String flutterFoundSpecifiedDevices(int count, String deviceId) =>
'Found $count devices with name or id matching $deviceId:';
String get flutterSpecifyDeviceWithAllOption =>

View File

@@ -557,6 +557,13 @@ abstract class Device {
await descriptions(devices).forEach(globals.printStatus);
}
static List<String> devicesPlatformTypes(List<Device> devices) {
return devices
.map(
(Device d) => d.platformType.toString(),
).toSet().toList()..sort();
}
/// Convert the Device object to a JSON representation suitable for serialization.
Future<Map<String, Object>> toJson() async {
final bool isLocalEmu = await isLocalEmulator;

View File

@@ -823,11 +823,28 @@ abstract class FlutterCommand extends Command<void> {
if (devices.isEmpty && deviceManager.hasSpecifiedDeviceId) {
globals.printStatus(userMessages.flutterNoMatchingDevice(deviceManager.specifiedDeviceId));
return null;
} else if (devices.isEmpty && deviceManager.hasSpecifiedAllDevices) {
globals.printStatus(userMessages.flutterNoDevicesFound);
return null;
} else if (devices.isEmpty) {
globals.printStatus(userMessages.flutterNoSupportedDevices);
if (deviceManager.hasSpecifiedAllDevices) {
globals.printStatus(userMessages.flutterNoDevicesFound);
} else {
globals.printStatus(userMessages.flutterNoSupportedDevices);
}
final List<Device> unsupportedDevices = await deviceManager.getDevices();
if (unsupportedDevices.isNotEmpty) {
final StringBuffer result = StringBuffer();
result.writeln(userMessages.flutterFoundButUnsupportedDevices);
result.writeAll(
await Device.descriptions(unsupportedDevices)
.map((String desc) => desc)
.toList(),
'\n',
);
result.writeln('');
result.writeln(userMessages.flutterMissPlatformProjects(
Device.devicesPlatformTypes(unsupportedDevices),
));
globals.printStatus(result.toString());
}
return null;
} else if (devices.length > 1 && !deviceManager.hasSpecifiedAllDevices) {
if (deviceManager.hasSpecifiedDeviceId) {