Prevent crashes on range errors when selecting device (#129290)

Prevent the cli from crashing when a user selects a number that is not valid for `flutter run` device selection

Fixes issue:
- https://github.com/flutter/flutter/issues/129191

*If you had to change anything in the [flutter/tests] repo, include a link to the migration guide as per the [breaking change policy].*
This commit is contained in:
Elias Yishak
2023-06-22 11:52:25 -04:00
committed by GitHub
parent 7c259deaf9
commit 18b94b7f57
2 changed files with 64 additions and 11 deletions

View File

@@ -774,7 +774,7 @@ class TargetDeviceSelection {
throwToolExit('');
}
final int deviceIndex = int.parse(userInputString) - 1;
if (deviceIndex < devices.length) {
if (deviceIndex > -1 && deviceIndex < devices.length) {
chosenDevice = devices[deviceIndex];
}
}