From ca03beda4dbef51b049fe50a6621afdf14aee049 Mon Sep 17 00:00:00 2001 From: Anas <65850618+Anas35@users.noreply.github.com> Date: Wed, 14 Feb 2024 18:19:24 +0530 Subject: [PATCH] [tools] Add column header for emulators information (#142853) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add column information as table header for `flutter emulators` command. **Before:** ``` 2 available emulators: Pixel_3_API_30 • Pixel 3 API 30 • Google • android Resizable_API_33 • Resizable API 33 • Google • android To run an emulator, run 'flutter emulators --launch '. To create a new emulator, run 'flutter emulators --create [--name xyz]'. You can find more information on managing emulators at the links below: https://developer.android.com/studio/run/managing-avds https://developer.android.com/studio/command-line/avdmanager ``` **After:** ``` 2 available emulators: Id • Name • Manufacturer • Platform Pixel_3_API_30 • Pixel 3 API 30 • Google • android Resizable_API_33 • Resizable API 33 • Google • android To run an emulator, run 'flutter emulators --launch '. To create a new emulator, run 'flutter emulators --create [--name xyz]'. You can find more information on managing emulators at the links below: https://developer.android.com/studio/run/managing-avds https://developer.android.com/studio/command-line/avdmanager ``` fixes #140656 --- packages/flutter_tools/lib/src/emulator.dart | 13 ++++++++++++- .../test/general.shard/emulator_test.dart | 12 ++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/packages/flutter_tools/lib/src/emulator.dart b/packages/flutter_tools/lib/src/emulator.dart index e210d2ac94..0277395ae9 100644 --- a/packages/flutter_tools/lib/src/emulator.dart +++ b/packages/flutter_tools/lib/src/emulator.dart @@ -291,8 +291,16 @@ abstract class Emulator { return []; } + const List tableHeader = [ + 'Id', + 'Name', + 'Manufacturer', + 'Platform', + ]; + // Extract emulators information final List> table = >[ + tableHeader, for (final Emulator emulator in emulators) [ emulator.id, @@ -323,7 +331,10 @@ abstract class Emulator { } static void printEmulators(List emulators, Logger logger) { - descriptions(emulators).forEach(logger.printStatus); + final List emulatorDescriptions = descriptions(emulators); + // Prints the first description as the table header, followed by a newline. + logger.printStatus('${emulatorDescriptions.first}\n'); + emulatorDescriptions.sublist(1).forEach(logger.printStatus); } } diff --git a/packages/flutter_tools/test/general.shard/emulator_test.dart b/packages/flutter_tools/test/general.shard/emulator_test.dart index 1e54f5b774..561b49da53 100644 --- a/packages/flutter_tools/test/general.shard/emulator_test.dart +++ b/packages/flutter_tools/test/general.shard/emulator_test.dart @@ -87,6 +87,18 @@ void main() { returnsNormally); }); + testUsingContext('printEmulators prints the the emualtors information with header', () { + Emulator.printEmulators(emulators, testLogger); + + expect(testLogger.statusText, ''' +Id • Name • Manufacturer • Platform + +Nexus_5 • Nexus 5 • Google • android +Nexus_5X_API_27_x86 • Nexus 5X • Google • android +iOS Simulator • iOS Simulator • Apple • android +'''); + }); + testUsingContext('getEmulators with no Android SDK', () async { // Test that EmulatorManager.getEmulators() doesn't throw when there's no Android SDK. final EmulatorManager emulatorManager = EmulatorManager(