Get started: web apps

    With DartPad you can experiment with the Dart language and APIs,no download necessary.

    For example, here’s an embedded DartPad that lets you play withthe code for a todo-list generator.Click Run to run the app;the console output appears beneath the code.Try editing the source code—perhaps you’d like to add “horses”to the list of pets. To get the full DartPad experience,which includes the web UI that the app produces,

    Note: If you see an empty box instead of code, go to theDartPad troubleshooting page.

    More information:

    2. Install Dart

    Once you’re ready to move beyond DartPad and develop real apps,you need the Dart SDK.

    • Windows
    • Linux
    • Mac

    Use to install a stable release of the Dart SDK:

    You can use Aptitude to install the Dart SDK on Linux.

    • Perform the following one-time setup:
    1. $ sudo apt-get install apt-transport-https
    2. $ sudo sh -c 'curl https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add -'
    • Install the Dart SDK:
    1. $ sudo apt-get update
    2. $ sudo apt-get install dart

    With Homebrew, installing Dart is easy.

    Important: For more information, including how to adjust your , see .

    1. $ pub global activate webdev
    2. $ pub global activate stagehand

    _web_Although using an IDE is optional, we highly recommend using one.For a list of available IDEs, see theoverview of editors & debuggers.

    4. Create a web app

    To create a web app from the command line, use these commands:

    1. $ mkdir quickstart
    2. $ cd quickstart
    3. $ stagehand web-simple

    _web_To create the same web app from an IDE that has Dart integration,create a project using the template named Bare-bones Web App.

    To run the app from the command line, use to build and serve the app:

    _web_Or run the app from your IDE.

    To view your app, use the Chrome browser to visit the app’s URL —for example, localhost:8080.

    Whether you use an IDE or the command line, builds and serves your appusing the Dart development compiler, dartdevc.Startup is slowest the first time dartdevc builds and serves your app.After that, assets are cached on disk and incremental builds are much faster.

    Once your app has compiled, the browser should display“Your Dart app is running.”

    6. Add custom code to the app

    • Copy the thingsTodo() function from the DartPad aboveto the web/main.dart file.

    • In the main() function, initialize the output element usingthingsTodo():

    1. void main() {
    2. Element output = querySelector('#output');
    3. output.children.addAll(thingsTodo().map(newLI));
    4. }
    5.  
    6. LIElement newLI(String itemText) => LIElement()..text = itemText;
    7.  
    8. Iterable<String> thingsTodo() sync* { ... }
    • The webdev tool automatically rebuilds your app.Refresh the app’s browser window.Now your simple Dart app has a todo list!It should look something like this:Running the revised app

    • Optionally, improve the formatting by editing ,then reload the app to check your changes.

    1. #output {
    2. padding: 20px;
    3. text-align: left;
    4. }

    Use Chrome DevTools to set breakpoints, view values and types,and step through your app’s Dart code.For setup details and a walkthrough, see.

    Feeling lost? Don’t worry! This was a whirlwind introduction to Dart and web programming that left out many details. For a gentler approach, try a low-level HTML tutorial for Dart.

    What next?

    Check out these resources:

    If you get stuck, find help at