dart:core library

Built-in types, collections, and other core functionality for every Dart program.

This library is automatically imported.

Some classes in this library, such as String and num, support Dart's built-in data types. Other classes, such as List and Map, provide data structures for managing collections of objects. And still other classes represent commonly used types of data such as URIs, dates and times, and errors.

Numbers and booleans

int and double provide support for Dart's built-in numerical data types: integers and double-precision floating point numbers, respectively. An object of type bool is either true or false. Variables of these types can be constructed from literals:

int meaningOfLife = 42;
double valueOfPi  = 3.141592;
bool visible      = true;

Strings and regular expressions

A String is immutable and represents a sequence of characters.

String shakespeareQuote = "All the world's a stage, ...";

StringBuffer provides a way to construct strings efficiently.

var moreShakespeare = StringBuffer();
moreShakespeare.write('And all the men and women ');
moreShakespeare.write('merely players; ...');

The String and StringBuffer classes implement string splitting, concatenation, and other string manipulation features.

bool isPalindrome(String text) => text == text.split('').reversed.join();

RegExp implements Dart regular expressions, which provide a grammar for matching patterns within text. For example, here's a regular expression that matches a substring containing one or more digits:

var numbers = RegExp(r'\d+');

Dart regular expressions have the same syntax and semantics as JavaScript regular expressions. See ecma-international.org/ecma-262/5.1/#sec-15.10 for the specification of JavaScript regular expressions.


The dart:core library provides basic collections, such as List, Map, and Set.

A List is an ordered collection of objects, with a length. Lists are sometimes called arrays. Use a List when you need to access objects by index.

var superheroes = ['Batman', 'Superman', 'Harry Potter'];

A Set is an unordered collection of unique objects. You cannot get an item efficiently by index (position). Adding an element which is already in the set, has no effect.

var villains = {'Joker'};
print(villains.length); // 1
villains.addAll(['Joker', 'Lex Luthor', 'Voldemort']);
print(villains.length); // 3

A Map is an unordered collection of key-value pairs, where each key can only occur once. Maps are sometimes called associative arrays because maps associate a key to some value for easy retrieval. Use a Map when you need to access objects by a unique identifier.

var sidekicks = {'Batman': 'Robin',
                 'Superman': 'Lois Lane',
                 'Harry Potter': 'Ron and Hermione'};

In addition to these classes, dart:core contains Iterable, an interface that defines functionality common in collections of objects. Examples include the ability to run a function on each element in the collection, to apply a test to each element, to retrieve an object, and to determine the number of elements.

Iterable is implemented by List and Set, and used by Map for its keys and values.

For other kinds of collections, check out the dart:collection library.

Date and time

Use DateTime to represent a point in time and Duration to represent a span of time.

You can create DateTime objects with constructors or by parsing a correctly formatted string.

var now = DateTime.now();
var berlinWallFell = DateTime(1989, 11, 9);
var moonLanding = DateTime.parse("1969-07-20");

Create a Duration object by specifying the individual time units.

var timeRemaining = const Duration(hours: 56, minutes: 14);

In addition to DateTime and Duration, dart:core contains the Stopwatch class for measuring elapsed time.


A Uri object represents a uniform resource identifier, which identifies a resource, for example on the web.

var dartlang = Uri.parse('http://dartlang.org/');


The Error class represents the occurrence of an error during runtime. Subclasses of this class represent specific kinds of errors.

Other documentation

For more information about how to use the built-in types, refer to Built-in Types in A tour of the Dart language.

Also, see dart:core - numbers, collections, strings, and more for more coverage of types in this library.

The Dart Language Specification provides technical details.


