From 612ef2095541d0b5fd57ad7d917453d3a22deff7 Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Mon, 21 Dec 2020 18:29:05 +0100 Subject: [PATCH] [flutter_tools] use 1-based index for device selection (#72189) --- packages/flutter_tools/lib/src/device.dart | 6 ++--- .../test/general.shard/device_test.dart | 22 +++++++++---------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/packages/flutter_tools/lib/src/device.dart b/packages/flutter_tools/lib/src/device.dart index 019c129f09..53c8861f5a 100644 --- a/packages/flutter_tools/lib/src/device.dart +++ b/packages/flutter_tools/lib/src/device.dart @@ -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 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 _readUserInput(int deviceCount) async { _terminal.usesTerminalUi = true; final String result = await _terminal.promptForCharInput( - [ for (int i = 0; i < deviceCount; i++) '$i', 'q', 'Q'], + [ for (int i = 0; i < deviceCount; i++) '${i + 1}', 'q', 'Q'], displayAcceptedCharacters: false, logger: _logger, prompt: _userMessages.flutterChooseOne, diff --git a/packages/flutter_tools/test/general.shard/device_test.dart b/packages/flutter_tools/test/general.shard/device_test.dart index 1331d1899d..ebd812669b 100644 --- a/packages/flutter_tools/test/general.shard/device_test.dart +++ b/packages/flutter_tools/test/general.shard/device_test.dart @@ -183,11 +183,11 @@ void main() { ]; final MockTerminal mockTerminal = MockTerminal(); when(mockTerminal.stdinHasTerminal).thenReturn(true); - when(mockTerminal.promptForCharInput(['0', '1', 'q', 'Q'], + when(mockTerminal.promptForCharInput(['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(['0', '1', 'q', 'Q'], + when(mockTerminal.promptForCharInput(['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(['0', '1', 'q', 'Q'], + when(mockTerminal.promptForCharInput(['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(['0', '1', 'q', 'Q'], + when(mockTerminal.promptForCharInput(['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(['0', '1', '2', '3', 'q', 'Q'], + when(mockTerminal.promptForCharInput(['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(['0', '1', 'q', 'Q'], + when(mockTerminal.promptForCharInput(['1', '2', 'q', 'Q'], displayAcceptedCharacters: false, logger: anyNamed('logger'), prompt: anyNamed('prompt'),