| layout | title | nav_title | permalink |
|---|---|---|---|
page |
Getting Started with Flutter |
Getting Started |
/getting-started/ |
Flutter currently supports developers on Mac and Linux, with Windows support in the works.
To get started, we need to set up Dart SDK:
- Install the Dart SDK:
- Mac:
brew tap dart-lang/dart && brew install dart --devel - Linux: See www.dartlang.org/downloads/linux.html
- Windows: Stay tuned, Windows support is in the works.
- Mac:
- Ensure that the
pubexecutable is in yourPATH.
Once you have installed Dart SDK, activate the flutter command line
tool and add it to your path:
$ pub global activate flutter
$ export PATH=$HOME/.pub-cache/bin:$PATH
Now we can use the flutter command to create a project named my_app:
$ flutter init -o my_app
This command creates a my_app directory that contains a simple demo
app that uses Material Design.
The code for your app is in my_app/lib/main.dart. Execution starts in
the main function, which uses runApp to run a MaterialApp widget.
The MaterialApp widget is configured with a route map, with one entry
for every screen of your app. In this case, there's only one screen, the
home screen named /, which builds a FlutterDemo component.
To learn more about how to build apps with Flutter, please see the tutorial.
Currently Flutter requires an Android device running the KitKat (or newer) version of the Android operating system.
-
Install the
adbtool from the Android SDK: -
Mac:
brew install android-platform-tools -
Linux:
sudo apt-get install android-tools-adb- If the version of
adbprovided by your Linux distribution is too old, you might need to install the Android SDK manually.
- If the version of
-
Enable developer mode on your device by visiting
Settings > About phoneand tapping theBuild numberfield seven times. -
Enable
Android debugginginSettings > Developer options. -
Using a USB cable, plug your phone into your computer. If prompted on your device, authorize your computer to access your device.
You can use the flutter command to run Flutter apps on your devices. First,
change directories to the root of your apps (i.e., the same directory that
contains the pubspec.yaml file).
To start your app, use the start command:
$ flutter start --checked
$ flutter logs
The --checked flag turns on type checking and asserts, both of which are quite
useful during development. The logs command lets you see textual output from
your app, including print statements and unhandled exceptions. To avoid confusion
from old log messages, you might want to use flutter logs --clear to clear the
logs between runs.
To improve your iteration speed, you can use flutter listen --checked instead
of flutter start. The listen command watches the file system and automatically
reloads your app whenever you make a change to its code.
Flutter uses Observatory for debugging and profiling. While running your app, you can access Observatory by navigating your web browser to http://localhost:8181/.
Although it is possible to build a standalone APK containing your application,
doing so right now is difficult. If you're feeling brave, you can see how we
build the Stocks.apk in
examples/stocks.
Eventually we plan to make this much easier and support platforms other than
Android, but that work still in progress.