Sitemap

Member-only story

Enums on Steroids with Dart. Best Enum features ever!

5 min readJul 18, 2024
Little girl learning to count

Introduction

Also known as enums or enumerations, enumerated types are a special kind of class used to represent a fixed set of constant values. These values are used to define a collection of related constants that can be referred to by name. Dart has a well-designed enum feature that stands out compared to many programming languages. This is a strong statement, but I’ll soon explain the rationale in this article.

In Dart, all enums extend the Enum class and are treated as such. They inherit methods and properties from the Enum class, making them powerful and versatile. The Dart documentation specifies that they cannot be subclassed, implemented, mixed in, or explicitly instantiated. This ensures the integrity and immutability of the enumerated types, providing a robust framework for developers.

Note: This article assumes you have basic knowledge of Dart or at least basic programming knowledge. If you’re new to Dart, I recommend familiarizing yourself with the basics of the language, such as its syntax and core principles, to fully grasp the concepts discussed here.

Let’s take a deep dive

Dart provides two types of enums, simple and enhanced enums. Simple enums are basically available in every or almost Object Oriented…

Ethiel ADIASSA
Ethiel ADIASSA

Written by Ethiel ADIASSA

Software Engineer - Google Developer Expert for Flutter and Dart

Responses (5)