LinuxCommandLibrary

flutter

Build, test, and deploy Flutter applications

TLDR

Initialize a new Flutter project in a directory of the same name

$ flutter create [project_name]
copy

Check if all external tools are correctly installed
$ flutter doctor
copy

List or change Flutter channel
$ flutter channel [stable|beta|dev|master]
copy

Run Flutter on all started emulators and connected devices
$ flutter run -d all
copy

Run tests in a terminal from the root of the project
$ flutter test [test/example_test.dart]
copy

Build a release APK targeting most modern smartphones
$ flutter build apk --target-platform [android-arm],[android-arm64]
copy

Delete the build and .dart_tool directories
$ flutter clean
copy

Display help about a specific command
$ flutter help [command]
copy

SYNOPSIS

flutter [global-options] <command> [arguments]
Common commands:
  flutter create <project_name>
  flutter run [options]
  flutter build <apk|ios|web|windows|macos|linux> [options]
  flutter test [options]
  flutter doctor [options]
  flutter upgrade [options]

PARAMETERS

create
    Creates a new Flutter project in the specified directory. Includes project structure, basic code, and necessary configuration files.

run
    Runs your Flutter application on a connected device (simulator, emulator, physical device) or in a web browser/desktop window. Supports hot reload for rapid development.

build
    Builds a production-ready artifact for the specified target platform (e.g., APK for Android, IPA for iOS, JavaScript for web, executable for desktop).

test
    Runs the tests defined in your Flutter project. Supports unit, widget, and integration tests.

doctor
    Checks your development environment and displays a report of the status of your Flutter installation and any missing dependencies (SDKs, tools, IDEs).

clean
    Deletes the 'build' directory and other generated files from your Flutter project. Useful for resolving build issues or reducing project size.

upgrade
    Upgrades your Flutter SDK to the latest available version. Also updates Dart SDK and installed packages.

pub
    Manages Dart package dependencies for your Flutter project. Common uses include `pub get` to download dependencies and `pub upgrade` to update them.

install
    Installs a Flutter application on a connected device without running it immediately. Useful for quick deployment of debug builds.

analyze
    Analyzes the Dart code in your project for potential issues, errors, warnings, and style violations.

config
    Configures Flutter settings such as device selection, analytics reporting, and enable/disable desktop development.

devices
    Lists all connected physical devices and running emulators/simulators available for running Flutter applications.

emulators
    Manages Android emulators. Used to list, create, and launch Android Virtual Devices (AVDs).

format
    Formats Dart code according to Flutter's style guide.

DESCRIPTION

The flutter command is the primary command-line interface (CLI) tool for interacting with the Flutter SDK. Flutter is an open-source UI software development kit created by Google for building beautiful, natively compiled applications for mobile (Android, iOS), web, and desktop (Windows, macOS, Linux) from a single codebase. The command provides a comprehensive set of functionalities for managing the entire application development lifecycle. This includes creating new projects, running applications on various devices (simulators, emulators, physical devices, web browsers, desktop environments), building production-ready packages, testing code, analyzing project health, and upgrading the SDK itself.

The flutter CLI simplifies complex tasks such as dependency management (via Dart's pub package manager), debugging, and deployment. Its core philosophy revolves around rapid development with features like stateful hot reload, which allows developers to see changes instantly without losing application state. It acts as the gateway to the Flutter ecosystem, enabling developers to leverage Dart language features and a rich set of pre-built widgets to create highly performant and visually appealing user interfaces across multiple platforms.

CAVEATS

The flutter command relies heavily on a properly configured development environment. Key caveats include:

  • SDK Dependencies: Requires the Flutter SDK to be installed and its path added to the system's PATH variable.
  • Platform-Specific SDKs: For mobile development, it necessitates the installation of Android SDK (Android Studio) and Xcode (for iOS on macOS). These platform SDKs provide the necessary compilers, emulators, and tools.
  • IDE/Editor Integration: While CLI-driven, optimal development often requires integration with an IDE like VS Code or Android Studio, which provide Flutter plugins for advanced features (debugging, hot reload shortcuts).
  • Dart Language: Flutter applications are written in Dart, so familiarity with Dart syntax and concepts is crucial.
  • Resource Intensive: Building and running Flutter applications, especially emulators, can be resource-intensive, requiring sufficient RAM and CPU.
  • Network Access: `flutter pub get` and `flutter upgrade` require internet access to download packages and SDK updates.

GLOBAL OPTIONS

The flutter command supports a few global options that apply to any subcommand:

  • --version: Shows the Flutter SDK version.
  • --verbose: Shows additional diagnostic output.
  • --color: Use terminal colors (auto-detected by default).
  • --no-color: Do not use terminal colors.
  • --device-id <id>: Specifies the ID of the device to target when running or building applications.

ENVIRONMENT VARIABLES

The flutter command respects several environment variables for configuration:

  • FLUTTER_ROOT: Specifies the path to the Flutter SDK installation. Typically set automatically during setup.
  • PUB_CACHE: Specifies the directory where Dart packages are cached.
  • FLUTTER_CHANNEL: Defines the update channel for the Flutter SDK (e.g., 'stable', 'beta', 'dev'). This affects which version `flutter upgrade` fetches.

HOT RELOAD VS. HOT RESTART

Two fundamental features for rapid development:

  • Hot Reload: Injects updated source code files into the running Dart Virtual Machine (VM). Most changes, including UI and logic, can be applied instantly without losing application state.
  • Hot Restart: Flushes all application state and rebuilds the widget tree from scratch. This is necessary for changes to `main()` or stateful objects not tracked by hot reload. Both are typically invoked via `flutter run` or IDE shortcuts.

HISTORY

Flutter was initially released by Google in May 2017 (alpha release). Its development began as "Sky" in 2015. The first stable release, Flutter 1.0, was announced in December 2018 at the Flutter Live event, focusing primarily on mobile development for Android and iOS. A key development was the introduction of "hot reload," allowing developers to inject code changes into a running app without losing its state, significantly speeding up development cycles.

Subsequent versions expanded Flutter's capabilities to new platforms. Flutter 1.9 introduced web support (beta), and Flutter 2.0, released in March 2021, brought stable web support and broadened desktop application development to stable releases for Windows, macOS, and Linux. This multi-platform capability from a single codebase has been a significant driver of its adoption, making the flutter command an indispensable tool for cross-platform developers.

SEE ALSO

dart(1), adb(1), xcode-select(1), gradle(1), cocoapods(1)

Copied to clipboard