Table Of ContentDart Essentials
Design and build full-featured web and CLI apps using
the powerful Dart language and its libraries and tools
Martin Sikora
BIRMINGHAM - MUMBAI
Dart Essentials
Copyright © 2015 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval
system, or transmitted in any form or by any means, without the prior written
permission of the publisher, except in the case of brief quotations embedded in
critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy
of the information presented. However, the information contained in this book is
sold without warranty, either express or implied. Neither the author, nor Packt
Publishing, and its dealers and distributors will be held liable for any damages
caused or alleged to be caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the
companies and products mentioned in this book by the appropriate use of capitals.
However, Packt Publishing cannot guarantee the accuracy of this information.
First published: May 2015
Production reference: 1190515
Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham B3 2PB, UK.
ISBN 978-1-78398-960-7
www.packtpub.com
Credits
Author Project Coordinator
Martin Sikora Milton Dsouza
Reviewers Proofreaders
Lamoriniere Cedric Stephen Copestake
Rokesh Jankie Safis Editing
Hans Van den Keybus
Frederik Leonhardt Indexer
Hemangini Bari
Marko Vuksanovic
Graphics
Commissioning Editor
Sheetal Aute
Taron Pereira
Production Coordinator
Acquisition Editor
Shantanu N. Zagade
Shaon Basu
Cover Work
Content Development Editor
Shantanu N. Zagade
Akashdeep Kundu
Technical Editor
Mrunal M. Chavan
Copy Editor
Stuti Srivastava
About the Author
Martin Sikora has been programming professionally since 2006 for companies
such as Miton CZ and Symbio Digital in various languages, mostly PHP. Since 2012,
he's been freelancing, working on projects in Python, PHP, Dart, Objective-C, and
AngularJS. He's a Zend Certified Engineer and was a member of the winning team
at Google Dart Hackathon 2012 in Prague.
About the Reviewers
Lamoriniere Cedric is a software engineer and a graduate from a French
engineering school, who mostly uses C++ during his day job.
His taste for innovation has led him to try out a considerable amount of various
web frameworks, technologies, and languages.
Among these languages, he has taken a strong interest in the Dart language for its
ease of use and efficiency. It allows developers to get things done in a timely manner.
Rokesh Jankie graduated in 1998 with a master's degree in computer science
from Leiden University, the Netherlands. He specialized in algorithms and
NP-complete problems. Scheduling problems that can be NP-complete was his area
of focus. He started working for the University of Leiden, ORTEC consultants, and
Ponte Vecchio, and later, worked for Qualogy. At Qualogy, he used what he had
experienced till that point to set up a product. Qualogy works in the field of Oracle
and Java technologies. With the current set of technologies, interesting products can
be delivered, and this is what QAFE is (refer to www.qafe.com for more information).
QAFE Inc. has a very dynamic team, which works in an agile way (going to
production weekly, quickly adjusting to market needs, and so on). In the team,
they don't distinguish between senior developers and junior developers, but they
recruit very good software engineers. This gives a new dynamic to the team and
makes it a great experience on a daily basis.
Books that Rokesh has worked on include Dart in Action, Manning Publications, and
HTML5 and CSS Responsive Web Design Cookbook and HTML5 Canvas Cookbook,
both by Packt Publishing.
I'm very grateful to my parents and my wife for supporting my
enthusiasm for computer science. My 2-year old son inspires me to
be the best dad, and he makes sure that I work hard to create a better
future for him through the application of computer science topics in
daily life and by sharing my knowledge on this subject. Reviewing
this book is part of that journey.
Hans Van den Keybus is a Belgium-based Flash, Flex, and Google Dart
developer, working for his one-man company called dotdotcommadot.
Although he started off creating simple games and animations for some well-known
design companies, he got the most fun out of structuring the code behind it. His
main areas of expertise are OOP, design patterns, and microarchitectures.
Currently, he's working on a major project developed in Google Dart for his
customers MSC and Maersk.
Whenever he's not programming, Hans is probably playing some sketchy basement
with his even sketchier grindcore band.
Frederik Leonhardt is a tech enthusiast and software engineer with more than
5 years of experience in Java, Java EE, and related frameworks. He likes to delve
into new technologies, and he started using Dart with its first beta release in 2012.
He likes to contribute to the open source community and is currently working for
Catalyst IT, a team of open source technologists. In the past, he has worked as a
researcher for the Institute of Information Systems at the German Research Center
for Artificial Intelligence, where he published papers on recommender systems and
their application in the mobile health domain.
He recently moved to New Zealand and enjoys the relaxed Kiwi lifestyle and the
beautiful outdoors, especially for tramping and photography.
Marko Vuksanovic is a consultant who specializes in software development and
delivery. He received his master's degree in electrical engineering and computing from
the University of Zagreb, Croatia, in 2009. He is currently employed by ThoughtWorks
Australia, where he helps deliver outstanding products to clients. He has spent the last
10 years working with web applications, and during this period, he has been involved
in numerous open source, as well as closed source, projects. He is very active within
the Dart community and used to actively contribute to AngularDart projects. His
other interests lie in the information security and machine-learning spaces.
When not providing services to clients, Marko spends time acquiring new skills,
breaking things, reverse engineering, or enjoying some time off at one of Australia's
beaches or a nearby tennis court.
www.PacktPub.com
Support files, eBooks, discount offers, and more
For support files and downloads related to your book, please visit www.PacktPub.com.
Did you know that Packt offers eBook versions of every book published, with PDF
and ePub files available? You can upgrade to the eBook version at www.PacktPub.com
and as a print book customer, you are entitled to a discount on the eBook copy. Get in
touch with us at [email protected] for more details.
At www.PacktPub.com, you can also read a collection of free technical articles, sign
up for a range of free newsletters and receive exclusive discounts and offers on Packt
books and eBooks.
TM
https://www2.packtpub.com/books/subscription/packtlib
Do you need instant solutions to your IT questions? PacktLib is Packt's online digital
book library. Here, you can search, access, and read Packt's entire library of books.
Why subscribe?
• Fully searchable across every book published by Packt
• Copy and paste, print, and bookmark content
• On demand and accessible via a web browser
Free access for Packt account holders
If you have an account with Packt at www.PacktPub.com, you can use this to access
PacktLib today and view 9 entirely free books. Simply use your login credentials for
immediate access.
Table of Contents
Preface vii
Chapter 1: Getting Started with Dart 1
What is Dart? 1
Why choose Dart? 2
Installing the Dart SDK 3
Dart Editor 3
Writing a greeting for all Dartisans 4
pubspec.yaml 5
index.html 6
The main() function 7
Running and debugging code in Dartium 12
Compiling Dart to JavaScript 13
The Dart language tour 15
The static checker 15
Variables 16
Built-in types 16
Functions and parameters 17
Class properties 18
Class inheritance and abstract classes 18
Constructors 19
Exceptions 20
Using static types 20
Summary 21
[ i ]