September 2019
Beginner
512 pages
12h 52m
English
In this chapter, we have seen that functions and variables in Dart can be tied to classes as members—class fields and methods.
The top-level way of writing functions is also already known from Chapter 1, An Introduction to Dart, where we wrote the most famous Dart function: the entry point of every application, main(). For variables, the way of declaring is the same. We just leave it out of any function scope, so that it's accessible globally on the application/package:
var globalNumber = 100;final globalFinalNumber = 1000;void printHello() { print("""Dart from global scope. This is a top-level number: $globalNumber This is a top-level final number: $globalFinalNumber """);}main() { // the most famous Dart ...Read now
Unlock full access