Skip to content

Instantly share code, notes, and snippets.

Dart Cookbook

Strings

A Dart string represents a sequence of characters encoded in UTF-16. Decoding UTF-16 yields Unicode code points. Borrowing terminology from Go, Dart uses the term rune for an integer representing a Unicode code

<!DOCTYPE html>
<html>
<body>
<div>
<h3>Person record</h3>
<p><em>First Name: </em> {{ person['firstName'] }}</p>
<p><em>Last Name: </em> {{ person['lastName'] }}</p>
<p><em>Address: </em>
var foo = "fee fi fo fum";
import 'dart:html';
import 'dart:js';
void main() {
JsObject google = context['google'];
google.callMethod('load', ['visualization', '1',
new JsObject.jsify({'packages': ['corechart']})]);
google.callMethod('setOnLoadCallback', [() {
var data = google['visualization'].callMethod('arrayToDataTable',
new JsObject.jsify([
// index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="import" href="foo_element.html">
<link rel="import" href="bar_element.html">
// When to use expectAsync?
import 'package:unittest/unittest.dart';
import 'dart:async';
syncAdd(x, y) => x + y;
asyncAdd(x, y) => new Future.value(x + y);
void main() {
-rw-r--r-- 1 shailentuli 5000 18B Mar 31 09:55 animation.dart.html_reference
-rw-r--r-- 1 shailentuli 5000 809K Mar 31 09:55 animation.dart.js
-rw-r--r-- 1 shailentuli 5000 1.1M Mar 31 09:55 animation.dart.precompiled.js
-rw-r--r-- 1 shailentuli 5000 1.6K Mar 31 09:55 animation.html
-rw-r--r-- 1 shailentuli 5000 23B Mar 31 09:55 bouncing_balls.dart.html_reference
-rw-r--r-- 1 shailentuli 5000 790K Mar 31 09:55 bouncing_balls.dart.js
-rw-r--r-- 1 shailentuli 5000 1.1M Mar 31 09:55 bouncing_balls.dart.precompiled.js
-rw-r--r-- 1 shailentuli 5000 1.9K Mar 31 09:55 bouncing_balls.html
drwxr-xr-x 5 shailentuli 5000 170B Mar 31 09:55 css
-rw-r--r-- 1 shailentuli 5000 20B Mar 31 09:55 hello_world.dart.html_reference
// The Polymer element.
<link rel="import" href="../components/polymer/polymer.html">
<polymer-element name="my-element">
<template>
<template if="{{!showAnswer}}">
<div id="question">What is the answer to "The Ultimate Question of Life, the Universe, and Everything"?
</div>
<div id="show" on-click="{{enableShowAnswer}}">Show</div>
</template>
<polymer-element name="my-element">
<template>
<div on-change="{{updateSelectedColor}}">
<template repeat="{{color in colors}}">
<label>{{color}}
<input type="radio" name="colors" value="{{color}}">
</label>
</template>
</div>
<div>{{selectedColor}}</div>
my_element.html
---------------
<link rel="import" href="packages/polymer/polymer.html">
<link rel="import" href="packages/core_elements/core_selector.html">
<polymer-element name="my-element">
<template>
<style>
.core-selected {