CINXE.COM
Built-in types | Dart
<!doctype html><html lang="en"><head><meta charset="utf-8"><meta http-equiv="x-ua-compatible" content="ie=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><script>!function(e,t,a,n){e[n]=e[n]||[],e[n].push({"gtm.start":(new Date).getTime(),event:"gtm.js"});var g=t.getElementsByTagName(a)[0],m=t.createElement(a);m.async=!0,m.src="https://www.googletagmanager.com/gtm.js?id=GTM-5VSZM5J",g.parentNode.insertBefore(m,g)}(window,document,"script","dataLayer")</script><meta name="description" content="Information on the types Dart supports."><title>Built-in types | Dart</title><link rel="icon" sizes="64x64" href="/assets/img/logo/dart-64.png" eleventy:ignore><link href="/assets/img/touch-icon-iphone.png" rel="apple-touch-icon" eleventy:ignore><link href="/assets/img/touch-icon-ipad.png" rel="apple-touch-icon" sizes="152x152" eleventy:ignore><link href="/assets/img/touch-icon-iphone-retina.png" rel="apple-touch-icon" sizes="180x180" eleventy:ignore><link href="/assets/img/touch-icon-ipad-retina.png" rel="apple-touch-icon" sizes="167x167" eleventy:ignore><meta name="twitter:card" content="summary"><meta name="twitter:site" content="@dart_lang"><meta name="twitter:title" content="Built-in types"><meta name="twitter:description" content="Information on the types Dart supports."><meta property="og:title" content="Built-in types"><meta property="og:description" content="Information on the types Dart supports."><meta property="og:url" content="/language/built-in-types/"><meta property="og:image" content="/assets/img/logo/dart-logo-for-shares.png?2" eleventy:ignore><link rel="preconnect" href="https://fonts.googleapis.com"><link rel="preconnect" href="https://fonts.gstatic.com" crossorigin><link href="https://fonts.googleapis.com/css2?family=Google+Sans:wght@400;500;700&display=swap" rel="stylesheet"><link href="https://fonts.googleapis.com/css2?family=Google+Sans+Display:wght@400&display=swap" rel="stylesheet"><link href="https://fonts.googleapis.com/css2?family=Google+Sans+Mono:wght@400;500;700&display=swap" rel="stylesheet"><link href="https://fonts.googleapis.com/css2?family=Google+Sans+Text:wght@400;500;700&display=swap" rel="stylesheet"><link href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,GRAD@24,400,0,0" rel="stylesheet"><link rel="stylesheet" href="/assets/css/main.css"><script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.0/jquery.min.js" integrity="sha512-3gJwYpMe3QewGELv8k/BX9vcqhryRdzRMxVfq6ngyWXwo03GFEzjsUm8Q7RZcHPHksttq7/GFoxjCVUjkjvPdw==" crossorigin="anonymous" referrerpolicy="no-referrer"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap/4.6.2/js/bootstrap.min.js" integrity="sha384-+sLIOodYLS7CIrQpBjl+C7nPvqq+FbNUBDunl/OZv93DB7Ln/533i8e/mZXLi/P+" crossorigin="anonymous" referrerpolicy="no-referrer"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/js-cookie/3.0.5/js.cookie.min.js" integrity="sha512-nlp9/l96/EpjYBx7EP7pGASVXNe80hGhYAUrjeXnu/fyF5Py0/RXav4BBNs7n5Hx1WFhOEOWSAVjGeC3oKxDVQ==" crossorigin="anonymous" referrerpolicy="no-referrer"></script><script src="/assets/js/os-tabs.js"></script><script src="/assets/js/utilities.js"></script><script src="/assets/js/main.js"></script><script>!function(e,a,t,n,c,o,s){e.GoogleAnalyticsObject=c,e[c]=e[c]||function(){(e[c].q=e[c].q||[]).push(arguments)},e[c].l=1*new Date,o=a.createElement(t),s=a.getElementsByTagName(t)[0],o.async=1,o.src="//www.google-analytics.com/analytics.js",s.parentNode.insertBefore(o,s)}(window,document,"script",0,"ga"),ga("create","UA-26406144-4","auto"),ga("send","pageview")</script></head><body class="default.html show_banner"><a id="skip" href="#site-content-title">Skip to main content</a><section id="cookie-notice"><div class="container"><p>dart.dev uses cookies from Google to deliver and enhance the quality of its services and to analyze traffic. <a href="https://policies.google.com/technologies/cookies" target="_blank" rel="noopener">Learn more</a>.</p><button id="cookie-consent" class="btn btn-primary">OK, got it</button></div></section><noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-5VSZM5J" height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript><header id="page-header" class="site-header"><nav id="mainnav" class="site-header"><div id="menu-toggle"><i class="material-symbols">menu</i></div><a href="/" class="brand" title="Dart"><img src="/assets/img/logo/logo-white-text.svg" alt="Dart"></a><ul class="navbar"><li><a href="/overview" class="nav-link">Overview</a></li><li class="mainnav__get-started"><a href="/guides" class="nav-link active"><span>Docs</span></a></li><li><a href="/community" class="nav-link">Community</a></li><li><a href="/#try-dart" class="nav-link">Try Dart</a></li><li><a href="/get-dart" class="nav-link">Get Dart</a></li><li class="searchfield"><form action="/search" class="site-header__search form-inline" id="cse-search-box"><input type="hidden" name="cx" value="011220921317074318178:_yy-tmb5t_i"> <input type="hidden" name="ie" value="UTF-8"> <input type="hidden" name="hl" value="en"> <input class="site-header__searchfield form-control search-field" type="search" name="q" id="search-main" autocomplete="off" placeholder="Search" aria-label="Search"></form></li></ul></nav></header><div class="banner"><p class="banner__text">Announcing Dart 3.5 and an updated Dart roadmap! <a href="https://medium.com/dartlang/dart-3-5-6ca36259fa2f" target="_blank">Learn more</a></p></div><div id="sidenav"><form action="/search/" class="site-header__search form-inline"><input class="site-header__searchfield form-control search-field" type="search" name="q" id="search-side" autocomplete="off" placeholder="Search" aria-label="Search"></form><div class="site-sidebar"><ul class="navbar-nav"><li class="nav-item"><a href="/overview" class="nav-link">Overview</a></li><li class="nav-item"><a href="/community" class="nav-link">Community</a></li><li class="nav-item"><a href="https://dartpad.dev" class="nav-link">Try Dart</a></li><li class="nav-item"><a href="/get-dart" class="nav-link">Get Dart</a></li><li class="nav-item"><a href="/guides" class="nav-link">Docs</a></li><li aria-hidden="true"><div class="sidebar-primary-divider"></div></li></ul><ul class="nav flex-column"><li class="nav-item"><a class="nav-link active collapsible" data-toggle="collapse" href="#sidenav-1" role="button" aria-expanded="true" aria-controls="sidenav-1">Language</a><ul class="nav flex-column flex-nowrap collapse show" id="sidenav-1"><li class="nav-item"><a class="nav-link" href="/language">Introduction</a></li><li class="nav-item"><a class="nav-link collapsible collapsed" data-toggle="collapse" data-target="#sidenav-1-2" href="#sidenav-1-2" role="button" aria-expanded="false" aria-controls="sidenav-1-2">Syntax basics</a><ul class="nav flex-column flex-nowrap collapse" id="sidenav-1-2"><li class="nav-item"><a class="nav-link" href="/language/variables">Variables</a></li><li class="nav-item"><a class="nav-link" href="/language/operators">Operators</a></li><li class="nav-item"><a class="nav-link" href="/language/comments">Comments</a></li><li class="nav-item"><a class="nav-link" href="/language/metadata">Metadata</a></li><li class="nav-item"><a class="nav-link" href="/language/libraries">Libraries & imports</a></li><li class="nav-item"><a class="nav-link" href="/language/keywords">Keywords</a></li></ul></li><li class="nav-item"><a class="nav-link active collapsible" data-toggle="collapse" data-target="#sidenav-1-3" href="#sidenav-1-3" role="button" aria-expanded="true" aria-controls="sidenav-1-3">Types</a><ul class="nav flex-column flex-nowrap collapse show" id="sidenav-1-3"><li class="nav-item"><a class="nav-link active" href="/language/built-in-types">Built-in types</a></li><li class="nav-item"><a class="nav-link" href="/language/records">Records</a></li><li class="nav-item"><a class="nav-link" href="/language/collections">Collections</a></li><li class="nav-item"><a class="nav-link" href="/language/generics">Generics</a></li><li class="nav-item"><a class="nav-link" href="/language/typedefs">Typedefs</a></li><li class="nav-item"><a class="nav-link" href="/language/type-system">Type system</a></li></ul></li><li class="nav-item"><a class="nav-link collapsible collapsed" data-toggle="collapse" data-target="#sidenav-1-4" href="#sidenav-1-4" role="button" aria-expanded="false" aria-controls="sidenav-1-4">Patterns</a><ul class="nav flex-column flex-nowrap collapse" id="sidenav-1-4"><li class="nav-item"><a class="nav-link" href="/language/patterns">Overview & usage</a></li><li class="nav-item"><a class="nav-link" href="/language/pattern-types">Pattern types</a></li><li class="nav-item"><a class="nav-link" href="https://codelabs.developers.google.com/codelabs/dart-patterns-records" target="_blank" rel="noopener">Applied tutorial</a></li></ul></li><li class="nav-item"><a class="nav-link" href="/language/functions">Functions</a></li><li class="nav-item"><a class="nav-link collapsible collapsed" data-toggle="collapse" data-target="#sidenav-1-6" href="#sidenav-1-6" role="button" aria-expanded="false" aria-controls="sidenav-1-6">Control flow</a><ul class="nav flex-column flex-nowrap collapse" id="sidenav-1-6"><li class="nav-item"><a class="nav-link" href="/language/loops">Loops</a></li><li class="nav-item"><a class="nav-link" href="/language/branches">Branches</a></li><li class="nav-item"><a class="nav-link" href="/language/error-handling">Error handling</a></li></ul></li><li class="nav-item"><a class="nav-link collapsible collapsed" data-toggle="collapse" data-target="#sidenav-1-7" href="#sidenav-1-7" role="button" aria-expanded="false" aria-controls="sidenav-1-7">Classes & objects</a><ul class="nav flex-column flex-nowrap collapse" id="sidenav-1-7"><li class="nav-item"><a class="nav-link" href="/language/classes">Classes</a></li><li class="nav-item"><a class="nav-link" href="/language/constructors">Constructors</a></li><li class="nav-item"><a class="nav-link" href="/language/methods">Methods</a></li><li class="nav-item"><a class="nav-link" href="/language/extend">Extend a class</a></li><li class="nav-item"><a class="nav-link" href="/language/mixins">Mixins</a></li><li class="nav-item"><a class="nav-link" href="/language/enums">Enums</a></li><li class="nav-item"><a class="nav-link" href="/language/extension-methods">Extension methods</a></li><li class="nav-item"><a class="nav-link" href="/language/extension-types">Extension types</a></li><li class="nav-item"><a class="nav-link" href="/language/callable-objects">Callable objects</a></li></ul></li><li class="nav-item"><a class="nav-link collapsible collapsed" data-toggle="collapse" data-target="#sidenav-1-8" href="#sidenav-1-8" role="button" aria-expanded="false" aria-controls="sidenav-1-8">Class modifiers</a><ul class="nav flex-column flex-nowrap collapse" id="sidenav-1-8"><li class="nav-item"><a class="nav-link" href="/language/class-modifiers">Overview & usage</a></li><li class="nav-item"><a class="nav-link" href="/language/class-modifiers-for-apis">Class modifiers for API maintainers</a></li><li class="nav-item"><a class="nav-link" href="/language/modifier-reference">Reference</a></li></ul></li><li class="nav-item"><a class="nav-link collapsible collapsed" data-toggle="collapse" data-target="#sidenav-1-9" href="#sidenav-1-9" role="button" aria-expanded="false" aria-controls="sidenav-1-9">Concurrency</a><ul class="nav flex-column flex-nowrap collapse" id="sidenav-1-9"><li class="nav-item"><a class="nav-link" href="/language/concurrency">Overview</a></li><li class="nav-item"><a class="nav-link" href="/language/async">Asynchronous support</a></li><li class="nav-item"><a class="nav-link" href="/language/isolates">Isolates</a></li></ul></li><li class="nav-item"><a class="nav-link collapsible collapsed" data-toggle="collapse" data-target="#sidenav-1-10" href="#sidenav-1-10" role="button" aria-expanded="false" aria-controls="sidenav-1-10">Null safety</a><ul class="nav flex-column flex-nowrap collapse" id="sidenav-1-10"><li class="nav-item"><a class="nav-link" href="/null-safety">Sound null safety</a></li><li class="nav-item"><a class="nav-link" href="/null-safety/migration-guide">Migrating to null safety</a></li><li class="nav-item"><a class="nav-link" href="/null-safety/understanding-null-safety">Understanding null safety</a></li><li class="nav-item"><a class="nav-link" href="/null-safety/unsound-null-safety">Unsound null safety</a></li><li class="nav-item"><a class="nav-link" href="/null-safety/faq">FAQ</a></li></ul></li></ul></li><li class="nav-item"><a class="nav-link collapsed collapsible" data-toggle="collapse" href="#sidenav-2" role="button" aria-expanded="false" aria-controls="sidenav-2">Core libraries</a><ul class="nav flex-column flex-nowrap collapse" id="sidenav-2"><li class="nav-item"><a class="nav-link" href="/libraries">Overview</a></li><li class="nav-item"><a class="nav-link" href="/libraries/dart-core">dart:core</a></li><li class="nav-item"><a class="nav-link" href="/libraries/dart-async">dart:async</a></li><li class="nav-item"><a class="nav-link" href="/libraries/dart-math">dart:math</a></li><li class="nav-item"><a class="nav-link" href="/libraries/dart-convert">dart:convert</a></li><li class="nav-item"><a class="nav-link" href="/libraries/dart-io">dart:io</a></li><li class="nav-item"><a class="nav-link" href="/libraries/dart-html">dart:html</a></li><div class="dropdown-divider"></div><li class="nav-item"><a class="nav-link" href="/libraries/collections/iterables">Iterable collections</a></li><li class="nav-item"><a class="nav-link collapsible collapsed" data-toggle="collapse" data-target="#sidenav-2-10" href="#sidenav-2-10" role="button" aria-expanded="false" aria-controls="sidenav-2-10">Asynchronous programming</a><ul class="nav flex-column flex-nowrap collapse" id="sidenav-2-10"><li class="nav-item"><a class="nav-link" href="/libraries/async/async-await">Tutorial</a></li><li class="nav-item"><a class="nav-link" href="/libraries/async/futures-error-handling">Futures and error handling</a></li><li class="nav-item"><a class="nav-link" href="/libraries/async/using-streams">Using streams</a></li><li class="nav-item"><a class="nav-link" href="/libraries/async/creating-streams">Creating streams</a></li></ul></li></ul></li><li class="nav-item"><a class="nav-link collapsed collapsible" data-toggle="collapse" href="#sidenav-3" role="button" aria-expanded="false" aria-controls="sidenav-3">Effective Dart</a><ul class="nav flex-column flex-nowrap collapse" id="sidenav-3"><li class="nav-item"><a class="nav-link" href="/effective-dart">Overview</a></li><li class="nav-item"><a class="nav-link" href="/effective-dart/style">Style</a></li><li class="nav-item"><a class="nav-link" href="/effective-dart/documentation">Documentation</a></li><li class="nav-item"><a class="nav-link" href="/effective-dart/usage">Usage</a></li><li class="nav-item"><a class="nav-link" href="/effective-dart/design">Design</a></li></ul></li><li class="nav-item"><a class="nav-link collapsed collapsible" data-toggle="collapse" href="#sidenav-4" role="button" aria-expanded="false" aria-controls="sidenav-4">Packages</a><ul class="nav flex-column flex-nowrap collapse" id="sidenav-4"><li class="nav-item"><a class="nav-link" href="/tools/pub/packages">How to use packages</a></li><li class="nav-item"><a class="nav-link" href="/resources/useful-packages">Commonly used packages</a></li><li class="nav-item"><a class="nav-link" href="/guides/libraries/create-packages">Creating packages</a></li><li class="nav-item"><a class="nav-link" href="/tools/pub/publishing">Publishing packages</a></li><li class="nav-item"><a class="nav-link" href="/tools/pub/writing-package-pages">Writing package pages</a></li><li class="nav-item"><a class="nav-link collapsible collapsed" data-toggle="collapse" data-target="#sidenav-4-6" href="#sidenav-4-6" role="button" aria-expanded="false" aria-controls="sidenav-4-6">Package reference</a><ul class="nav flex-column flex-nowrap collapse" id="sidenav-4-6"><li class="nav-item"><a class="nav-link" href="/tools/pub/dependencies">Dependencies</a></li><li class="nav-item"><a class="nav-link" href="/tools/pub/glossary">Glossary</a></li><li class="nav-item"><a class="nav-link" href="/tools/pub/package-layout">Package layout conventions</a></li><li class="nav-item"><a class="nav-link" href="/tools/pub/environment-variables">Pub environment variables</a></li><li class="nav-item"><a class="nav-link" href="/tools/pub/pubspec">Pubspec file</a></li><li class="nav-item"><a class="nav-link" href="/tools/pub/troubleshoot">Troubleshooting pub</a></li><li class="nav-item"><a class="nav-link" href="/tools/pub/verified-publishers">Verified publishers</a></li><li class="nav-item"><a class="nav-link" href="/tools/pub/security-advisories">Security advisories</a></li><li class="nav-item"><a class="nav-link" href="/tools/pub/versioning">Versioning</a></li><li class="nav-item"><a class="nav-link" href="/tools/pub/custom-package-repositories">Custom package repositories</a></li></ul></li><li class="nav-item"><a class="nav-link" href="/guides/libraries/private-files">What not to commit</a></li></ul></li><li class="nav-item"><a class="nav-link collapsed collapsible" data-toggle="collapse" href="#sidenav-5" role="button" aria-expanded="false" aria-controls="sidenav-5">Development</a><ul class="nav flex-column flex-nowrap collapse" id="sidenav-5"><li class="nav-item"><a class="nav-link" href="/guides/json">JSON</a></li><li class="nav-item"><a class="nav-link" href="/guides/language/numbers">Number representation</a></li><li class="nav-item"><a class="nav-link" href="/resources/google-apis">Google APIs</a></li><li class="nav-item"><a class="nav-link" href="/multiplatform-apps">Multi-platform apps</a></li><li class="nav-item"><a class="nav-link collapsible collapsed" data-toggle="collapse" data-target="#sidenav-5-5" href="#sidenav-5-5" role="button" aria-expanded="false" aria-controls="sidenav-5-5">Command-line & server apps</a><ul class="nav flex-column flex-nowrap collapse" id="sidenav-5-5"><li class="nav-item"><a class="nav-link" href="/server">Overview</a></li><li class="nav-item"><a class="nav-link" href="/tutorials/server/get-started">Get started</a></li><li class="nav-item"><a class="nav-link" href="/tutorials/server/cmdline">Write command-line apps</a></li><li class="nav-item"><a class="nav-link" href="/tutorials/server/fetch-data">Fetch data from the internet</a></li><li class="nav-item"><a class="nav-link" href="/tutorials/server/httpserver">Write HTTP servers</a></li><li class="nav-item"><a class="nav-link" href="/server/libraries">Libraries & packages</a></li><li class="nav-item"><a class="nav-link" href="/server/google-cloud">Google Cloud</a></li></ul></li><li class="nav-item"><a class="nav-link collapsible collapsed" data-toggle="collapse" data-target="#sidenav-5-6" href="#sidenav-5-6" role="button" aria-expanded="false" aria-controls="sidenav-5-6">Web apps</a><ul class="nav flex-column flex-nowrap collapse" id="sidenav-5-6"><li class="nav-item"><a class="nav-link" href="/web">Overview</a></li><li class="nav-item"><a class="nav-link" href="/web/get-started">Get started</a></li><li class="nav-item"><a class="nav-link" href="/web/deployment">Deployment</a></li><li class="nav-item"><a class="nav-link" href="/web/libraries">Libraries & packages</a></li><li class="nav-item"><a class="nav-link" href="/web/wasm">Wasm compilation</a></li></ul></li><li class="nav-item"><a class="nav-link" href="/guides/environment-declarations">Environment declarations</a></li></ul></li><li class="nav-item"><a class="nav-link collapsed collapsible" data-toggle="collapse" href="#sidenav-6" role="button" aria-expanded="false" aria-controls="sidenav-6">Interoperability</a><ul class="nav flex-column flex-nowrap collapse" id="sidenav-6"><li class="nav-item"><a class="nav-link" href="/interop/c-interop">C interop</a></li><li class="nav-item"><a class="nav-link" href="/interop/objective-c-interop">Objective-C & Swift interop</a></li><li class="nav-item"><a class="nav-link" href="/interop/java-interop">Java & Kotlin interop</a></li><li class="nav-item"><a class="nav-link collapsible collapsed" data-toggle="collapse" data-target="#sidenav-6-4" href="#sidenav-6-4" role="button" aria-expanded="false" aria-controls="sidenav-6-4">JavaScript interop</a><ul class="nav flex-column flex-nowrap collapse" id="sidenav-6-4"><li class="nav-item"><a class="nav-link" href="/interop/js-interop">Overview</a></li><li class="nav-item"><a class="nav-link" href="/interop/js-interop/usage">Usage</a></li><li class="nav-item"><a class="nav-link" href="/interop/js-interop/js-types">JS types</a></li><li class="nav-item"><a class="nav-link" href="/interop/js-interop/tutorials">Tutorials</a></li><li class="nav-item"><a class="nav-link" href="/interop/js-interop/past-js-interop">Past JS interop</a></li><div class="dropdown-divider"></div><li class="nav-item"><a class="nav-link" href="/interop/js-interop/package-web">Web interop</a></li></ul></li></ul></li><li class="nav-item"><a class="nav-link collapsed collapsible" data-toggle="collapse" href="#sidenav-7" role="button" aria-expanded="false" aria-controls="sidenav-7">Tools & techniques</a><ul class="nav flex-column flex-nowrap collapse" id="sidenav-7"><li class="nav-item"><a class="nav-link" href="/tools">Overview</a></li><li class="nav-item"><a class="nav-link collapsible collapsed" data-toggle="collapse" data-target="#sidenav-7-2" href="#sidenav-7-2" role="button" aria-expanded="false" aria-controls="sidenav-7-2">Editors & debuggers</a><ul class="nav flex-column flex-nowrap collapse" id="sidenav-7-2"><li class="nav-item"><a class="nav-link" href="/tools/jetbrains-plugin">IntelliJ & Android Studio</a></li><li class="nav-item"><a class="nav-link" href="/tools/vs-code">VS Code</a></li><li class="nav-item"><a class="nav-link" href="/tools/dart-devtools">Dart DevTools</a></li><li class="nav-item"><a class="nav-link collapsible collapsed" data-toggle="collapse" data-target="#sidenav-7-2-4" href="#sidenav-7-2-4" role="button" aria-expanded="false" aria-controls="sidenav-7-2-4">DartPad</a><ul class="nav flex-column flex-nowrap collapse" id="sidenav-7-2-4"><li class="nav-item"><a class="nav-link" href="/tools/dartpad">Overview</a></li><li class="nav-item"><a class="nav-link" href="/tools/dartpad/troubleshoot">Troubleshooting DartPad</a></li></ul></li></ul></li><li class="nav-item"><a class="nav-link collapsible collapsed" data-toggle="collapse" data-target="#sidenav-7-3" href="#sidenav-7-3" role="button" aria-expanded="false" aria-controls="sidenav-7-3">Command-line tools</a><ul class="nav flex-column flex-nowrap collapse" id="sidenav-7-3"><li class="nav-item"><a class="nav-link collapsible" data-toggle="collapse" data-target="#sidenav-7-3-1" href="#sidenav-7-3-1" role="button" aria-expanded="true" aria-controls="sidenav-7-3-1">Dart SDK</a><ul class="nav flex-column flex-nowrap collapse show" id="sidenav-7-3-1"><li class="nav-item"><a class="nav-link" href="/tools/sdk">Overview</a></li><li class="nav-item"><a class="nav-link" href="/tools/dart-tool">dart</a></li><li class="nav-item"><a class="nav-link" href="/tools/dart-analyze">dart analyze</a></li><li class="nav-item"><a class="nav-link" href="/tools/dart-compile">dart compile</a></li><li class="nav-item"><a class="nav-link" href="/tools/dart-create">dart create</a></li><li class="nav-item"><a class="nav-link" href="/tools/dart-doc">dart doc</a></li><li class="nav-item"><a class="nav-link" href="/tools/dart-fix">dart fix</a></li><li class="nav-item"><a class="nav-link" href="/tools/dart-format">dart format</a></li><li class="nav-item"><a class="nav-link" href="/tools/dart-info">dart info</a></li><li class="nav-item"><a class="nav-link" href="/tools/pub/cmd">dart pub</a></li><li class="nav-item"><a class="nav-link" href="/tools/dart-run">dart run</a></li><li class="nav-item"><a class="nav-link" href="/tools/dart-test">dart test</a></li><li class="nav-item"><a class="nav-link" href="/tools/dartaotruntime">dartaotruntime</a></li><li class="nav-item"><a class="nav-link" href="/tools/experiment-flags">Experiment flags</a></li></ul></li><li class="nav-item"><a class="nav-link collapsible" data-toggle="collapse" data-target="#sidenav-7-3-2" href="#sidenav-7-3-2" role="button" aria-expanded="true" aria-controls="sidenav-7-3-2">Other command-line tools</a><ul class="nav flex-column flex-nowrap collapse show" id="sidenav-7-3-2"><li class="nav-item"><a class="nav-link" href="/tools/build_runner">build_runner</a></li><li class="nav-item"><a class="nav-link" href="/tools/webdev">webdev</a></li></ul></li></ul></li><li class="nav-item"><a class="nav-link collapsible collapsed" data-toggle="collapse" data-target="#sidenav-7-4" href="#sidenav-7-4" role="button" aria-expanded="false" aria-controls="sidenav-7-4">Static analysis</a><ul class="nav flex-column flex-nowrap collapse" id="sidenav-7-4"><li class="nav-item"><a class="nav-link" href="/tools/analysis">Customizing static analysis</a></li><li class="nav-item"><a class="nav-link" href="/guides/language/sound-problems">Fixing common type problems</a></li><li class="nav-item"><a class="nav-link" href="/tools/non-promotion-reasons">Fixing type promotion failures</a></li><li class="nav-item"><a class="nav-link" href="/tools/linter-rules">Linter rules</a></li><li class="nav-item"><a class="nav-link" href="/tools/diagnostic-messages">Diagnostic messages</a></li></ul></li><li class="nav-item"><a class="nav-link collapsible collapsed" data-toggle="collapse" data-target="#sidenav-7-5" href="#sidenav-7-5" role="button" aria-expanded="false" aria-controls="sidenav-7-5">Testing & optimization</a><ul class="nav flex-column flex-nowrap collapse" id="sidenav-7-5"><li class="nav-item"><a class="nav-link" href="/guides/testing">Testing</a></li><li class="nav-item"><a class="nav-link" href="/web/debugging">Debugging web apps</a></li></ul></li></ul></li><li aria-hidden="true"><div class="sidebar-primary-divider"></div></li><li class="nav-item"><a class="nav-link collapsed collapsible" data-toggle="collapse" href="#sidenav-9" role="button" aria-expanded="false" aria-controls="sidenav-9">Resources</a><ul class="nav flex-column flex-nowrap collapse" id="sidenav-9"><li class="nav-item"><a class="nav-link" href="/resources/dart-cheatsheet">Language cheatsheet</a></li><li class="nav-item"><a class="nav-link" href="/resources/breaking-changes">Breaking changes</a></li><li class="nav-item"><a class="nav-link" href="/guides/language/evolution">Language evolution</a></li><li class="nav-item"><a class="nav-link" href="/guides/language/spec">Language specification</a></li><li class="nav-item"><a class="nav-link" href="/resources/dart-3-migration">Dart 3 migration guide</a></li><li class="nav-item"><a class="nav-link collapsible collapsed" data-toggle="collapse" data-target="#sidenav-9-6" href="#sidenav-9-6" role="button" aria-expanded="false" aria-controls="sidenav-9-6">Coming from ...</a><ul class="nav flex-column flex-nowrap collapse" id="sidenav-9-6"><li class="nav-item"><a class="nav-link" href="/resources/coming-from/js-to-dart">JavaScript to Dart</a></li><li class="nav-item"><a class="nav-link" href="/resources/coming-from/swift-to-dart">Swift to Dart</a></li></ul></li><div class="dropdown-divider"></div><li class="nav-item"><a class="nav-link" href="/resources/faq">FAQ</a></li><li class="nav-item"><a class="nav-link" href="/resources/glossary">Glossary</a></li><li class="nav-item"><a class="nav-link" href="/resources/books">Books</a></li><li class="nav-item"><a class="nav-link" href="/resources/videos">Videos</a></li><li class="nav-item"><a class="nav-link" href="/tutorials">Tutorials</a></li></ul></li><li class="nav-item"><a class="nav-link collapsible" data-toggle="collapse" href="#sidenav-10" role="button" aria-expanded="true" aria-controls="sidenav-10">Related sites</a><ul class="nav flex-column flex-nowrap collapse show" id="sidenav-10"><li class="nav-item"><a class="nav-link" href="https://api.dart.dev" target="_blank" rel="noopener">API reference</a></li><li class="nav-item"><a class="nav-link" href="https://medium.com/dartlang" target="_blank" rel="noopener">Blog</a></li><li class="nav-item"><a class="nav-link" href="https://dartpad.dev" target="_blank" rel="noopener">DartPad (online editor)</a></li><li class="nav-item"><a class="nav-link" href="https://flutter.dev" target="_blank" rel="noopener">Flutter</a></li><li class="nav-item"><a class="nav-link" href="https://pub.dev" target="_blank" rel="noopener">Package site</a></li></ul></li></ul></div></div><main id="page-content"><div id="site-toc--side" class="site-toc"><header class="site-toc__title">Contents</header><ul class="section-nav"><li class="toc-entry nav-item"><a class="nav-link" href="#numbers">Numbers</a></li><li class="toc-entry nav-item"><a class="nav-link" href="#strings">Strings</a></li><li class="toc-entry nav-item"><a class="nav-link" href="#booleans">Booleans</a></li><li class="toc-entry nav-item"><a class="nav-link" href="#runes-and-grapheme-clusters">Runes and grapheme clusters</a></li><li class="toc-entry nav-item"><a class="nav-link" href="#symbols">Symbols</a></li></ul></div><article><div class="content"><nav id="subnav"><ul><li class="previous"><a href="/language/keywords">⟨ Keywords</a></li><li class="next"><a href="/language/records">Records ⟩</a></li></ul></nav><div id="site-content-title"><h1>Built-in types</h1></div><div id="site-toc--inline" class="site-toc"><header class="site-toc__title">Contents</header><ul class="section-nav"><li class="toc-entry"><a href="#numbers">Numbers</a></li><li class="toc-entry"><a href="#strings">Strings</a></li><li class="toc-entry"><a href="#booleans">Booleans</a></li><li class="toc-entry"><a href="#runes-and-grapheme-clusters">Runes and grapheme clusters</a></li><li class="toc-entry"><a href="#symbols">Symbols</a></li></ul></div><p>The Dart language has special support for the following:</p><ul><li><a href="#numbers">Numbers</a> (<code>int</code>, <code>double</code>)</li><li><a href="#strings">Strings</a> (<code>String</code>)</li><li><a href="#booleans">Booleans</a> (<code>bool</code>)</li><li><a href="/language/records">Records</a> (<code>(value1, value2)</code>)</li><li><a href="/language/functions#function-types">Functions</a> (<code>Function</code>)</li><li><a href="/language/collections#lists">Lists</a> (<code>List</code>, also known as <em>arrays</em>)</li><li><a href="/language/collections#sets">Sets</a> (<code>Set</code>)</li><li><a href="/language/collections#maps">Maps</a> (<code>Map</code>)</li><li><a href="#runes-and-grapheme-clusters">Runes</a> (<code>Runes</code>; often replaced by the <code>characters</code> API)</li><li><a href="#symbols">Symbols</a> (<code>Symbol</code>)</li><li>The value <code>null</code> (<code>Null</code>)</li></ul><p>This support includes the ability to create objects using literals. For example, <code>'this is a string'</code> is a string literal, and <code>true</code> is a boolean literal.</p><p>Because every variable in Dart refers to an object—an instance of a <em>class</em>—you can usually use <em>constructors</em> to initialize variables. Some of the built-in types have their own constructors. For example, you can use the <code>Map()</code> constructor to create a map.</p><p>Some other types also have special roles in the Dart language:</p><ul><li><code>Object</code>: The superclass of all Dart classes except <code>Null</code>.</li><li><code>Enum</code>: The superclass of all enums.</li><li><code>Future</code> and <code>Stream</code>: Used in <a href="/language/async">asynchrony support</a>.</li><li><code>Iterable</code>: Used in <a href="/libraries/dart-core#iteration">for-in loops</a> and in synchronous <a href="/language/functions#generators">generator functions</a>.</li><li><code>Never</code>: Indicates that an expression can never successfully finish evaluating. Most often used for functions that always throw an exception.</li><li><code>dynamic</code>: Indicates that you want to disable static checking. Usually you should use <code>Object</code> or <code>Object?</code> instead.</li><li><code>void</code>: Indicates that a value is never used. Often used as a return type.</li></ul><p>The <code>Object</code>, <code>Object?</code>, <code>Null</code>, and <code>Never</code> classes have special roles in the class hierarchy. Learn about these roles in <a href="/null-safety/understanding-null-safety#top-and-bottom">Understanding null safety</a>.</p><div class="header-wrapper"><h2 id="numbers">Numbers</h2><a class="heading-link" href="#numbers" aria-label="Link to 'Numbers' section">#</a></div><p>Dart numbers come in two flavors:</p><dl><dt><a href="https://api.dart.dev/dart-core/int-class.html"><code>int</code></a></dt><dd>Integer values no larger than 64 bits, <a href="/guides/language/numbers">depending on the platform</a>. On native platforms, values can be from -2<sup>63</sup> to 2<sup>63</sup> - 1. On the web, integer values are represented as JavaScript numbers (64-bit floating-point values with no fractional part) and can be from -2<sup>53</sup> to 2<sup>53</sup> - 1.</dd><dt><a href="https://api.dart.dev/dart-core/double-class.html"><code>double</code></a></dt><dd>64-bit (double-precision) floating-point numbers, as specified by the IEEE 754 standard.</dd></dl><p>Both <code>int</code> and <code>double</code> are subtypes of <a href="https://api.dart.dev/dart-core/num-class.html"><code>num</code></a>. The num type includes basic operators such as +, -, /, and *, and is also where you'll find <code>abs()</code>,<code>ceil()</code>, and <code>floor()</code>, among other methods. (Bitwise operators, such as >>, are defined in the <code>int</code> class.) If num and its subtypes don't have what you're looking for, the <a href="https://api.dart.dev/dart-math">dart:math</a> library might.</p><p>Integers are numbers without a decimal point. Here are some examples of defining integer literals:</p> <?code-excerpt "misc/lib/language_tour/built_in_types.dart (integer-literals)"?> <div class="code-block-wrapper language-dart"><div class="code-block-body"><span class="code-block-language" title="Language dart">dart</span><pre class="shiki dash-light" tabindex="0"><code><span class="line"><span style="color:#D43324">var</span><span style="color:#222222"> x = </span><span style="color:#11796D">1</span><span style="color:#222222">;</span></span> <span class="line"><span style="color:#D43324">var</span><span style="color:#222222"> hex = </span><span style="color:#11796D">0xDEADBEEF</span><span style="color:#222222">;</span></span></code></pre></div></div><p>If a number includes a decimal, it is a double. Here are some examples of defining double literals:</p> <?code-excerpt "misc/lib/language_tour/built_in_types.dart (double-literals)"?> <div class="code-block-wrapper language-dart"><div class="code-block-body"><span class="code-block-language" title="Language dart">dart</span><pre class="shiki dash-light" tabindex="0"><code><span class="line"><span style="color:#D43324">var</span><span style="color:#222222"> y = </span><span style="color:#11796D">1.1</span><span style="color:#222222">;</span></span> <span class="line"><span style="color:#D43324">var</span><span style="color:#222222"> exponents = </span><span style="color:#11796D">1.42e5</span><span style="color:#222222">;</span></span></code></pre></div></div><p>You can also declare a variable as a num. If you do this, the variable can have both integer and double values.</p> <?code-excerpt "misc/lib/language_tour/built_in_types.dart (declare-num)"?> <div class="code-block-wrapper language-dart"><div class="code-block-body"><span class="code-block-language" title="Language dart">dart</span><pre class="shiki dash-light" tabindex="0"><code><span class="line"><span style="color:#0468D7">num</span><span style="color:#222222"> x = </span><span style="color:#11796D">1</span><span style="color:#222222">; </span><span style="color:#6E6E70">// x can have both int and double values</span></span> <span class="line"><span style="color:#222222">x += </span><span style="color:#11796D">2.5</span><span style="color:#222222">;</span></span></code></pre></div></div><p>Integer literals are automatically converted to doubles when necessary:</p> <?code-excerpt "misc/lib/language_tour/built_in_types.dart (int-to-double)"?> <div class="code-block-wrapper language-dart"><div class="code-block-body"><span class="code-block-language" title="Language dart">dart</span><pre class="shiki dash-light" tabindex="0"><code><span class="line"><span style="color:#0468D7">double</span><span style="color:#222222"> z = </span><span style="color:#11796D">1</span><span style="color:#222222">; </span><span style="color:#6E6E70">// Equivalent to double z = 1.0.</span></span></code></pre></div></div><p>Here's how you turn a string into a number, or vice versa:</p> <?code-excerpt "misc/test/language_tour/built_in_types_test.dart (number-conversion)"?> <div class="code-block-wrapper language-dart"><div class="code-block-body"><span class="code-block-language" title="Language dart">dart</span><pre class="shiki dash-light" tabindex="0"><code><span class="line"><span style="color:#6E6E70">// String -> int</span></span> <span class="line"><span style="color:#D43324">var</span><span style="color:#222222"> one = </span><span style="color:#0468D7">int</span><span style="color:#222222">.</span><span style="color:#6200EE">parse</span><span style="color:#222222">(</span><span style="color:#11796D">'1'</span><span style="color:#222222">);</span></span> <span class="line"><span style="color:#D43324">assert</span><span style="color:#222222">(one == </span><span style="color:#11796D">1</span><span style="color:#222222">);</span></span> <span class="line"></span> <span class="line"><span style="color:#6E6E70">// String -> double</span></span> <span class="line"><span style="color:#D43324">var</span><span style="color:#222222"> onePointOne = </span><span style="color:#0468D7">double</span><span style="color:#222222">.</span><span style="color:#6200EE">parse</span><span style="color:#222222">(</span><span style="color:#11796D">'1.1'</span><span style="color:#222222">);</span></span> <span class="line"><span style="color:#D43324">assert</span><span style="color:#222222">(onePointOne == </span><span style="color:#11796D">1.1</span><span style="color:#222222">);</span></span> <span class="line"></span> <span class="line"><span style="color:#6E6E70">// int -> String</span></span> <span class="line"><span style="color:#0468D7">String</span><span style="color:#222222"> oneAsString = </span><span style="color:#11796D">1.</span><span style="color:#6200EE">toString</span><span style="color:#222222">();</span></span> <span class="line"><span style="color:#D43324">assert</span><span style="color:#222222">(oneAsString == </span><span style="color:#11796D">'1'</span><span style="color:#222222">);</span></span> <span class="line"></span> <span class="line"><span style="color:#6E6E70">// double -> String</span></span> <span class="line"><span style="color:#0468D7">String</span><span style="color:#222222"> piAsString = </span><span style="color:#11796D">3.14159</span><span style="color:#222222">.</span><span style="color:#6200EE">toStringAsFixed</span><span style="color:#222222">(</span><span style="color:#11796D">2</span><span style="color:#222222">);</span></span> <span class="line"><span style="color:#D43324">assert</span><span style="color:#222222">(piAsString == </span><span style="color:#11796D">'3.14'</span><span style="color:#222222">);</span></span></code></pre></div></div><p>The <code>int</code> type specifies the traditional bitwise shift (<code><<</code>, <code>>></code>, <code>>>></code>), complement (<code>~</code>), AND (<code>&</code>), OR (<code>|</code>), and XOR (<code>^</code>) operators, which are useful for manipulating and masking flags in bit fields. For example:</p> <?code-excerpt "misc/test/language_tour/built_in_types_test.dart (bit-shifting)"?> <div class="code-block-wrapper language-dart"><div class="code-block-body"><span class="code-block-language" title="Language dart">dart</span><pre class="shiki dash-light" tabindex="0"><code><span class="line"><span style="color:#D43324">assert</span><span style="color:#222222">((</span><span style="color:#11796D">3</span><span style="color:#222222"> << </span><span style="color:#11796D">1</span><span style="color:#222222">) == </span><span style="color:#11796D">6</span><span style="color:#222222">); </span><span style="color:#6E6E70">// 0011 << 1 == 0110</span></span> <span class="line"><span style="color:#D43324">assert</span><span style="color:#222222">((</span><span style="color:#11796D">3</span><span style="color:#222222"> | </span><span style="color:#11796D">4</span><span style="color:#222222">) == </span><span style="color:#11796D">7</span><span style="color:#222222">); </span><span style="color:#6E6E70">// 0011 | 0100 == 0111</span></span> <span class="line"><span style="color:#D43324">assert</span><span style="color:#222222">((</span><span style="color:#11796D">3</span><span style="color:#222222"> & </span><span style="color:#11796D">4</span><span style="color:#222222">) == </span><span style="color:#11796D">0</span><span style="color:#222222">); </span><span style="color:#6E6E70">// 0011 & 0100 == 0000</span></span></code></pre></div></div><p>For more examples, see the <a href="/language/operators#bitwise-and-shift-operators">bitwise and shift operator</a> section.</p><p>Number literals are compile-time constants. Many arithmetic expressions are also compile-time constants, as long as their operands are compile-time constants that evaluate to numbers.</p> <?code-excerpt "misc/lib/language_tour/built_in_types.dart (const-num)"?> <div class="code-block-wrapper language-dart"><div class="code-block-body"><span class="code-block-language" title="Language dart">dart</span><pre class="shiki dash-light" tabindex="0"><code><span class="line"><span style="color:#D43324">const</span><span style="color:#222222"> msPerSecond = </span><span style="color:#11796D">1000</span><span style="color:#222222">;</span></span> <span class="line"><span style="color:#D43324">const</span><span style="color:#222222"> secondsUntilRetry = </span><span style="color:#11796D">5</span><span style="color:#222222">;</span></span> <span class="line"><span style="color:#D43324">const</span><span style="color:#222222"> msUntilRetry = secondsUntilRetry * msPerSecond;</span></span></code></pre></div></div><p>For more information, see <a href="/guides/language/numbers">Numbers in Dart</a>.</p><p>You can use one or more underscores (<code>_</code>) as digit separators to make long number literals more readable. Multiple digit separators allow for higher level grouping.</p><div class="code-block-wrapper language-dart"><div class="code-block-body"><span class="code-block-language" title="Language dart">dart</span><pre class="shiki dash-light" tabindex="0"><code><span class="line"><span style="color:#D43324">var</span><span style="color:#222222"> n1 = </span><span style="color:#11796D">1_000_000</span><span style="color:#222222">;</span></span> <span class="line"><span style="color:#D43324">var</span><span style="color:#222222"> n2 = </span><span style="color:#11796D">0.000_000_000_01</span><span style="color:#222222">;</span></span> <span class="line"><span style="color:#D43324">var</span><span style="color:#222222"> n3 = </span><span style="color:#11796D">0x00_14_22_01_23_45</span><span style="color:#222222">; </span><span style="color:#6E6E70">// MAC address</span></span> <span class="line"><span style="color:#D43324">var</span><span style="color:#222222"> n4 = </span><span style="color:#11796D">555_123_4567</span><span style="color:#222222">; </span><span style="color:#6E6E70">// US Phone number</span></span> <span class="line"><span style="color:#D43324">var</span><span style="color:#222222"> n5 = </span><span style="color:#11796D">100__000_000__000_000</span><span style="color:#222222">; </span><span style="color:#6E6E70">// one hundred million million!</span></span></code></pre></div></div><aside class="alert alert-info"><div class="alert-header"><i class="material-symbols" aria-hidden="true">merge_type</i> <span>Version note</span></div><div class="alert-content"><p>Using digit separators requires a <a href="/guides/language/evolution#language-versioning">language version</a> of at least 3.6.0.</p></div></aside><div class="header-wrapper"><h2 id="strings">Strings</h2><a class="heading-link" href="#strings" aria-label="Link to 'Strings' section">#</a></div><p>A Dart string (<code>String</code> object) holds a sequence of UTF-16 code units. You can use either single or double quotes to create a string:</p> <?code-excerpt "misc/lib/language_tour/built_in_types.dart (quoting)"?> <div class="code-block-wrapper language-dart"><div class="code-block-body"><span class="code-block-language" title="Language dart">dart</span><pre class="shiki dash-light" tabindex="0"><code><span class="line"><span style="color:#D43324">var</span><span style="color:#222222"> s1 = </span><span style="color:#11796D">'Single quotes work well for string literals.'</span><span style="color:#222222">;</span></span> <span class="line"><span style="color:#D43324">var</span><span style="color:#222222"> s2 = </span><span style="color:#11796D">"Double quotes work just as well."</span><span style="color:#222222">;</span></span> <span class="line"><span style="color:#D43324">var</span><span style="color:#222222"> s3 = </span><span style="color:#11796D">'It</span><span style="color:#222222">\'</span><span style="color:#11796D">s easy to escape the string delimiter.'</span><span style="color:#222222">;</span></span> <span class="line"><span style="color:#D43324">var</span><span style="color:#222222"> s4 = </span><span style="color:#11796D">"It's even easier to use the other delimiter."</span><span style="color:#222222">;</span></span></code></pre></div></div><p><a id="string-interpolation"></a></p><p>You can put the value of an expression inside a string by using <code>${</code><em><code>expression</code></em><code>}</code>. If the expression is an identifier, you can skip the <code>{}</code>. To get the string corresponding to an object, Dart calls the object's <code>toString()</code> method.</p> <?code-excerpt "misc/test/language_tour/built_in_types_test.dart (string-interpolation)"?> <div class="code-block-wrapper language-dart"><div class="code-block-body"><span class="code-block-language" title="Language dart">dart</span><pre class="shiki dash-light" tabindex="0"><code><span class="line"><span style="color:#D43324">var</span><span style="color:#222222"> s = </span><span style="color:#11796D">'string interpolation'</span><span style="color:#222222">;</span></span> <span class="line"></span> <span class="line"><span style="color:#D43324">assert</span><span style="color:#222222">(</span><span style="color:#11796D">'Dart has </span><span style="color:#11796D">$</span><span style="color:#222222">s</span><span style="color:#11796D">, which is very handy.'</span><span style="color:#222222"> ==</span></span> <span class="line"><span style="color:#11796D"> 'Dart has string interpolation, '</span></span> <span class="line"><span style="color:#11796D"> 'which is very handy.'</span><span style="color:#222222">);</span></span> <span class="line"><span style="color:#D43324">assert</span><span style="color:#222222">(</span><span style="color:#11796D">'That deserves all caps. '</span></span> <span class="line"><span style="color:#11796D"> '</span><span style="color:#11796D">${</span><span style="color:#222222">s</span><span style="color:#11796D">.</span><span style="color:#6200EE">toUpperCase</span><span style="color:#11796D">()}</span><span style="color:#11796D"> is very handy!'</span><span style="color:#222222"> ==</span></span> <span class="line"><span style="color:#11796D"> 'That deserves all caps. '</span></span> <span class="line"><span style="color:#11796D"> 'STRING INTERPOLATION is very handy!'</span><span style="color:#222222">);</span></span></code></pre></div></div><aside class="alert alert-info"><div class="alert-header"><i class="material-symbols" aria-hidden="true">info</i> <span>Note</span></div><div class="alert-content"><p>The <code>==</code> operator tests whether two objects are equivalent. Two strings are equivalent if they contain the same sequence of code units.</p></div></aside><p>You can concatenate strings using adjacent string literals or the <code>+</code> operator:</p> <?code-excerpt "misc/test/language_tour/built_in_types_test.dart (adjacent-string-literals)"?> <div class="code-block-wrapper language-dart"><div class="code-block-body"><span class="code-block-language" title="Language dart">dart</span><pre class="shiki dash-light" tabindex="0"><code><span class="line"><span style="color:#D43324">var</span><span style="color:#222222"> s1 = </span><span style="color:#11796D">'String '</span></span> <span class="line"><span style="color:#11796D"> 'concatenation'</span></span> <span class="line"><span style="color:#11796D"> " works even over line breaks."</span><span style="color:#222222">;</span></span> <span class="line"><span style="color:#D43324">assert</span><span style="color:#222222">(s1 ==</span></span> <span class="line"><span style="color:#11796D"> 'String concatenation works even over '</span></span> <span class="line"><span style="color:#11796D"> 'line breaks.'</span><span style="color:#222222">);</span></span> <span class="line"></span> <span class="line"><span style="color:#D43324">var</span><span style="color:#222222"> s2 = </span><span style="color:#11796D">'The + operator '</span><span style="color:#222222"> + </span><span style="color:#11796D">'works, as well.'</span><span style="color:#222222">;</span></span> <span class="line"><span style="color:#D43324">assert</span><span style="color:#222222">(s2 == </span><span style="color:#11796D">'The + operator works, as well.'</span><span style="color:#222222">);</span></span></code></pre></div></div><p>To create a multi-line string, use a triple quote with either single or double quotation marks:</p> <?code-excerpt "misc/lib/language_tour/built_in_types.dart (triple-quotes)"?> <div class="code-block-wrapper language-dart"><div class="code-block-body"><span class="code-block-language" title="Language dart">dart</span><pre class="shiki dash-light" tabindex="0"><code><span class="line"><span style="color:#D43324">var</span><span style="color:#222222"> s1 = </span><span style="color:#11796D">'''</span></span> <span class="line"><span style="color:#11796D">You can create</span></span> <span class="line"><span style="color:#11796D">multi-line strings like this one.</span></span> <span class="line"><span style="color:#11796D">'''</span><span style="color:#222222">;</span></span> <span class="line"></span> <span class="line"><span style="color:#D43324">var</span><span style="color:#222222"> s2 = </span><span style="color:#11796D">"""This is also a</span></span> <span class="line"><span style="color:#11796D">multi-line string."""</span><span style="color:#222222">;</span></span></code></pre></div></div><p>You can create a "raw" string by prefixing it with <code>r</code>:</p> <?code-excerpt "misc/lib/language_tour/built_in_types.dart (raw-strings)"?> <div class="code-block-wrapper language-dart"><div class="code-block-body"><span class="code-block-language" title="Language dart">dart</span><pre class="shiki dash-light" tabindex="0"><code><span class="line"><span style="color:#D43324">var</span><span style="color:#222222"> s = </span><span style="color:#11796D">r'In a raw string, not even \n gets special treatment.'</span><span style="color:#222222">;</span></span></code></pre></div></div><p>See <a href="#runes-and-grapheme-clusters">Runes and grapheme clusters</a> for details on how to express Unicode characters in a string.</p><p>String literals are compile-time constants, as long as any interpolated expression is a compile-time constant that evaluates to null or a numeric, string, or boolean value.</p> <?code-excerpt "misc/lib/language_tour/built_in_types.dart (string-literals)"?> <div class="code-block-wrapper language-dart"><div class="code-block-body"><span class="code-block-language" title="Language dart">dart</span><pre class="shiki dash-light" tabindex="0"><code><span class="line"><span style="color:#6E6E70">// These work in a const string.</span></span> <span class="line"><span style="color:#D43324">const</span><span style="color:#222222"> aConstNum = </span><span style="color:#11796D">0</span><span style="color:#222222">;</span></span> <span class="line"><span style="color:#D43324">const</span><span style="color:#222222"> aConstBool = </span><span style="color:#11796D">true</span><span style="color:#222222">;</span></span> <span class="line"><span style="color:#D43324">const</span><span style="color:#222222"> aConstString = </span><span style="color:#11796D">'a constant string'</span><span style="color:#222222">;</span></span> <span class="line"></span> <span class="line"><span style="color:#6E6E70">// These do NOT work in a const string.</span></span> <span class="line"><span style="color:#D43324">var</span><span style="color:#222222"> aNum = </span><span style="color:#11796D">0</span><span style="color:#222222">;</span></span> <span class="line"><span style="color:#D43324">var</span><span style="color:#222222"> aBool = </span><span style="color:#11796D">true</span><span style="color:#222222">;</span></span> <span class="line"><span style="color:#D43324">var</span><span style="color:#222222"> aString = </span><span style="color:#11796D">'a string'</span><span style="color:#222222">;</span></span> <span class="line"><span style="color:#D43324">const</span><span style="color:#222222"> aConstList = [</span><span style="color:#11796D">1</span><span style="color:#222222">, </span><span style="color:#11796D">2</span><span style="color:#222222">, </span><span style="color:#11796D">3</span><span style="color:#222222">];</span></span> <span class="line"></span> <span class="line"><span style="color:#D43324">const</span><span style="color:#222222"> validConstString = </span><span style="color:#11796D">'</span><span style="color:#11796D">$</span><span style="color:#222222">aConstNum</span><span style="color:#11796D"> $</span><span style="color:#222222">aConstBool</span><span style="color:#11796D"> $</span><span style="color:#222222">aConstString</span><span style="color:#11796D">'</span><span style="color:#222222">;</span></span> <span class="line"><span style="color:#6E6E70">// const invalidConstString = '$aNum $aBool $aString $aConstList';</span></span></code></pre></div></div><p>For more information on using strings, check out <a href="/libraries/dart-core#strings-and-regular-expressions">Strings and regular expressions</a>.</p><div class="header-wrapper"><h2 id="booleans">Booleans</h2><a class="heading-link" href="#booleans" aria-label="Link to 'Booleans' section">#</a></div><p>To represent boolean values, Dart has a type named <code>bool</code>. Only two objects have type bool: the boolean literals <code>true</code> and <code>false</code>, which are both compile-time constants.</p><p>Dart's type safety means that you can't use code like <code>if (<em>nonbooleanValue</em>)</code> or <code>assert (<em>nonbooleanValue</em>)</code>. Instead, explicitly check for values, like this:</p> <?code-excerpt "misc/test/language_tour/built_in_types_test.dart (no-truthy)"?> <div class="code-block-wrapper language-dart"><div class="code-block-body"><span class="code-block-language" title="Language dart">dart</span><pre class="shiki dash-light" tabindex="0"><code><span class="line"><span style="color:#6E6E70">// Check for an empty string.</span></span> <span class="line"><span style="color:#D43324">var</span><span style="color:#222222"> fullName = </span><span style="color:#11796D">''</span><span style="color:#222222">;</span></span> <span class="line"><span style="color:#D43324">assert</span><span style="color:#222222">(fullName.isEmpty);</span></span> <span class="line"></span> <span class="line"><span style="color:#6E6E70">// Check for zero.</span></span> <span class="line"><span style="color:#D43324">var</span><span style="color:#222222"> hitPoints = </span><span style="color:#11796D">0</span><span style="color:#222222">;</span></span> <span class="line"><span style="color:#D43324">assert</span><span style="color:#222222">(hitPoints == </span><span style="color:#11796D">0</span><span style="color:#222222">);</span></span> <span class="line"></span> <span class="line"><span style="color:#6E6E70">// Check for null.</span></span> <span class="line"><span style="color:#D43324">var</span><span style="color:#222222"> unicorn = </span><span style="color:#11796D">null</span><span style="color:#222222">;</span></span> <span class="line"><span style="color:#D43324">assert</span><span style="color:#222222">(unicorn == </span><span style="color:#11796D">null</span><span style="color:#222222">);</span></span> <span class="line"></span> <span class="line"><span style="color:#6E6E70">// Check for NaN.</span></span> <span class="line"><span style="color:#D43324">var</span><span style="color:#222222"> iMeantToDoThis = </span><span style="color:#11796D">0</span><span style="color:#222222"> / </span><span style="color:#11796D">0</span><span style="color:#222222">;</span></span> <span class="line"><span style="color:#D43324">assert</span><span style="color:#222222">(iMeantToDoThis.isNaN);</span></span></code></pre></div></div><div class="header-wrapper"><h2 id="runes-and-grapheme-clusters">Runes and grapheme clusters</h2><a class="heading-link" href="#runes-and-grapheme-clusters" aria-label="Link to 'Runes and grapheme clusters' section">#</a></div><p>In Dart, <a href="https://api.dart.dev/dart-core/Runes-class.html">runes</a> expose the Unicode code points of a string. You can use the <a href="https://pub.dev/packages/characters">characters package</a> to view or manipulate user-perceived characters, also known as <a href="https://unicode.org/reports/tr29/#Grapheme_Cluster_Boundaries">Unicode (extended) grapheme clusters.</a></p><p>Unicode defines a unique numeric value for each letter, digit, and symbol used in all of the world's writing systems. Because a Dart string is a sequence of UTF-16 code units, expressing Unicode code points within a string requires special syntax. The usual way to express a Unicode code point is <code>\uXXXX</code>, where XXXX is a 4-digit hexadecimal value. For example, the heart character (♥) is <code>\u2665</code>. To specify more or less than 4 hex digits, place the value in curly brackets. For example, the laughing emoji (😆) is <code>\u{1f606}</code>.</p><p>If you need to read or write individual Unicode characters, use the <code>characters</code> getter defined on String by the characters package. The returned <a href="https://pub.dev/documentation/characters/latest/characters/Characters-class.html"><code>Characters</code></a> object is the string as a sequence of grapheme clusters. Here's an example of using the characters API:</p> <?code-excerpt "misc/lib/language_tour/characters.dart"?> <div class="code-block-wrapper language-dart"><div class="code-block-body"><span class="code-block-language" title="Language dart">dart</span><pre class="shiki dash-light" tabindex="0"><code><span class="line"><span style="color:#D43324">import</span><span style="color:#11796D"> 'package:characters/characters.dart'</span><span style="color:#222222">;</span></span> <span class="line"></span> <span class="line"><span style="color:#D43324">void</span><span style="color:#6200EE"> main</span><span style="color:#222222">() {</span></span> <span class="line"><span style="color:#D43324"> var</span><span style="color:#222222"> hi = </span><span style="color:#11796D">'Hi 🇩🇰'</span><span style="color:#222222">;</span></span> <span class="line"><span style="color:#6200EE"> print</span><span style="color:#222222">(hi);</span></span> <span class="line"><span style="color:#6200EE"> print</span><span style="color:#222222">(</span><span style="color:#11796D">'The end of the string: </span><span style="color:#11796D">${</span><span style="color:#222222">hi</span><span style="color:#11796D">.</span><span style="color:#6200EE">substring</span><span style="color:#11796D">(</span><span style="color:#222222">hi</span><span style="color:#11796D">.</span><span style="color:#222222">length</span><span style="color:#11796D"> - 1)}</span><span style="color:#11796D">'</span><span style="color:#222222">);</span></span> <span class="line"><span style="color:#6200EE"> print</span><span style="color:#222222">(</span><span style="color:#11796D">'The last character: </span><span style="color:#11796D">${</span><span style="color:#222222">hi</span><span style="color:#11796D">.</span><span style="color:#222222">characters</span><span style="color:#11796D">.</span><span style="color:#222222">last</span><span style="color:#11796D">}</span><span style="color:#11796D">'</span><span style="color:#222222">);</span></span> <span class="line"><span style="color:#222222">}</span></span></code></pre></div></div><p>The output, depending on your environment, looks something like this:</p><div class="code-block-wrapper language-console"><div class="code-block-body"><pre class="shiki dash-light" tabindex="0"><code><span class="line"><span style="color:#222222">$ dart run bin/main.dart</span></span> <span class="line"><span style="color:#222222">Hi 🇩🇰</span></span> <span class="line"><span style="color:#222222">The end of the string: ???</span></span> <span class="line"><span style="color:#222222">The last character: 🇩🇰</span></span></code></pre></div></div><p>For details on using the characters package to manipulate strings, see the <a href="https://pub.dev/packages/characters/example">example</a> and <a href="https://pub.dev/documentation/characters">API reference</a> for the characters package.</p><div class="header-wrapper"><h2 id="symbols">Symbols</h2><a class="heading-link" href="#symbols" aria-label="Link to 'Symbols' section">#</a></div><p>A <a href="https://api.dart.dev/dart-core/Symbol-class.html"><code>Symbol</code></a> object represents an operator or identifier declared in a Dart program. You might never need to use symbols, but they're invaluable for APIs that refer to identifiers by name, because minification changes identifier names but not identifier symbols.</p><p>To get the symbol for an identifier, use a symbol literal, which is just <code>#</code> followed by the identifier:</p><div class="code-block-wrapper language-plaintext"><div class="code-block-body"><pre class="shiki dash-light" tabindex="0"><code><span class="line"><span>#radix</span></span> <span class="line"><span>#bar</span></span></code></pre></div></div><p>Symbol literals are compile-time constants.</p><nav id="subnav"><ul><li class="previous"><a href="/language/keywords">⟨ Keywords</a></li><li class="next"><a href="/language/records">Records ⟩</a></li></ul></nav><p id="page-github-links"><span>Unless stated otherwise, the documentation on this site reflects Dart 3.5.4. Page last updated on 2024-11-17.</span> <a href="https://github.com/dart-lang/site-www/tree/main/src/content/language/built-in-types.md" target="_blank" rel="noopener">View source</a> <span>or </span><a href="https://github.com/dart-lang/site-www/issues/new?template=1_page_issue.yml&page-url=https://dart.dev/language/built-in-types/&page-source=https://github.com/dart-lang/site-www/tree/main/src/content/language/built-in-types.md" title="Report an issue with this page" target="_blank" rel="noopener">report an issue</a>.</p></div></article></main><footer id="page-footer"><div class="footer-section footer-main"><a href="/" class="brand" title="Dart"><img src="/assets/img/logo/logo-white-text.svg" alt="Dart" width="164"></a><div class="footer-social-links"><a href="https://medium.com/dartlang" target="_blank" rel="noopener" title="Medium blog"><svg><use href="/assets/img/social/medium.svg#medium"></use></svg> </a><a href="https://github.com/dart-lang" target="_blank" rel="noopener" title="GitHub"><svg><use href="/assets/img/social/github.svg#github"></use></svg> </a><a href="https://twitter.com/dart_lang" target="_blank" rel="noopener" title="X (Twitter)"><svg><use href="/assets/img/social/x.svg#x"></use></svg></a></div></div><div class="footer-section footer-tray"><div class="footer-licenses">Except as otherwise noted, this site is licensed under a <a href="https://creativecommons.org/licenses/by/4.0/">Creative Commons Attribution 4.0 International License</a>, and code samples are licensed under the <a href="https://opensource.org/licenses/BSD-3-Clause">3-Clause BSD License</a>.</div><div class="footer-utility-links"><ul><li><a href="/terms" title="Terms of use">Terms</a></li><li><a href="https://policies.google.com/privacy" target="_blank" rel="noopener" title="Privacy policy">Privacy</a></li><li><a href="/security" title="Security philosophy and practices">Security</a></li></ul></div></div></footer></body></html>