[flutter_tools] use 1-based index for device selection (#72189)
This commit is contained in:
@@ -305,11 +305,11 @@ abstract class DeviceManager {
|
||||
if (userInput.toLowerCase() == 'q') {
|
||||
throwToolExit('');
|
||||
}
|
||||
return devices[int.parse(userInput)];
|
||||
return devices[int.parse(userInput) - 1];
|
||||
}
|
||||
|
||||
void _displayDeviceOptions(List<Device> devices) {
|
||||
int count = 0;
|
||||
int count = 1;
|
||||
for (final Device device in devices) {
|
||||
_logger.printStatus(_userMessages.flutterChooseDevice(count, device.name, device.id));
|
||||
count++;
|
||||
@@ -319,7 +319,7 @@ abstract class DeviceManager {
|
||||
Future<String> _readUserInput(int deviceCount) async {
|
||||
_terminal.usesTerminalUi = true;
|
||||
final String result = await _terminal.promptForCharInput(
|
||||
<String>[ for (int i = 0; i < deviceCount; i++) '$i', 'q', 'Q'],
|
||||
<String>[ for (int i = 0; i < deviceCount; i++) '${i + 1}', 'q', 'Q'],
|
||||
displayAcceptedCharacters: false,
|
||||
logger: _logger,
|
||||
prompt: _userMessages.flutterChooseOne,
|
||||
|
||||
@@ -183,11 +183,11 @@ void main() {
|
||||
];
|
||||
final MockTerminal mockTerminal = MockTerminal();
|
||||
when(mockTerminal.stdinHasTerminal).thenReturn(true);
|
||||
when(mockTerminal.promptForCharInput(<String>['0', '1', 'q', 'Q'],
|
||||
when(mockTerminal.promptForCharInput(<String>['1', '2', 'q', 'Q'],
|
||||
displayAcceptedCharacters: false,
|
||||
logger: anyNamed('logger'),
|
||||
prompt: anyNamed('prompt'),
|
||||
)).thenAnswer((Invocation invocation) async => '0');
|
||||
)).thenAnswer((Invocation invocation) async => '1');
|
||||
|
||||
final DeviceManager deviceManager = TestDeviceManager(
|
||||
devices,
|
||||
@@ -209,11 +209,11 @@ void main() {
|
||||
final MockTerminal mockTerminal = MockTerminal();
|
||||
|
||||
when(mockTerminal.stdinHasTerminal).thenReturn(true);
|
||||
when(mockTerminal.promptForCharInput(<String>['0', '1', 'q', 'Q'],
|
||||
when(mockTerminal.promptForCharInput(<String>['1', '2', 'q', 'Q'],
|
||||
displayAcceptedCharacters: false,
|
||||
logger: anyNamed('logger'),
|
||||
prompt: anyNamed('prompt'),
|
||||
)).thenAnswer((Invocation invocation) async => '1');
|
||||
)).thenAnswer((Invocation invocation) async => '2');
|
||||
|
||||
final DeviceManager deviceManager = TestDeviceManager(
|
||||
devices,
|
||||
@@ -236,11 +236,11 @@ void main() {
|
||||
final MockTerminal mockTerminal = MockTerminal();
|
||||
|
||||
when(mockTerminal.stdinHasTerminal).thenReturn(true);
|
||||
when(mockTerminal.promptForCharInput(<String>['0', '1', 'q', 'Q'],
|
||||
when(mockTerminal.promptForCharInput(<String>['1', '2', 'q', 'Q'],
|
||||
displayAcceptedCharacters: false,
|
||||
logger: anyNamed('logger'),
|
||||
prompt: anyNamed('prompt'),
|
||||
)).thenAnswer((Invocation invocation) async => '0');
|
||||
)).thenAnswer((Invocation invocation) async => '1');
|
||||
|
||||
final DeviceManager deviceManager = TestDeviceManager(
|
||||
devices,
|
||||
@@ -262,11 +262,11 @@ void main() {
|
||||
final MockTerminal mockTerminal = MockTerminal();
|
||||
|
||||
when(mockTerminal.stdinHasTerminal).thenReturn(true);
|
||||
when(mockTerminal.promptForCharInput(<String>['0', '1', 'q', 'Q'],
|
||||
when(mockTerminal.promptForCharInput(<String>['1', '2', 'q', 'Q'],
|
||||
displayAcceptedCharacters: false,
|
||||
logger: anyNamed('logger'),
|
||||
prompt: anyNamed('prompt'),
|
||||
)).thenAnswer((Invocation invocation) async => '1');
|
||||
)).thenAnswer((Invocation invocation) async => '2');
|
||||
|
||||
final DeviceManager deviceManager = TestDeviceManager(
|
||||
devices,
|
||||
@@ -291,11 +291,11 @@ void main() {
|
||||
final MockTerminal mockTerminal = MockTerminal();
|
||||
|
||||
when(mockTerminal.stdinHasTerminal).thenReturn(true);
|
||||
when(mockTerminal.promptForCharInput(<String>['0', '1', '2', '3', 'q', 'Q'],
|
||||
when(mockTerminal.promptForCharInput(<String>['1', '2', '3', '4', 'q', 'Q'],
|
||||
displayAcceptedCharacters: false,
|
||||
logger: anyNamed('logger'),
|
||||
prompt: anyNamed('prompt'),
|
||||
)).thenAnswer((Invocation invocation) async => '2');
|
||||
)).thenAnswer((Invocation invocation) async => '3');
|
||||
|
||||
final DeviceManager deviceManager = TestDeviceManager(
|
||||
devices,
|
||||
@@ -319,7 +319,7 @@ void main() {
|
||||
final MockTerminal mockTerminal = MockTerminal();
|
||||
|
||||
when(mockTerminal.stdinHasTerminal).thenReturn(true);
|
||||
when(mockTerminal.promptForCharInput(<String>['0', '1', 'q', 'Q'],
|
||||
when(mockTerminal.promptForCharInput(<String>['1', '2', 'q', 'Q'],
|
||||
displayAcceptedCharacters: false,
|
||||
logger: anyNamed('logger'),
|
||||
prompt: anyNamed('prompt'),
|
||||
|
||||
Reference in New Issue
Block a user