Dart tutorial
Learn Dart, the language behind Flutter, from your first program to async code.
Course contents
Dart Foundations
- Introduction to Dart — What Dart is, why Google made it, how it works with Flutter, where it is used, how to set it up, and how to write your first program with comments.
- Variables and Constants — How to store values in variables, the rules for naming them, and when to use var, final and const.
- Data Types — The basic Dart types (int, double, num, String, bool, dynamic, Object, Null, Never), how Dart infers types, and how to check, convert, parse and cast values.
Operators
- Operators — Arithmetic, increment, comparison, logical, assignment, type and bitwise operators, the ternary operator, and the order Dart works them out.
- Null Safety — What null is, how Dart stops null crashes, nullable types, the operators ?. ?? ??= and !, and late variables.
Control Flow
- Conditional Statements — How a program makes decisions with if, else, else if, nested conditions, switch statements and switch expressions.
- Loops — How to repeat work with for, while and do-while loops, how to stop or skip rounds, nested loops, and looping over a list.
- Functions — How to write and call functions, return values, positional, optional and named parameters, arrow and anonymous functions, closures, recursion and scope.
Collections
- Lists — How to create lists, read and change items by index, add, remove, search and sort items, and use spread, collection if and collection for.
- Working with Iterables — How to transform and question a list with map, where, fold, reduce, any, every, firstWhere, take and skip, and how to chain them.
- Sets — How to keep unique values with sets and set operations, and how to add and remove at both ends with queues from dart:collection.
- Maps — How to store key-value pairs, read and change values by key, handle missing keys, and add, remove, search, loop over and transform maps.
Strings
- Strings — How to create strings, put values inside them, compare, search, cut, change, split and join them, build long text with StringBuffer, and handle Unicode and emoji.
- Date and Time — How to create DateTime values, read their parts, compare and subtract dates, add time with Duration, and convert dates to text and timestamps.
Libraries
- Libraries — How to import Dart's own libraries with prefixes, show and hide, split your code into your own libraries with private names, and add packages from pub.dev with pubspec.yaml and dart pub.
Object-Oriented Programming
- Classes — How to design classes with fields and methods, make objects, use this, static members and cascades, and build objects with default, named, redirecting, const and factory constructors.
- Enums — How to make a fixed set of choices with enums, read their name and index, add fields and methods with enhanced enums, and use enums in switch.
- Encapsulation — How to hide an object's data with private names, and control how it is read and changed with getters, setters and computed properties.
- Inheritance — How to build a child class on a parent with extends, override and use super, and when to build objects from parts instead, with aggregation and composition.
- Polymorphism — How abstract classes and interfaces set out what a class must do, and how polymorphism lets one call run a different method for each kind of object.
- Mixins — How to add ready-made abilities to classes with mixins, make callable classes, and add methods to existing types like String and List with extensions and extension types.
- Class Modifiers — How abstract, base, interface, final, sealed and mixin class control who can make, extend or implement a class, and how sealed classes make switch check every case.
- Generics — How to write classes and functions with type parameters like T, so one piece of code works safely with many types.
Pattern Matching
- Pattern Matching — How to bundle values with records, and how patterns check the shape of a value and take it apart: in declarations, switch, when guards and if-case.
Exception Handling
- Exception Handling — How to catch errors with try, on, catch and finally, throw and rethrow them, write your own exceptions, and read Dart's built-in errors.
Asynchronous Programming
- Async Basics and Futures — How Dart runs slow work without freezing: the event loop, Futures and their states, then and catchError, async and await, and waiting for several Futures with wait, any and timeout.
- Streams — How Streams deliver many values over time: creating them, listening with listen and await for, making your own with StreamController and async*, and changing them with map, where and friends.
- Isolates — How isolates run heavy work in the background with their own memory: Isolate.run for one job, Isolate.spawn with ReceivePort and SendPort for messages, and closing, killing and error listeners.
File Handling
- File Handling — How to read and write files and folders with dart:io, and how to save and load data as JSON with dart:convert, model classes and safe parsing.
Reference
- Dart Cheat Sheet — A lookup page for the whole course: one table per topic, from data types and null safety to classes, patterns, async code, files and JSON.