As you learn about the Dart language, keep these facts and concepts in mind:
Everything you can place in a variable is an object, and every object is an instance of a class. Even numbers, functions, and
nullare objects. All objects inherit from the
Although Dart is strongly typed, type annotations are optional because Dart can infer types. In the code above,
numberis inferred to be of type
int. When you want to explicitly say that no type is expected, use the special type
Dart supports generic types, like
List<int>(a list of integers) or
List<dynamic>(a list of objects of any type).
Dart supports top-level functions (such as
main()), as well as functions tied to a class or object (static and instance methods, respectively). You can also create functions within functions (nested or local functions).
- Similarly, Dart supports top-level variables, as well as variables tied to a class or object (static and instance variables). Instance variables are sometimes known as fields or properties.
Unlike Java, Dart doesn’t have the keywords
private. If an identifier starts with an underscore (
_), it’s private to its library. For details, see Libraries and visibility.
Identifiers can start with a letter or underscore (
_), followed by any combination of those characters plus digits.
Dart has both expressions (which have runtime values) and statements (which don’t). For example, the conditional expression
condition ? expr1 : expr2has a value of
expr2. Compare that to an if-else statement, which has no value. A statement often contains one or more expressions, but an expression can’t directly contain a statement.
- Dart tools can report two kinds of problems: warnings and errors. Warnings are just indications that your code might not work, but they don’t prevent your program from executing. Errors can be either compile-time or run-time. A compile-time error prevents the code from executing at all; a run-time error results in an exception being raised while the code executes.
Is a client-optimized programming language for apps on multiple platforms. It is developed by Google and is used to build mobile, desktop, server, and web applications
Integer values no larger than 64 bits, depending on the platform. Integers are numbers without a decimal point.
Store references. Everything you can place in a variable is an object, and every object is an instance of a class. Even numbers, functions, and null are objects. All objects inherit from the Object class.
The Dart language has special support for the following types: numbers; strings; booleans; lists (also known as arrays); sets; maps; runes (for expressing Unicode characters in a string); symbols.
Dart numbers come in two flavors: int and double. Both int and double are subtypes of num. The num type includes basic operators such as +, -, /, and *, and is also where you’ll find abs(), ceil() and floor(), among other methods.
Every app must have a top-level main() function, which serves as the entrypoint to the app. The main() function returns void and has an optional List<String> parameter for arguments. main() function for a command-line app that takes arguments.
You can use generics to reduce code duplication. Properly specifying generic types results in better generated code. The <…> notation marks List as a generic (or parameterized) type — a type that has formal type parameters. By convention, most type variables have single-letter names, such as E, T, S, K, and V.