blob: 2b5fee15b6856c576de62ed0588dce5684bd87f3 [file] [log] [blame] [view]
Adam Barth576795d2015-11-08 21:33:00 -08001Contributing to Flutter
2=======================
3
Greg Spencere60087a2018-08-07 13:41:33 -07004[![Build Status](https://api.cirrus-ci.com/github/flutter/flutter.svg)](https://cirrus-ci.org/flutter/flutter)
Adam Barth576795d2015-11-08 21:33:00 -08005
Ian Hicksoncffe4812016-12-10 21:46:57 -08006_See also: [Flutter's code of conduct](https://flutter.io/design-principles/#code-of-conduct)_
7
Ian Hickson529d2502018-06-01 12:04:20 -07008Welcome
9-------
10
11We gladly accept contributions via GitHub pull requests.
12
13Please become familiar with our
14[style guide](https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo) and
15[design philosophy](https://flutter.io/design-principles/). These guidelines are intended to
16keep the code consistent and avoid common pitfalls, and being familiar with them will
17make everything much easier for you. If you have questions about our processes or are looking
18for random tips and tricks, you may be interested in the [engine wiki](https://github.com/flutter/engine/wiki) and [framework wiki](https://github.com/flutter/flutter/wiki).
19
20This document will introduce you to the basic steps for developing for the Flutter framework (Dart).
21If you're interested in developing for the Flutter engine (C++, Java, Objective C), please
22switch to [the engine repo's `CONTRIBUTING.md` document](https://github.com/flutter/engine/blob/master/CONTRIBUTING.md).
23
24If you have an itch, work on that. If you are just looking for something good to start with, consider
25[the issues marked "easy fix"](https://github.com/flutter/flutter/issues?q=is%3Aopen+is%3Aissue+label%3A%22easy+fix%22+sort%3Areactions-%2B1-desc) in our issues list.
26
Adam Barth576795d2015-11-08 21:33:00 -080027Things you will need
28--------------------
29
Michael Goderbauer13edb322017-06-26 09:47:05 -070030 * Linux, Mac OS X, or Windows
Adam Barth576795d2015-11-08 21:33:00 -080031 * git (used for source version control).
Jacob Richman05b4bd72018-08-28 16:22:50 -070032 * An IDE. We recommend [Android Studio with the Flutter plugin](https://flutter.io/using-ide/).
Adam Barth576795d2015-11-08 21:33:00 -080033 * An ssh client (used to authenticate with GitHub).
34 * Python (used by some of our tools).
Adam Barth576795d2015-11-08 21:33:00 -080035 * The Android platform tools (see [Issue #55](https://github.com/flutter/flutter/issues/55)
Adam Barthf4c62a82015-11-08 22:18:16 -080036 about downloading the Android platform tools automatically).
Ian Hickson82686642016-02-08 13:39:24 -080037 _If you're also working on the Flutter engine, you can use the
Adam Barthf4c62a82015-11-08 22:18:16 -080038 copy of the Android platform tools in
Ian Hickson82686642016-02-08 13:39:24 -080039 `.../engine/src/third_party/android_tools/sdk/platform-tools`._
Jacob Richman05b4bd72018-08-28 16:22:50 -070040 - Mac: `brew cask install android-platform-tools`
Adam Barth576795d2015-11-08 21:33:00 -080041 - Linux: `sudo apt-get install android-tools-adb`
42
43Getting the code and configuring your environment
44-------------------------------------------------
45
46 * Ensure all the dependencies described in the previous section, in particular
Ian Hicksone23d7602016-02-15 10:46:24 -080047 git, ssh, and python are installed. Ensure that `adb`
48 (from the Android platform tools) is in your path (e.g.,
49 that `which adb` prints sensible output).
Adam Barth576795d2015-11-08 21:33:00 -080050 * Fork `https://github.com/flutter/flutter` into your own GitHub account. If
51 you already have a fork, and are now installing a development environment on
52 a new machine, make sure you've updated your fork so that you don't use stale
53 configuration options from long ago.
54 * If you haven't configured your machine with an SSH key that's known to github then
55 follow the directions here: https://help.github.com/articles/generating-ssh-keys/.
56 * `git clone git@github.com:<your_name_here>/flutter.git`
57 * `cd flutter`
58 * `git remote add upstream git@github.com:flutter/flutter.git` (So that you
59 fetch from the master repository, not your clone, when running `git fetch`
60 et al.)
Adam Barth576795d2015-11-08 21:33:00 -080061 * Add this repository's `bin` directory to your path. That will let you use the
Ian Hicksone23d7602016-02-15 10:46:24 -080062 `flutter` command in this directory more easily.
Lex Berezhny778742e2016-02-27 12:35:05 -050063 * Run `flutter update-packages` This will fetch all the Dart packages that
64 Flutter depends on. You can replicate what this script does by running
65 `pub get` in each directory that contains a `pubspec.yaml` file.
Greg Spencer797b39e2017-11-13 10:55:22 -080066 * If you plan on using IntelliJ as your IDE, then also run
67 `flutter ide-config --overwrite` to create all of the IntelliJ configuration
68 files so you can open the main flutter directory as a project and run examples
69 from within the IDE.
Adam Barth576795d2015-11-08 21:33:00 -080070
71Running the examples
72--------------------
73
Greg Spencer797b39e2017-11-13 10:55:22 -080074To run an example, switch to that example's directory, and use `flutter run`.
75Make sure you have an emulator running, or a device connected over USB and
76debugging enabled on that device.
Adam Barth576795d2015-11-08 21:33:00 -080077
Ali Ghassemi53c86e02016-05-20 13:06:03 -070078 * `cd examples/hello_world`
79 * `flutter run`
Adam Barth576795d2015-11-08 21:33:00 -080080
81You can also specify a particular Dart file to run if you want to run an example
82that doesn't have a `lib/main.dart` file using the `-t` command-line option. For
Ali Ghassemi705b5d12016-05-20 13:53:18 -070083example, to run the `widgets/spinning_square.dart` example in the [examples/layers](examples/layers)
Adam Barth576795d2015-11-08 21:33:00 -080084directory on a connected Android device, from that directory you would run:
Ali Ghassemi53c86e02016-05-20 13:06:03 -070085`flutter run -t widgets/spinning_square.dart`
Adam Barth576795d2015-11-08 21:33:00 -080086
87When running code from the examples directory, any changes you make to the
88example code, as well as any changes to Dart code in the
89[packages/flutter](packages/flutter) directory and subdirectories, will
90automatically be picked when you relaunch the app. You can do the same for your
91own code by mimicking the `pubspec.yaml` files in the `examples` subdirectories.
92
Ian Hickson895aaa92016-12-15 15:59:57 -080093Running the analyzer
94--------------------
95
Ian Hickson36e71382017-09-23 22:23:09 -070096When editing Flutter code, it's important to check the code with the
97analyzer. There are two main ways to run it. In either case you will
98want to run `flutter update-packages` first, or you will get bogus
99error messages about core classes like Offset from `dart:ui`.
Ian Hickson895aaa92016-12-15 15:59:57 -0800100
Devon Carew09dec7f2018-05-10 09:48:40 -0700101For a one-off, use `flutter analyze --flutter-repo`. This uses the `analysis_options.yaml` file
Ian Hickson895aaa92016-12-15 15:59:57 -0800102at the root of the repository for its configuration.
103
104For continuous analysis, use `flutter analyze --flutter-repo --watch`. This uses normal
Dan Rubel3a31c352017-08-15 08:46:42 -0400105`analysis_options.yaml` files, and they can differ from package to package.
Ian Hickson895aaa92016-12-15 15:59:57 -0800106
107If you want to see how many members are missing dartdocs, you should use the first option,
108providing the additional command `--dartdocs`.
109
110If you omit the `--flutter-repo` option you may end up in a confusing state because that will
111assume you want to check a single package and the flutter repository has several packages.
112
113
Adam Barth576795d2015-11-08 21:33:00 -0800114Running the tests
115-----------------
116
Seth Laddd6dad952018-01-26 16:34:08 -0800117To automatically find all files named `_test.dart` inside a package's `test/` subdirectory, and
118run them inside the flutter shell as a test, use the `flutter test` command, e.g:
Adam Barth576795d2015-11-08 21:33:00 -0800119
Eric Seidel723e5f72015-12-08 14:09:47 -0800120 * `cd examples/stocks`
Eric Seidel724388d2015-12-08 13:51:05 -0800121 * `flutter test`
Adam Barth576795d2015-11-08 21:33:00 -0800122
Eric Seidel723e5f72015-12-08 14:09:47 -0800123Individual tests can also be run directly, e.g. `flutter test lib/my_app_test.dart`
124
Seth Laddd6dad952018-01-26 16:34:08 -0800125Flutter tests use [package:flutter_test](https://github.com/flutter/flutter/tree/master/packages/flutter_test)
126which provides flutter-specific extensions on top of [package:test](https://pub.dartlang.org/packages/test).
Adam Barth576795d2015-11-08 21:33:00 -0800127
Seth Laddd6dad952018-01-26 16:34:08 -0800128`flutter test` runs tests inside the flutter shell. To debug tests in Observatory, use the `--start-paused`
129option to start the test in a paused state and wait for connection from a debugger. This option lets you
130set breakpoints before the test runs.
Eric Seidel723e5f72015-12-08 14:09:47 -0800131
Alexander Aprelev391e91c2018-08-30 07:30:25 -0700132To run analysis and all the tests for the entire Flutter repository, the same way that Cirrus runs them, run `dart dev/bots/test.dart` and `dart dev/bots/analyze.dart`.
Eric Seidel723e5f72015-12-08 14:09:47 -0800133
Seth Laddd6dad952018-01-26 16:34:08 -0800134If you've built [your own flutter engine](#working-on-the-engine-and-the-framework-at-the-same-time), you
135can pass `--local-engine` to change what flutter shell `flutter test` uses. For example,
Adam Barthb4002502016-05-31 10:28:25 -0700136if you built an engine in the `out/host_debug_unopt` directory, you can pass
137`--local-engine=host_debug_unopt` to run the tests in that engine.
Adam Barth576795d2015-11-08 21:33:00 -0800138
Ian Hickson895aaa92016-12-15 15:59:57 -0800139Flutter tests are headless, you won't see any UI. You can use
Ian Hickson34190682015-11-09 00:30:45 -0800140`print` to generate console output or you can interact with the DartVM
141via observatory at [http://localhost:8181/](http://localhost:8181/).
Adam Barth576795d2015-11-08 21:33:00 -0800142
143Adding a test
144-------------
145
Ian Hickson895aaa92016-12-15 15:59:57 -0800146To add a test to the Flutter package, create a file whose name
Ian Hickson7151fdd2015-12-15 22:32:45 -0800147ends with `_test.dart` in the `packages/flutter/test` directory. The
Mikkel Nygaard Ravn711174a2018-05-24 17:15:35 +0200148test should have a `main` function and use the `flutter_test` package.
Adam Barth576795d2015-11-08 21:33:00 -0800149
xster606ee362017-01-25 19:00:06 -0800150Working with flutter tools
151--------------------------
152
krisgiesingb6185b62017-10-05 16:34:16 -0700153The flutter tool itself is built when you run `flutter` for the first time and each time
xster606ee362017-01-25 19:00:06 -0800154you run `flutter upgrade`. If you want to alter and re-test the tool's behavior itself,
155locally commit your tool changes in git and the tool will be rebuilt from Dart sources
156in `packages/flutter_tools` the next time you run `flutter`.
157
Michael Goderbauer7532a992017-08-10 08:46:56 -0700158Alternatively, delete the `bin/cache/flutter_tools.snapshot` file. Doing so will
159force a rebuild of the tool from your local sources the next time you run `flutter`.
160
xster606ee362017-01-25 19:00:06 -0800161flutter_tools' tests run inside the Dart command line VM rather than in the
Phil Quitslund82e18822017-12-14 06:01:28 -0800162flutter shell. To run the tests, ensure that no devices are connected,
163then navigate to `flutter_tools` and execute:
xster606ee362017-01-25 19:00:06 -0800164
Phil Quitslund82e18822017-12-14 06:01:28 -0800165```shell
Mikkel Nygaard Ravn9bc048c2018-02-08 22:15:08 +0100166../../bin/cache/dart-sdk/bin/pub run test -j1
Phil Quitslund82e18822017-12-14 06:01:28 -0800167```
xster606ee362017-01-25 19:00:06 -0800168
169The pre-built flutter tool runs in release mode with the observatory off by default.
170To enable debugging mode and the observatory on the `flutter` tool, uncomment the
171`FLUTTER_TOOL_ARGS` line in the `bin/flutter` shell script.
172
Ian Hickson529d2502018-06-01 12:04:20 -0700173Using git
174---------
Ian Hickson895aaa92016-12-15 15:59:57 -0800175
Adam Barth576795d2015-11-08 21:33:00 -0800176To start working on a patch:
177
178 * `git fetch upstream`
179 * `git checkout upstream/master -b name_of_your_branch`
Ian Hickson895aaa92016-12-15 15:59:57 -0800180 * Hack away.
Ian Hickson34190682015-11-09 00:30:45 -0800181 * `git commit -a -m "<your informative commit message>"`
Adam Barth576795d2015-11-08 21:33:00 -0800182 * `git push origin name_of_your_branch`
183
184To send us a pull request:
185
186* `git pull-request` (if you are using [Hub](http://github.com/github/hub/)) or
187 go to `https://github.com/flutter/flutter` and click the
188 "Compare & pull request" button
189
190Please make sure all your checkins have detailed commit messages explaining the patch.
Adam Barth576795d2015-11-08 21:33:00 -0800191
Ian Hicksonbe9dd4b2017-07-13 10:23:29 -0700192Once you've gotten an LGTM from a project maintainer and once your PR has received
Greg Spencere60087a2018-08-07 13:41:33 -0700193the green light from all our automated testing (running on Cirrus, etc), and once
Ian Hicksonbe9dd4b2017-07-13 10:23:29 -0700194the tree is green (see the [design principles](https://flutter.io/design-principles/)
195document for more details), submit your changes to the `master` branch using one of
196the following methods:
yjbanov15e7bdb2016-02-02 11:17:16 -0800197
Ali Ghassemi53c86e02016-05-20 13:06:03 -0700198* Wait for one of the project maintainers to submit it for you.
yjbanov15e7bdb2016-02-02 11:17:16 -0800199* Click the green "Merge pull request" button on the GitHub UI of your pull
200 request (requires commit access)
yjbanov15e7bdb2016-02-02 11:17:16 -0800201
Adam Barth576795d2015-11-08 21:33:00 -0800202You must complete the
203[Contributor License Agreement](https://cla.developers.google.com/clas).
204You can do this online, and it only takes a minute.
205If you've never submitted code before, you must add your (or your
206organization's) name and contact info to the [AUTHORS](AUTHORS) file.
207
Ian Hicksoncffe4812016-12-10 21:46:57 -0800208We grant commit access to people who have gained our trust and demonstrated
209a commitment to Flutter.
210
krisgiesingb6185b62017-10-05 16:34:16 -0700211Tools for tracking and improving test coverage
212----------------------------------------------
Adam Barth56039c02016-06-23 13:43:42 -0700213
214We strive for a high degree of test coverage for the Flutter framework. We use
215Coveralls to [track our test coverage](https://coveralls.io/github/flutter/flutter?branch=master).
216You can download our current coverage data from cloud storage and visualize it
217in Atom as follows:
218
Adam Barth428023c2017-02-08 10:56:03 -0800219 * Install [Atom](https://atom.io/).
Adam Barth56039c02016-06-23 13:43:42 -0700220 * Install the [lcov-info](https://atom.io/packages/lcov-info) package for Atom.
Adam Barth10931af2016-06-23 16:31:25 -0700221 * Open the `packages/flutter` folder in Atom.
222 * Open a Dart file in the `lib` directory an type `Ctrl+Alt+C` to bring up the
223 coverage data.
224
225If you don't see any coverage data, check that you have an `lcov.info` file in
226the `packages/flutter/coverage` directory. It should have been downloaded by the
227`flutter update-packages` command you ran previously.
Adam Barth56039c02016-06-23 13:43:42 -0700228
Adam Barth46da9e82016-06-23 18:02:55 -0700229If you want to iterate quickly on improving test coverage, consider using this
230workflow:
231
232 * Open a file and observe that some line is untested.
233 * Write a test that exercises that line.
234 * Run `flutter test --merge-coverage path/to/your/test_test.dart`.
235 * After the test passes, observe that the line is now tested.
236
237This workflow merges the coverage data from this test run with the base coverage
238data downloaded by `flutter update-packages`.
239
Adam Barth56039c02016-06-23 13:43:42 -0700240See [issue 4719](https://github.com/flutter/flutter/issues/4719) for ideas about
241how to improve this workflow.
242
Adam Barth576795d2015-11-08 21:33:00 -0800243Working on the engine and the framework at the same time
244--------------------------------------------------------
245
246You can work both with this repository (flutter.git) and the Flutter
247[engine repository](https://github.com/flutter/engine) at the same time using
248the following steps.
249
2501. Follow the instructions above for creating a working copy of this repository.
251
2522. Follow the [contributing instructions](https://github.com/flutter/engine/blob/master/CONTRIBUTING.md)
Yegore9cf9502018-03-23 17:51:41 -0700253 in the engine repository to create a working copy of the engine. The instructions
254 also explain how to use a locally-built engine instead of the one bundled with
255 your installation of the Flutter framework.
Adam Barth576795d2015-11-08 21:33:00 -0800256
257Making a breaking change to the engine
258--------------------------------------
259
krisgiesing3dfdf4b2016-03-15 13:16:48 -0700260If you make a breaking change to the engine, you'll need to land your change in a
Adam Barth576795d2015-11-08 21:33:00 -0800261few steps:
262
2631. Land your change in the engine repository.
264
2652. Publish a new version of the engine that contains your change. See the
266 engine's [release process](https://github.com/flutter/engine/wiki/Release-process)
267 for instructions about how to publish a new version of the engine. Publishing
268 a new version is important in order to not break folks using prebuilt
269 binaries in their workflow (e.g., our customers).
270
Seth Laddd6dad952018-01-26 16:34:08 -0800271API docs for master branch
272--------------------------
273
274To view the API docs for the `master` branch,
275visit https://master-docs-flutter-io.firebaseapp.com/.
276
277Those docs should be updated after a successful CI build
278of Flutter's `master` branch.
279
280(Looking for the API docs for our releases?
281Please visit https://docs.flutter.io.)
Yegorbf4409f2017-12-06 17:30:44 -0800282
283Build infrastructure
284--------------------
285
286We build and test Flutter on:
287
Greg Spencere60087a2018-08-07 13:41:33 -0700288- [Cirrus](https://cirrus-ci.com/) ([details](.cirrus.yml))
Yegorbf4409f2017-12-06 17:30:44 -0800289- Chromebots (a.k.a. "recipes", [details](dev/bots/README.md))
Leaf Petersen1dca1b22018-01-11 08:55:14 -0800290- Devicelab (a.k.a. "cocoon", [details](dev/devicelab/README.md))