Creating an enum
Enum does not exist in Dart as a built-in type. Enums provide additional type checking and thus, help enhance code maintainability. So what alternative do we have? Look at the code in project enum
, where we want to differentiate the degree of an issue reported to us (we distinguish between the following levels: TRIVIAL
, REGU
LAR
, IMPO
RTANT
, and CRITICAL
).
How to do it...
The first way to achieve the creating an enum functionality is shown in enu
m1.dart
:
class IssueDegree { final _value; const IssueDegree(this._value); toString() => 'Enum.$_value'; static const TRIVIAL = const IssueDegree('TRIVIAL'); static const REGULAR = const IssueDegree('REGULAR'); static const IMPORTANT = const IssueDegree('IMPORTANT'); static const CRITICAL ...
Get Dart: Scalable Application Development now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.