Show unsupported devices when no supported devices are connected (#56531)
This commit is contained in:
@@ -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 =>
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user