Getting Started

Getting Started with Flutter

Sky apps are written in Dart. To get started, we need to set up Dart SDK:

Once you have installed Dart SDK, create a new directory and add a
pubspec.yaml:

1
2
3
4
name: your_app_name
dependencies:
  sky: any
  sky_tools: any

Next, create a lib directory (which is where your Dart code will go) and use
the pub tool to fetch the Sky package and its dependencies:

Sky assumes the entry point for your application is a main function in
lib/main.dart:

1
2
3
4
5
6
7
8
9
10
11
import 'package:sky/widgets.dart';

class HelloWorldApp extends App {
  Widget build() {
    return new Center(child: new Text('Hello, world!'));
  }
}

void main() {
  runApp(new HelloWorldApp());
}

Execution starts in main, which in this example runs a new instance of the
HelloWorldApp. The HelloWorldApp builds a Text widget containing the
traditional Hello, world! string and centers it on the screen using a Center
widget. To learn more about the widget system, please see the widgets tutorial.

Setting up your Android device

Currently Sky requires an Android device running the Lollipop (or newer) version
of the Android operating system.

Running a Sky application

The sky pub package includes a sky_tool script to assist in running Sky
applications inside the SkyShell.apk harness. The sky_tool script expects
to be run from the root directory of your application’s package (i.e., the same
directory that contains the pubspec.yaml file).

To run your app with logging, run this command:

The sky_tool start command starts the dev server and uploads your app to the
device, installing SkyShell.apk if needed. The --checked flag triggers
checked mode, in which types are checked, asserts are run, and various
debugging features
are enabled. The sky_tool logs command logs errors and Dart print() output
from the app, automatically limiting the output to just output from Sky Dart
code and the Sky Engine C++ code (which for historical reasons currently uses
the tag chromium.)

To avoid confusion from old log messages, you may wish to call
sky_tool logs --clear before calling sky_tool start, to clear the log
between runs.

Rapid Iteration

As an alternative to running ./packages/sky/sky_tool start every time you make
a change, you might prefer to have the SkyShell reload your app automatically
for you as you edit. To do this, run the following command:

This is a long-running command — just press ctrl-c when you want to stop
listening for changes to the file system and automatically reloading your app.

Currently sky_tool listen only works for Android, but iOS device and iOS
simulator support are coming soon.

Debugging

Sky uses Observatory for
debugging and profiling. While running your Sky app using sky_tool, you can
access Observatory by navigating your web browser to http://localhost:8181/.

Building a standalone APK

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.