Book Image

Learning Dart, Second Edition - Second Edition

By : Ivo Balbaert
Book Image

Learning Dart, Second Edition - Second Edition

By: Ivo Balbaert

Overview of this book

Table of Contents (18 chapters)
Learning Dart Second Edition
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Using functions in Dart


Functions are another tool to change the program flow; a certain task is delegated to a function by calling it and providing some arguments. A function does the requested task and returns a value; the control flow returns where the function was called. In Java and C#, classes are indispensable and they are the most important structuring concept.

However, Dart is both functional and object-oriented. Functions are first-class objects themselves (they are of the function type) and can exist outside of a class as top-level functions (inside a class, they are called methods). In prorabbits_v2.dart of Chapter 1, Dart – A Modern Web Programming Language, calculateRabbits is an example of a top-level function; and deposit, withdraw, and toString, from banking_v2.dart of this chapter, are methods to be called on as an object of the class. Don't create a static class only as a container for helper functions!

Return types

A function can do either of the following:

  • Do something ...