Reputation: 111
Here is the deal:
I have 4 classes with almost 1200 variables in each of them (they are icons).
static const IconData access_alarm = IconData(0xe805, fontFamily: _kFontFam);
...
Since all those variables have the same name between those classes, I would like to create a "global template" (abstract class
a.k.a. interface
) in order to let the developer change between those "Icon packs" in runtime, and help me be sure all variables have the same name between classes, and all icons have been set.
So I have created the abstract class
like this:
abstract class MaterialIcons {
static IconData access_alarm;
static IconData access_alarms;
static IconData access_time;
...
Is there any way to force the classes to set those variables?
Upvotes: 4
Views: 1269
Reputation: 3768
You cannot use the abstract concept with properties. You need to create abstract methods.
This can be done in multiple ways, but the simplest I can think of is to create getters:
abstract class MaterialIcons {
IconData get access_alarm;
IconData get access_alarms;
IconData get access_time;
}
When creating a sub-class, do it normally, overriding the abstract getters:
class A extends MaterialIcons{
IconData get access_alarm => IconData(0xe805, fontFamily: _kFontFam);
}
If you do not implement one of the abstract getters, the following error occurs:
Error: The non-abstract class 'A' is missing implementations for these members:
Which is the expected behaviour you want.
Upvotes: 4