Consider the following class. It is what we may call a "two-dimensional enum". We could have used
an enum
with four states, but since the four states have a clear meaning, we choose the more
direct approach of storing two Boolean flags.
class FlowerType {
bool has_scent = false;
bool has_thorns = false;
FlowerType({this.has_scent = false, this.has_thorns = false});
}
The class has one constructor with two named optional parameters.
This constructor also acts as a default constructor, and since the two bool
s are non-nullable, they need to be specified (again) in the constructor.
Can default values be specified once?
Declaring two final static variables for this purpose is one option (though a pretty lousy one). Here I'm wondering whether I'm missing some basic fact about constructors.