Dart Tutorial
The language of Flutter for apps on every screen.
Getting started3 lessons
Basics22 lessons
- 4Dart VariablesDeclare with var (type inferred) or a type such as int and String.
- 5Dart Data TypesTypes: int, double, String, bool, List, Set, Map and null.
- 6Dart StringsStrings use single or double quotes.
- 7Dart Null SafetyTypes are non nullable by default.
- 8Dart Type ConversionConvert with int.parse, double.parse, toString, toInt and toDouble.
- 9Dart Input and Outputprint writes a line.
- 10Dart CommentsUse // for one line, /* */ for several lines and /// for documentation comments that tools.
- 11Dart Booleansbool has two values, true and false.
- 12Dart Mathdart:math has sqrt, pow, min, max, Random and pi.
- 13More String Methodssplit, join, padLeft, startsWith, endsWith, indexOf, trim and a StringBuffer handle most t.
- 14Dart Date and TimeDateTime.now gives the current moment.
- 15The main FunctionEvery Dart program starts in main().
- 16var, final and constvar infers a type and can change.
- 17Built in Typesint, double, num, String, bool, List, Set, Map and dynamic.
- 18Null SafetyTypes are non-nullable by default.
- 19String Interpolation$name inserts a variable and ${expression} inserts any expression.
- 20Type Conversionint.parse, double.parse, tryParse, toString, toInt and toDouble convert values.
- 21dart:mathImport dart:math for sqrt, pow, min, max, pi and Random.
- 22OperatorsArithmetic includes ~/ for integer division.
- 23Cascade Notation.
- 24Conditional Expressionscond ? a : b and a ?? b choose between values.
- 25Comments and Documentation// starts a line comment and /// a documentation comment that tools show.
Operators2 lessons
Control flow10 lessons
- 28Dart If and Elseif runs code when a condition is true.
- 29Dart Switchswitch compares a value to cases.
- 30Dart Loopsfor repeats with a counter, for in visits collections, while and do while use conditions.
- 31if and elseConditions must be bool.
- 32switch Statements and ExpressionsDart 3 switch expressions return values.
- 33for and for-in Loopsfor counts, for in walks collections and forEach runs a function.
- 34while and do whilewhile checks first and do while runs at least once.
- 35break, continue and Labelsbreak leaves a loop and continue skips.
- 36Collection if and forBuild lists with if and for inside the literal.
- 37Pattern Matching and RecordsRecords group values and patterns destructure them.
Collections14 lessons
- 38Dart ListsA List is an ordered, growable collection.
- 39Dart Sets and MapsA Set keeps unique values.
- 40Collection Methodsmap, where, reduce, fold, any, every and sort transform collections.
- 41Sorting and Iterablessort changes a list in place with an optional comparison function.
- 42ListsLists are ordered and growable.
- 43List Methodssublist, indexOf, contains, join, reversed, take and skip are everyday tools.
- 44SetsSets hold unique values.
- 45MapsMaps hold key value pairs.
- 46Spread Operators.
- 47Sorting and Comparingsort takes a compare function.
- 48toList, toSet and expandConvert between collections and flatten nested ones.
- 49Queue and IterableQueue from dart:collection works at both ends.
- 50String Methodslength, substring, split, replaceAll, trim, toUpperCase, contains and padLeft.
- 51Regular ExpressionsRegExp tests patterns and finds matches.
Functions10 lessons
- 52Dart FunctionsA function has a return type, a name and parameters.
- 53Optional and Named ParametersPositional parameters can be optional in square brackets, and named parameters go in curly.
- 54Closures and Function ValuesFunctions are objects.
- 55FunctionsDeclare a return type, name and parameters.
- 56Named and Optional ParametersCurly braces make named parameters, square brackets positional optionals.
- 57Closures and Function TypesFunctions are objects.
- 58Higher Order Functionsmap, where, reduce, fold and any take functions.
- 59RecursionA function may call itself with a base case.
- 60typedef and Callbackstypedef names a function type so callbacks read clearly.
- 61Generators: sync* and async*sync* returns an Iterable and yield produces values lazily.
Object oriented Dart19 lessons
- 62Dart Classes and ObjectsA class has fields and methods.
- 63Dart ConstructorsNamed constructors give extra ways to create objects, and factory constructors can return .
- 64Getters, Setters and Privacyget and set define computed properties.
- 65Dart InheritanceUse extends to inherit from one class, @override to replace a method and super to reach th.
- 66Abstract Classes and InterfacesAn abstract class cannot be instantiated.
- 67MixinsA mixin shares behaviour across classes without inheritance.
- 68Enums and RecordsEnhanced enums have fields and methods.
- 69ClassesA class has fields, a constructor and methods.
- 70ConstructorsNamed constructors, factory constructors and initialiser lists give flexibility.
- 71Getters and Settersget and set make computed properties.
- 72Inheritanceextends creates a subclass.
- 73abstract Classes and Interfacesabstract classes cannot be created.
- 74MixinsA mixin reuses code across classes with with.
- 75EnumsEnhanced enums have fields and methods.
- 76Static Membersstatic members belong to the class.
- 77GenericsType parameters with bounds make reusable classes and functions.
- 78Extension Methodsextension adds methods to existing types.
- 79toString, == and hashCodeOverride toString for readable output and == with hashCode for value equality.
- 80Operator Overloading and Callable Classesoperator + and call() make types behave like numbers or functions.
Errors and files13 lessons
- 81Dart Exceptionstry, catch and finally handle errors.
- 82Dart Filesdart:io offers File with readAsString, writeAsString and exists.
- 83try, catch and finallyHandle exceptions with on and catch.
- 84throw and Custom Exceptionsthrow raises any object.
- 85Futures and async/awaitA Future is a value available later.
- 86StreamsA Stream delivers many values over time.
- 87Files with dart:ioFile reads and writes files.
- 88JSON with dart:convertjsonEncode and jsonDecode convert between objects and text.
- 89Dates and DurationsDateTime and Duration handle time.
- 90Null Aware Operators?., ??, ??= and ! handle nullable values.
- 91Practice: Word FrequencySplit, count in a map and sort.
- 92Practice: FizzBuzzCombine a loop and a switch expression.
- 93Practice: Bank AccountCombine a class, getter and exception.
Advanced DartPremium6 lessons
- 94Dart GenericsGenerics make classes and functions work with many types safely.
- 95Futures, async and awaitA Future is a value that arrives later.
- 96StreamsA Stream delivers a sequence of values over time.
- 97IsolatesDart code runs in an isolate with its own memory.
- 98Extension MethodsExtensions add methods to existing types without changing them.
- 99Patterns and Sealed ClassesDart 3 patterns destructure values in switch, if and variable declarations.
Dart in practicePremium8 lessons
- 100Flutter BasicsFlutter builds UIs from widgets.
- 101Flutter StateA StatelessWidget never changes.
- 102Flutter LayoutRow and Column arrange children, Expanded shares space, Padding and SizedBox add spacing, .
- 103HTTP and JSONThe http package makes requests and dart:convert decodes JSON with jsonDecode and encodes .
- 104Packages and pubspecpub.dev hosts packages.
- 105Testing DartThe test package runs unit tests, and flutter_test adds widget tests.
- 106Dart Best PracticesPrefer final and const, use null safety instead of checks, keep widgets small, run dart fo.
- 107Building and Publishingflutter build apk or appbundle makes an Android release, flutter build ios prepares iOS an.
More Dart basics8 lessons
- 108assertassert checks a condition while developing and does nothing in release builds.
- 109late Variableslate delays initialisation until first use and can make expensive values lazy.
- 110Characters and RunesStrings are UTF-16.
- 111Type Tests and Castsis checks a type and as casts.
- 112Iterable Helpersfirst, last, isEmpty, single, takeWhile and skipWhile read collections.
- 113const and Unmodifiable Collectionsconst lists cannot change.
- 114Command Line ArgumentsArguments arrive as a list of strings in main.
- 115Libraries and Importsimport brings in libraries.