- 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
Named arguments
This lesson covers named arguments, which let you specify an argument by name.
Wrapping a parameter in {}, as in {type name}, lets the caller pass it as name: value. You can then pass only the arguments you need, in any order.
The sample code defines void greet(String name, {String title = 'Mr./Ms.'}) and calls it both with the title left out and with it supplied.
A common early stumble is the difference in syntax between ordinary (positional) arguments and named ones. A parameter wrapped in {} has to be passed with name: at the call site.
In professional work, almost every Flutter widget constructor is built from named arguments, which makes it obvious at the call site what each value means.
๐งช 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).
