Run flutter application from command line

I am new to flutter, I just write it down something that I learned when I learning flutter.

Run flutter application from command line
I got this picture from beach, it was the art of a little crab

List devices

First, when I create a project or get source code from github, I want to run the application to have a look. First of all, I need to run it on a device, so I need to know which devices that I can run, we can use the following command to list all the device that flutter can run on.flutter devices

The sample output of the command are like below:$ flutter devices
3 connected devices:iPhone 11 (mobile) • FE3B6CB8-AA93-47B6-874F-8C59CBB563E3 • ios            •
com.apple.CoreSimulator.SimRuntime.iOS-15-5 (simulator)
macOS (desktop)    • macos                                • darwin-x64     • macOS 12.4 21F79 darwin-x64
Chrome (web)       • chrome                               • web-javascript • Google Chrome 101.0.4951.64

Form the output, we don’t know the field name, each device has four columns, separated with •, when we run flutter devices --machine command, we can get the json format, form the json output, we can see that the fields of the output are: name, id, targetPlatform and sdk.

Run application with specify device

We can run the application with the name and id for the device, on my machine, I have three devices, so I can run with the following commands under the application root folder:

Run on iOS simulator# Run with device name
flutter run -d "iPhone 11"# Run with device id
flutter run -d FE3B6CB8-AA93-47B6-874F-8C59CBB563E3

Run on macOS desktop# Run with device name
flutter run -d macOS# Run with device id
flutter run -d macos

Run on Chrome web browser# Run with device name
flutter run -d Chrome
# Run with device id
flutter run -d chrome

Thanks for your reading!