From ffdca6f7e81d435084725e237459f1745229bdee Mon Sep 17 00:00:00 2001 From: Todd Volkert Date: Thu, 27 Apr 2017 13:12:59 -0700 Subject: [PATCH] Fix getDevicesById() (#9646) If the user specified a non-exact device id, it was producing an exception whereby we were trying to listen to the `getAllConnectedDevies()` stream twice. --- packages/flutter_tools/lib/src/device.dart | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/flutter_tools/lib/src/device.dart b/packages/flutter_tools/lib/src/device.dart index 7ba2299e10..b3566906ca 100644 --- a/packages/flutter_tools/lib/src/device.dart +++ b/packages/flutter_tools/lib/src/device.dart @@ -53,7 +53,7 @@ class DeviceManager { bool get hasSpecifiedAllDevices => _specifiedDeviceId == 'all'; Stream getDevicesById(String deviceId) async* { - final Stream devices = getAllConnectedDevices(); + final List devices = await getAllConnectedDevices().toList(); deviceId = deviceId.toLowerCase(); bool exactlyMatchesDeviceId(Device device) => device.id.toLowerCase() == deviceId || @@ -62,15 +62,15 @@ class DeviceManager { device.id.toLowerCase().startsWith(deviceId) || device.name.toLowerCase().startsWith(deviceId); - final Device exactMatch = await devices.firstWhere( - exactlyMatchesDeviceId, defaultValue: () => null); + final Device exactMatch = devices.firstWhere( + exactlyMatchesDeviceId, orElse: () => null); if (exactMatch != null) { yield exactMatch; return; } // Match on a id or name starting with [deviceId]. - await for (Device device in devices.where(startsWithDeviceId)) + for (Device device in devices.where(startsWithDeviceId)) yield device; }