I'm doing the Udacity flutter course. There's this constructor call.
child: Category(
name: _categoryName,
color: _categoryColor,
iconLocation: _categoryIcon,
),
When I did this on my own, I naturally wrote the constructor as follows:
const Category({
@required this.name,
@required this.icon,
@required this.color
}) : assert(name != null),
assert(icon != null),
assert(color != null);
Disregard the asserts and @requireds. You call using three parameters, so the constructor must have three parameters.
However, in the solution file of this exercise, the instructors did it like this.
const Category({
Key key,
@required this.name,
@required this.color,
@required this.iconLocation,
}) : assert(name != null),
assert(color != null),
assert(iconLocation != null),
super(key: key);
What is this key parameter and why is the parent of the category widget class (StatelessWidget I presume) is being passed it?
I have looked at Key class, but I did not understand anything. There's no context in this page or an example I can use.