Complete the code to define a constructor with a named parameter called 'name'.
class Person { String name; Person([1]); }
The constructor uses a named parameter with required this.name to ensure the 'name' is passed when creating an object.
Complete the constructor to accept an optional named parameter 'age' with a default value of 18.
class Person { int age; Person([1]); }
Using this.age = 18 in the named parameter sets a default value of 18 if no value is provided.
Fix the error in the constructor to correctly assign the named parameter 'title' to the field.
class Book { String title; Book([1]) { this.title = title; } }
Using required this.title in the constructor parameters automatically assigns the value to the field.
Fill both blanks to create a constructor with a named parameter 'color' that is optional and has a default value 'blue'.
class Car { String color; Car([1] [2]); }
The constructor uses this.color = 'blue' as an optional named parameter with a default value, and this.color to assign it.
Fill all three blanks to define a constructor with named parameters 'width' and 'height' both required, and an optional 'color' with default 'red'.
class Rectangle { int width; int height; String color; Rectangle([1] [2] [3]); }
The constructor requires width and height using required this.field, and sets an optional color with a default value.