Random; // Import a class from a library. void main() { // The app starts executing here. print(new Dice(n: 12).roll()); // Print a new object's value. } class Dice { // Define a class. static Random shaker = new Random(); // Define a class variable. int sides, value; // Define instance variables. String toString() => '$value'; // Define a method using shorthand syntax. Dice({int n: 6}) { // Define a constructor. if (4 <= n && n <= 20) { sides = n; } else { throw new ArgumentError(/* */); // Support for errors and exceptions. } } int roll() { // Define an instance method. return value = shaker.nextInt(sides) + 1; // Get a random number. } }
num _strength; num get strength { // some code return this._strength; } set strength(num value) { // do something with value; this._strength = value; } }
A application using google play game services version: 0.1.0 author: Giovanni Laquidara dependencies: googleapis: any googleapis_auth: any browser: any core_elements: ">=0.2.0 <0.3.0" polymer: ">=0.12.0 <0.13.0" paper_elements: ">=0.1.0 <0.2.0" pubspec.yaml
'package:polymer/polymer.dart'; import 'dart:html'; @CustomTag('volume-nob') class VolumeNobElement extends PolymerElement { // @published means 'this is an attribute', and it is observable. @published int volume = 0; VolumeNobElement.created() : super.created(); }
'images/flowers.json', TextureAtlasFormat.JSONARRAY); resourceManager.load().then((result) { var dog = resourceManager.getBitmapData('dog'); var plop = resourceManager.getSound('plop'); var flowers = resourceManager.getTextureAtlas('fl'); var daisy = flowers.getBitmapData('daisy'); });
substitutes embedded resources of Flash. var resourceManager = new ResourceManager(); resourceManager.addSound("plop", "sounds/plop.mp3"); // loads ogg-file in Firefox! ... var sound = resourceManager.getSound("plop"); var soundTransform = new SoundTransform(0.5); var soundChannel = sound.play(false, soundTransform);