Dart's Core Data Types: Everything is an Object
In Dart, everything is an object, from numbers to functions. This means even a simple `int` or `String` has methods and properties, unlike primitive types in other languages. The main footgun is forgetting that `null` itself is a type, `Null`.
WHY IT EXISTS Dart was designed to provide a consistent, object-oriented foundation for all data. By making every value an instance of a class (an object), Dart avoids the confusing distinction between primitive types and object wrappers common in languages like Java, simplifying the mental model for developers.
THE MENTAL MODEL Think of Dart's types not as raw data but as smart containers. An int isn't just a number; it's an object with methods like isEven or toRadixString(). A String isn't just text; it's an object with methods like toUpperCase() and split(). Every variable you declare is simply a reference to one of these objects.
HOW IT WORKS Dart has special support for a core set of types, allowing you to create them with simple literals. The most common are Numbers (int for integers, double for floating-point), String for text, and bool for true/false values. For collections, you have List (ordered, like arrays), Set (unordered, unique items), and Map (key-value pairs). Other important types include Records for anonymous composite values, Future and Stream for asynchronous programming, and Function. Every type, except Null, is a subclass of the top-level Object class.
WHEN TO USE IT You use these types in every line of Dart code. Use int for counts and IDs, double for prices or measurements, String for names and messages, bool for flags and states, List for sequences of items, and Map for structured data lookups. These are the fundamental building blocks for representing any information in your application.
WHEN NOT TO USE IT The question is less about when not to use them and more about choosing the correct one. Don't use a String to store a number you need to perform math on. Don't use a List if you need to guarantee that every item is unique; use a Set instead. Don't use a double for financial calculations where precision is critical without careful handling; consider specialized packages or integer-based representations of the smallest currency unit.
ONE CANONICAL EXAMPLE Declaring variables with built-in types is straightforward using literals:
int score = 10; String playerName = 'Alice'; bool isReady = true; List<int> highScores = [10, 9, 8]; Map<String, String> config = { 'theme': 'dark', 'language': 'en' };
Read the original → dart.dev
Get five bites like this every day.
Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.