- 01Setting up (what you'll need)
- 02Your first output (print)
- 03Variables and types (var and annotations)
- 04Null safety (? and !)
- 05Branching (the if statement)
- 06Repeating (the for loop)
- 07Writing your own function
- 08Repeating (the while loop)
- 09Working with lists (List)
- 10Working with maps (Map)
- 11Classes (object orientation)
- 12Constructors
- 13Inheritance
- 14Named arguments
- 15Asynchronous work (Future, async, await)
- 16Working with strings
- 17The switch statement
- 18The ternary operator
- 19Extension methods
- 20[Project] Build a small inventory system
Classes (object orientation)
This lesson covers the basics of writing a class in Dart.
A class bundles data (fields) together with behaviour (methods). Dart is designed around the idea that everything is an object.
The sample code defines class Animal with a name field and a speak() method that returns the sound it makes.
A common early stumble is when fields get initialised. In Dart, a field not initialised in the constructor must either be marked with ? or be given an initial value, under the null-safety rules.
In professional work, almost every screen component (widget) in Flutter is defined as a class, so understanding classes is the foundation of Flutter development.
๐งช This site can't compile or run Dart directly, so it checks on the spot whether what you typed matches the reference code (scoring happens entirely in your browser โ nothing is sent anywhere).