An arbitrarily large integer value.
The reserved words true and false denote objects that are the only two instances of this class.
Interface used by types that have an intrinsic ordering.
An instant in time, such as July 20, 1969, 8:18pm GMT.
The annotation @Deprecated('migration') marks a feature as deprecated.
A double-precision floating point number.
A span of time, such as 27 days, 4 hours, 12 minutes, and 3 seconds.
An enumerated value.
Expando<T extends Object>
An Expando allows adding new properties to objects.
A finalizer which can be attached to Dart objects.
A function value.
The result of an asynchronous computation.
An integer number.
Representation of the invocation of a member on an object.
A collection of values, or "elements", that can be accessed sequentially.
An interface for getting items, one at a time, from an object.
An indexable collection of objects with a length.
Map<K, V>
A collection of key/value pairs, from which you retrieve a value using its associated key.
MapEntry<K, V>
A key/value pair representing an entry in a Map.
A result from searching within a string.
The reserved word null denotes an object that is the sole instance of this class.
An integer or floating-point number.
The base class for all Dart objects except null.
An interface for basic searches within strings.
A hint to tools.
A record value.
A regular expression pattern.
A regular expression match.
Iterator for reading runes (integer Unicode code points) of a Dart string.
The runes (integer Unicode code points) of a String.
A collection of objects in which each object can occur only once.
A generic destination for data.
An interface implemented by all stack trace objects.
A stopwatch which measures time while it's running.
A source of asynchronous data events.
A sequence of UTF-16 code units.
A class for concatenating strings efficiently.
Opaque name used by mirrors, invocations and Function.apply.
Runtime representation of a type.
A parsed URI, such as a URL.
A way to access the structure of a data: URI.
WeakReference<T extends Object>
A weak reference to a Dart object.


DateTimeCopyWith on DateTime
Adds copyWith method to DateTime objects.
EnumByName on Iterable<T>
Access enum values by name.
EnumName on Enum
Access to the name of an enum value.
FutureExtensions on Future<T>
Convenience methods on futures.
FutureIterable on Iterable<Future<T>>
FutureRecord2 on (Future<T1>, Future<T2>)
Parallel operations on a record of futures.
FutureRecord3 on (Future<T1>, Future<T2>, Future<T3>)
Parallel operations on a record of futures.
FutureRecord4 on (Future<T1>, Future<T2>, Future<T3>, Future<T4>)
Parallel operations on a record of futures.
FutureRecord5 on (Future<T1>, Future<T2>, Future<T3>, Future<T4>, Future<T5>)
Parallel operations on a record of futures.
FutureRecord6 on (Future<T1>, Future<T2>, Future<T3>, Future<T4>, Future<T5>, Future<T6>)
Parallel operations on a record of futures.
FutureRecord7 on (Future<T1>, Future<T2>, Future<T3>, Future<T4>, Future<T5>, Future<T6>, Future<T7>)
Parallel operations on a record of futures.
FutureRecord8 on (Future<T1>, Future<T2>, Future<T3>, Future<T4>, Future<T5>, Future<T6>, Future<T7>, Future<T8>)
Parallel operations on a record of futures.
FutureRecord9 on (Future<T1>, Future<T2>, Future<T3>, Future<T4>, Future<T5>, Future<T6>, Future<T7>, Future<T8>, Future<T9>)
Parallel operations on a record of futures.
IterableExtensions on Iterable<T>
Operations on iterables.
NullableIterableExtensions on Iterable<T?>
Operations on iterables with nullable elements.


deprecated → const Deprecated
Marks a feature as Deprecated until the next release.
override → const Object
Annotation on instance members which override an interface member.


identical(Object? a, Object? b) bool
Check whether two object references are to the same object.
identityHashCode(Object? object) int
The identity hash code of object.
print(Object? object) → void
Prints an object to the console.


Comparator<T> = int Function(T a, T b)
The signature of a generic comparison function.

Exceptions / Errors

Error thrown when a function is passed an unacceptable argument.
Error thrown by the runtime system when an assert statement fails.
Error occurring when a collection is modified during iteration.
Error objects thrown in the case of a program failure.
A marker interface implemented by all core library exceptions.
Exception thrown when a string or some other data does not have an expected format and cannot be parsed or processed.
A specialized RangeError used when an index is not in the range 0..indexable.length-1.
Error thrown on an invalid function or method invocation.
Error that the platform can use in case of memory shortage.
ParallelWaitError<V, E>
Error thrown when waiting for multiple futures, when some have errors.
Error thrown due to an argument value being outside an accepted range.
Error that the platform can use in case of stack overflow.
The operation was not allowed by the current state of the object.
Error thrown by the runtime system when a dynamic type error happens.
Thrown by operations that have not been implemented yet.
The operation was not allowed by the object.