Dart from the ground up
The language behind Flutter, from the first line to a report
- Beginner
- 12 chapters
- 213 min read
Learn Dart by running it: main and print, values in var and final, the built-in types, string interpolation and fixed decimals, if and switch over an enum, four kinds of loop, functions with optional and named parameters, lists and maps, the calls that replace whole loops, classes with getters and their own text form, inheritance and interfaces, null safety with fallbacks and the one bang to avoid, errors caught rather than crashed, and a sales report that uses the whole course at once.
What You'll Learn
- Write and run a Dart program, and know what the compiler expects of it
- Hold values in var and final, and tell whole numbers from decimals
- Build text with interpolation, and round a price to the decimals you want
- Choose a path with if and a case with switch, over numbers and over an enum
- Repeat work with a counted for loop, for in, while and do while
- Write functions with defaults, named arguments and one-line arrow bodies
- Keep values in a list and lookups in a map, and add, remove, find and sort
- Replace loops with map, where, fold and reduce, one question at a time
- Model a record as a class, with fields, getters and a readable text form
- Share behaviour with extends, and promise a shape with implements
- Handle a missing value with the safe call and a fallback, and catch a failure
- Assemble a sales report from a record class, a filter, an order and a total
Prerequisites
- No programming experience needed — this course starts at the first line
- Any other language you know will make the early chapters quick
Course Content
- 01Your first Dart programNot started
What Dart runs on, the main function every program begins at, print and the line breaks it adds, and the comments that are for the reader rather than for the compiler.
- 02Values, names and typesNot started
Holding a value under a name with var and final, the built-in types for whole numbers, decimals, text and truth, and the two kinds of division that catch people out.
- 03Text, interpolation and formattingNot started
Joining text with the plus sign, dropping values into a string with a dollar sign, and turning a number into the wording you want with toStringAsFixed.
- 04Decisions: if, else and switchNot started
Choosing a path with if and else, picking one of two values with a short expression, and naming the cases of a choice with switch and an enum.
- 05Loops: for, for in, while and doNot started
Repeating work a counted number of times, walking through a list one value at a time, and repeating while a condition holds or until it has held once.
- 06Functions and their parametersNot started
Naming a piece of work, giving it inputs and an answer, letting a caller leave an argument out, and passing arguments by name so the call reads like a sentence.
- 07Lists and mapsNot started
Keeping many values in a list and many lookups in a map, reading them by position or by key, and the handful of calls that add, remove, find and order what is inside.
- 08Doing work on a whole list at onceNot started
Replacing loops with calls that each answer one question: map to change every value, where to keep the ones that pass a test, and fold and reduce to boil a list down to one value.
- 09Classes: values with behaviourNot started
Grouping values with the work that belongs to them, writing a constructor that fills the fields, adding getters that look like values, and overriding toString so printing an object says something useful.
- 10Sharing behaviour: extends, implements and abstractNot started
One class taking the fields and methods of another with extends, an abstract class saying what every kind must be able to do, and implements for a class that promises a shape without borrowing any code.
- 11Missing values and calls that failNot started
Types that say a value may be absent, the safe call and the fallback that handle one, why the bang is the last resort, and how throw with try and catch keeps a failure from ending the program.
- 12Putting it together: a sales reportNot started
A capstone that uses the whole course once: a class holding a record, a getter for the line total, a filter and an ordering built from the calls in chapter eight, and a report printed one line at a time.
