You have used named optional arguemnts but your constructor accept postional optional parameter.
named optional parameter {}:
- Use to omit/avoid arguments and for readability.
- argument position doesnt matter since refer using name.
- Since you can avoid the argument, to denote that this argument is required use
@required. Most of the time this annotation use to say this is cannot avoid(like a notice).
const Category({
@required this.name,
@required this.icon,
@required this.color
}) : assert(name != null),
assert(icon != null),
assert(color != null);
//Category(name: _categoryName, icon: _categoryIcon, color: _categoryColor),
positional optional parameter []:
- Also use to avoid or omit args.
- Cannot mention name because of that no readability(as a example for boolean params).
- Argument position matters.
- No need of
@required because we must provide args.
const Category(
this.name,
this.icon,
this.color
) : assert(name != null),
assert(icon != null),
assert(color != null);
//Category(_categoryName, _categoryIcon, _categoryColor),
Read more from this SO answer.