CINXE.COM

dart:developer library - Dart API

<!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, height=device-height, initial-scale=1, user-scalable=no"> <meta name="description" content="dart:developer library API docs, for the Dart programming language."> <title>dart:developer library - Dart API</title> <link rel="canonical" href="https://api.dart.dev/dart-developer"> <link rel="preconnect" href="https://fonts.gstatic.com"> <link href="https://fonts.googleapis.com/css2?family=Roboto+Mono:ital,wght@0,300;0,400;0,500;0,700;1,400&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="../static-assets/github.css?v1"> <link rel="stylesheet" href="../static-assets/styles.css?v1"> <link rel="icon" href="../static-assets/favicon.png?v1"> <!-- Google tag (gtag.js) --> <script async src="https://www.googletagmanager.com/gtag/js?id=G-VVQ8908SJ5"></script> <script> window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag('js', new Date()); gtag('config', 'G-VVQ8908SJ5'); </script> <link rel="preconnect" href="https://fonts.googleapis.com"> <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin> <link rel="preload" href="https://fonts.googleapis.com/css2?family=Google+Sans+Text:wght@400&family=Google+Sans:wght@500&display=swap" as="style"> <link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Google+Sans+Text:wght@400&family=Google+Sans:wght@500&display=swap"> <link rel="stylesheet" href="https://www.gstatic.com/glue/cookienotificationbar/cookienotificationbar.min.css"> </head> <body data-base-href="../" data-using-base-href="false" class="light-theme"> <div id="overlay-under-drawer"></div> <header id="title"> <span id="sidenav-left-toggle" class="material-symbols-outlined" role="button" tabindex="0">menu</span> <ol class="breadcrumbs gt-separated dark hidden-xs"> <li><a href="../index.html">Dart</a></li> <li class="self-crumb">dart:developer</li> </ol> <div class="self-name">dart:developer</div> <form class="search navbar-right" role="search"> <input type="text" id="search-box" autocomplete="off" disabled class="form-control typeahead" placeholder="Loading search..."> </form> <div class="toggle" id="theme-button" title="Toggle brightness"> <label for="theme"> <input type="checkbox" id="theme" value="light-theme"> <span id="dark-theme-button" class="material-symbols-outlined"> dark_mode </span> <span id="light-theme-button" class="material-symbols-outlined"> light_mode </span> </label> </div> </header> <main> <div id="dartdoc-main-content" class="main-content" data-above-sidebar="" data-below-sidebar="dart-developer&#47;dart-developer-library-sidebar.html"> <div> <div id="external-links" class="btn-group"><a title="View source code" class="source-link" href="https://github.com/dart-lang/sdk/blob/9594995093f642957b780603c6435d9e7a61b923/sdk/lib/developer/developer.dart#L74"><span class="material-symbols-outlined">description</span></a></div> <h1> <span class="kind-library">dart:developer</span> library </h1> </div> <section class="desc markdown"> <p>Interact with developer tools such as the debugger and inspector.</p> <p>This is a specialized library intended for interacting with the Dart runtime programmatically for debugging and inspection. Sample uses include advanced debugging, and creating developer tools.</p> <p>This library has platform specific implementations for Dart web and Dart Native (VM). A specific platform may not support all operations.</p> <p>The functionality provided by this library is generally only available to Dart code run in development mode, e.g., <code>dart run</code>, and not in production mode, e.g., the output of <code>dart compile exe</code>.</p> <h2 id="debugging">Debugging</h2> <p>The <a href="../dart-developer/debugger.html">debugger</a> function can be used to stop the program as if a breakpoint was hit. The breakpoint will be placed right after the call to <code>debugger</code>. This functionality can be useful for triggering breakpoints based on logic in the code.</p> <p>Example:</p> <pre class="language-dart"><code class="language-dart">var counter = 0; final someInterestingValue = 1000; while (true) { if (counter == someInterestingValue) { // Trigger a breakpoint in the the debugger. debugger(); } counter++; } </code></pre> <p>When executed with <code>dart run --observe</code>, and opened in DevTools, the debugger will be stopped with <code>counter</code> at the value <code>1000</code>.</p> <h2 id="inspection">Inspection</h2> <p>Developer tools, such as Dart DevTools, connected to the runtime system may allow for inspecting execution timing in a "timeline" view. The static methods of <a href="../dart-developer/Timeline-class.html">Timeline</a> can add extra information and timing events to this view.</p> <p>Example:</p> <pre class="language-dart"><code class="language-dart">void main() { Timeline.timeSync('Calculation loop', () { for (var i = 30; i &lt; 50; i++) { Timeline.timeSync('fib($i)', () { fibonacci(i); }); } }); } int fibonacci(int n) =&gt; (n &lt; 2) ? n : fibonacci(n - 2) + fibonacci(n - 1); </code></pre> <p>When executed with <code>dart run --observe</code>, and opened in DevTools, the Performance tab will display a timeline containing the annotations passed to <code>timeSync</code>.</p> <h2 id="developer-tools">Developer tools</h2> <p>A developer tool, like the debugger built into the <code>dart</code> command, may access information about the running application exposed by the runtime system, using the <a href="../dart-developer/Service-class.html">Service</a> and <a href="../dart-developer/ServiceProtocolInfo-class.html">ServiceProtocolInfo</a> classes.</p> </section> <section class="summary offset-anchor" id="classes"> <h2>Classes</h2> <dl> <dt id="Flow"> <span class="name "><a href="../dart-developer/Flow-class.html">Flow</a></span> </dt> <dd> A class to represent Flow events. </dd> <dt id="NativeRuntime"> <span class="name "><a href="../dart-developer/NativeRuntime-class.html">NativeRuntime</a></span> </dt> <dd> Functionality available on the native runtime. </dd> <dt id="Service"> <span class="name "><a href="../dart-developer/Service-class.html">Service</a></span> </dt> <dd> Access information about the service protocol and control the web server that provides access to the services provided by the Dart VM for debugging and inspecting Dart programs. </dd> <dt id="ServiceExtensionResponse"> <span class="name "><a href="../dart-developer/ServiceExtensionResponse-class.html">ServiceExtensionResponse</a></span> </dt> <dd> A response to a service protocol extension RPC. </dd> <dt id="ServiceProtocolInfo"> <span class="name "><a href="../dart-developer/ServiceProtocolInfo-class.html">ServiceProtocolInfo</a></span> </dt> <dd> Service protocol is the protocol that a client like the Observatory could use to access the services provided by the Dart VM for debugging and inspecting Dart programs. This class encapsulates the version number and Uri for accessing this service. </dd> <dt id="Timeline"> <span class="name "><a href="../dart-developer/Timeline-class.html">Timeline</a></span> </dt> <dd> Add to the timeline. </dd> <dt id="TimelineTask"> <span class="name "><a href="../dart-developer/TimelineTask-class.html">TimelineTask</a></span> </dt> <dd> An asynchronous task on the timeline. An asynchronous task can have many (nested) synchronous operations. Synchronous operations can live longer than the current isolate event. To pass a <a href="../dart-developer/TimelineTask-class.html">TimelineTask</a> to another isolate, you must first call <a href="../dart-developer/TimelineTask/pass.html">pass</a> to get the task id and then construct a new <a href="../dart-developer/TimelineTask-class.html">TimelineTask</a> in the other isolate. </dd> <dt id="UserTag"> <span class="name "><a href="../dart-developer/UserTag-class.html">UserTag</a></span> </dt> <dd> A UserTag can be used to group samples in the <a href="https://docs.flutter.dev/tools/devtools/cpu-profiler">DevTools CPU profiler</a>. </dd> </dl> </section> <section class="summary offset-anchor" id="properties"> <h2>Properties</h2> <dl class="properties"> <dt id="extensionStreamHasListener" class="property"> <span class="name"><a href="../dart-developer/extensionStreamHasListener.html">extensionStreamHasListener</a></span> <span class="signature">&#8594; <a href="../dart-core/bool-class.html">bool</a></span> </dt> <dd> Whether the "Extension" stream currently has at least one listener. <div class="features"><span class="feature">no setter</span></div> </dd> <dt id="reachabilityBarrier" class="property"> <span class="name"><a href="../dart-developer/reachabilityBarrier.html">reachabilityBarrier</a></span> <span class="signature">&#8594; <a href="../dart-core/int-class.html">int</a></span> </dt> <dd> Current reachability barrier state. <div class="features"><span class="feature">no setter</span></div> </dd> </dl> </section> <section class="summary offset-anchor" id="functions"> <h2>Functions</h2> <dl class="callables"> <dt id="addHttpClientProfilingData" class="callable"> <span class="name"><a href="../dart-developer/addHttpClientProfilingData.html">addHttpClientProfilingData</a></span><span class="signature">(<wbr><span class="parameter" id="addHttpClientProfilingData-param-requestProfile"><span class="type-annotation"><a href="../dart-core/Map-class.html">Map</a><span class="signature">&lt;<wbr><span class="type-parameter"><a href="../dart-core/String-class.html">String</a></span>, <span class="type-parameter">dynamic</span>&gt;</span></span> <span class="parameter-name">requestProfile</span></span>) <span class="returntype parameter">&#8594; void</span> </span> </dt> <dd> Records the data associated with an HTTP request for profiling purposes. </dd> <dt id="debugger" class="callable"> <span class="name"><a href="../dart-developer/debugger.html">debugger</a></span><span class="signature">(<wbr>{<span class="parameter" id="debugger-param-when"><span class="type-annotation"><a href="../dart-core/bool-class.html">bool</a></span> <span class="parameter-name">when</span> = <span class="default-value">true</span>, </span><span class="parameter" id="debugger-param-message"><span class="type-annotation"><a href="../dart-core/String-class.html">String</a>?</span> <span class="parameter-name">message</span></span>}) <span class="returntype parameter">&#8594; <a href="../dart-core/bool-class.html">bool</a></span> </span> </dt> <dd> If <code>when</code> is true, stop the program as if a breakpoint were hit at the following statement. </dd> <dt id="getCurrentTag" class="callable"> <span class="name"><a href="../dart-developer/getCurrentTag.html">getCurrentTag</a></span><span class="signature">(<wbr>) <span class="returntype parameter">&#8594; <a href="../dart-developer/UserTag-class.html">UserTag</a></span> </span> </dt> <dd> Returns the current <a href="../dart-developer/UserTag-class.html">UserTag</a> for the isolate. </dd> <dt id="getHttpClientProfilingData" class="callable"> <span class="name"><a href="../dart-developer/getHttpClientProfilingData.html">getHttpClientProfilingData</a></span><span class="signature">(<wbr>) <span class="returntype parameter">&#8594; <a href="../dart-core/List-class.html">List</a><span class="signature">&lt;<wbr><span class="type-parameter"><a href="../dart-core/Map-class.html">Map</a><span class="signature">&lt;<wbr><span class="type-parameter"><a href="../dart-core/String-class.html">String</a></span>, <span class="type-parameter">dynamic</span>&gt;</span></span>&gt;</span></span> </span> </dt> <dd> Returns the data added through <a href="../dart-developer/addHttpClientProfilingData.html">addHttpClientProfilingData</a>. </dd> <dt id="inspect" class="callable"> <span class="name"><a href="../dart-developer/inspect.html">inspect</a></span><span class="signature">(<wbr><span class="parameter" id="inspect-param-object"><span class="type-annotation"><a href="../dart-core/Object-class.html">Object</a>?</span> <span class="parameter-name">object</span></span>) <span class="returntype parameter">&#8594; <a href="../dart-core/Object-class.html">Object</a>?</span> </span> </dt> <dd> Send a reference to <code>object</code> to any attached debuggers. </dd> <dt id="log" class="callable"> <span class="name"><a href="../dart-developer/log.html">log</a></span><span class="signature">(<wbr><span class="parameter" id="log-param-message"><span class="type-annotation"><a href="../dart-core/String-class.html">String</a></span> <span class="parameter-name">message</span>, {</span><span class="parameter" id="log-param-time"><span class="type-annotation"><a href="../dart-core/DateTime-class.html">DateTime</a>?</span> <span class="parameter-name">time</span>, </span><span class="parameter" id="log-param-sequenceNumber"><span class="type-annotation"><a href="../dart-core/int-class.html">int</a>?</span> <span class="parameter-name">sequenceNumber</span>, </span><span class="parameter" id="log-param-level"><span class="type-annotation"><a href="../dart-core/int-class.html">int</a></span> <span class="parameter-name">level</span> = <span class="default-value">0</span>, </span><span class="parameter" id="log-param-name"><span class="type-annotation"><a href="../dart-core/String-class.html">String</a></span> <span class="parameter-name">name</span> = <span class="default-value">&#39;&#39;</span>, </span><span class="parameter" id="log-param-zone"><span class="type-annotation"><a href="../dart-async/Zone-class.html">Zone</a>?</span> <span class="parameter-name">zone</span>, </span><span class="parameter" id="log-param-error"><span class="type-annotation"><a href="../dart-core/Object-class.html">Object</a>?</span> <span class="parameter-name">error</span>, </span><span class="parameter" id="log-param-stackTrace"><span class="type-annotation"><a href="../dart-core/StackTrace-class.html">StackTrace</a>?</span> <span class="parameter-name">stackTrace</span></span>}) <span class="returntype parameter">&#8594; void</span> </span> </dt> <dd> Emit a log event. </dd> <dt id="postEvent" class="callable"> <span class="name"><a href="../dart-developer/postEvent.html">postEvent</a></span><span class="signature">(<wbr><span class="parameter" id="postEvent-param-eventKind"><span class="type-annotation"><a href="../dart-core/String-class.html">String</a></span> <span class="parameter-name">eventKind</span>, </span><span class="parameter" id="postEvent-param-eventData"><span class="type-annotation"><a href="../dart-core/Map-class.html">Map</a></span> <span class="parameter-name">eventData</span>, {</span><span class="parameter" id="postEvent-param-stream"><span class="type-annotation"><a href="../dart-core/String-class.html">String</a></span> <span class="parameter-name">stream</span> = <span class="default-value">&#39;Extension&#39;</span></span>}) <span class="returntype parameter">&#8594; void</span> </span> </dt> <dd> Post an event of <code>eventKind</code> with payload of <code>eventData</code> to the "Extension" event stream. </dd> <dt id="registerExtension" class="callable"> <span class="name"><a href="../dart-developer/registerExtension.html">registerExtension</a></span><span class="signature">(<wbr><span class="parameter" id="registerExtension-param-method"><span class="type-annotation"><a href="../dart-core/String-class.html">String</a></span> <span class="parameter-name">method</span>, </span><span class="parameter" id="registerExtension-param-handler"><span class="type-annotation"><a href="../dart-developer/ServiceExtensionHandler.html">ServiceExtensionHandler</a></span> <span class="parameter-name">handler</span></span>) <span class="returntype parameter">&#8594; void</span> </span> </dt> <dd> Register a <a href="../dart-developer/ServiceExtensionHandler.html">ServiceExtensionHandler</a> that will be invoked in this isolate for <code>method</code>. <em>NOTE</em>: Service protocol extensions must be registered in each isolate. </dd> </dl> </section> <section class="summary offset-anchor" id="typedefs"> <h2>Typedefs</h2> <dl> <dt id="ServiceExtensionHandler" class="callable"> <span class="name"><a href="../dart-developer/ServiceExtensionHandler.html">ServiceExtensionHandler</a></span><span class="signature"> <span class="returntype parameter">= <a href="../dart-async/Future-class.html">Future</a><span class="signature">&lt;<wbr><span class="type-parameter"><a href="../dart-developer/ServiceExtensionResponse-class.html">ServiceExtensionResponse</a></span>&gt;</span> Function<span class="signature">(<span class="parameter" id="ServiceExtensionHandler-param-method"><span class="type-annotation"><a href="../dart-core/String-class.html">String</a></span> <span class="parameter-name">method</span>, </span><span class="parameter" id="ServiceExtensionHandler-param-parameters"><span class="type-annotation"><a href="../dart-core/Map-class.html">Map</a><span class="signature">&lt;<wbr><span class="type-parameter"><a href="../dart-core/String-class.html">String</a></span>, <span class="type-parameter"><a href="../dart-core/String-class.html">String</a></span>&gt;</span></span> <span class="parameter-name">parameters</span></span>)</span></span> </span> </dt> <dd> A service protocol extension handler. Registered with <a href="../dart-developer/registerExtension.html">registerExtension</a>. </dd> <dt id="TimelineAsyncFunction" class="callable"> <span class="name"><a href="../dart-developer/TimelineAsyncFunction.html">TimelineAsyncFunction</a></span><span class="signature"> <span class="returntype parameter">= <a href="../dart-async/Future-class.html">Future</a> Function<span class="signature">()</span></span> </span> </dt> <dd> </dd> <dt id="TimelineSyncFunction" class="callable"> <span class="name"><a href="../dart-developer/TimelineSyncFunction.html">TimelineSyncFunction</a></span>&lt;<wbr><span class="type-parameter">T</span>&gt;<span class="signature"> <span class="returntype parameter">= T Function<span class="signature">()</span></span> </span> </dt> <dd> A typedef for the function argument to <a href="../dart-developer/Timeline/timeSync.html">Timeline.timeSync</a>. </dd> </dl> </section> </div> <!-- /.main-content --> <div id="dartdoc-sidebar-left" class="sidebar sidebar-offcanvas-left"> <!-- The search input and breadcrumbs below are only responsively visible at low resolutions. --> <header id="header-search-sidebar" class="hidden-l"> <form class="search-sidebar" role="search"> <input type="text" id="search-sidebar" autocomplete="off" disabled class="form-control typeahead" placeholder="Loading search..."> </form> </header> <ol class="breadcrumbs gt-separated dark hidden-l" id="sidebar-nav"> <li><a href="../index.html">Dart</a></li> <li class="self-crumb">dart:developer</li> </ol> <h5><span class="package-name">Dart</span> <span class="package-kind">SDK</span></h5> <ol> <li class="section-title">Libraries</li> <li class="section-subtitle">Core</li> <li class="section-subitem"><a href="../dart-async">dart:async</a></li> <li class="section-subitem"><a href="../dart-collection">dart:collection</a></li> <li class="section-subitem"><a href="../dart-convert">dart:convert</a></li> <li class="section-subitem"><a href="../dart-core">dart:core</a></li> <li class="section-subitem"><a href="../dart-developer">dart:developer</a></li> <li class="section-subitem"><a href="../dart-math">dart:math</a></li> <li class="section-subitem"><a href="../dart-typed_data">dart:typed_data</a></li> <li class="section-subtitle">VM</li> <li class="section-subitem"><a href="../dart-ffi">dart:ffi</a></li> <li class="section-subitem"><a href="../dart-io">dart:io</a></li> <li class="section-subitem"><a href="../dart-isolate">dart:isolate</a></li> <li class="section-subitem"><a href="../dart-mirrors">dart:mirrors</a></li> <li class="section-subtitle">Web</li> <li class="section-subitem"> <a href="https:&#47;&#47;pub.dev&#47;documentation&#47;web&#47;latest&#47;" target="_blank"> package:web <span class="material-symbols-outlined">open_in_new</span> </a> </li> <li class="section-subitem"><a href="../dart-js_interop">dart:js_interop</a></li> <li class="section-subitem"><a href="../dart-js_interop_unsafe">dart:js_interop_unsafe</a></li> <li class="section-subtitle">Web (Legacy)</li> <li class="section-subitem"><a class="deprecated" href="../dart-html">dart:html</a></li> <li class="section-subitem"><a class="deprecated" href="../dart-indexed_db">dart:indexed_db</a></li> <li class="section-subitem"><a class="deprecated" href="../dart-js">dart:js</a></li> <li class="section-subitem"><a class="deprecated" href="../dart-js_util">dart:js_util</a></li> <li class="section-subitem"><a class="deprecated" href="../dart-svg">dart:svg</a></li> <li class="section-subitem"><a class="deprecated" href="../dart-web_audio">dart:web_audio</a></li> <li class="section-subitem"><a class="deprecated" href="../dart-web_gl">dart:web_gl</a></li> </ol> </div> <div id="dartdoc-sidebar-right" class="sidebar sidebar-offcanvas-right"> <h5>dart:developer library</h5> </div><!--/sidebar-offcanvas-right--> </main> <footer> <span class="no-break"> Dart 3.7.2 </span> <span class="glue-footer"> <span class="no-break"> | <a href="https://dart.dev/terms" title="Terms of use">Terms</a> </span> <span class="no-break"> | <a href="https://policies.google.com/privacy" target="_blank" rel="noopener" title="Privacy policy" class="no-automatic-external">Privacy</a> </span> <span class="no-break"> | <a href="https://dart.dev/security" title="Security philosophy and practices">Security</a> </span> <div class="copyright" style="font-size: 0.9em; color: darkgrey; margin-top: 0.5em;"> Except as otherwise noted, this site is licensed under a <a style="color: darkgrey;" href="https://creativecommons.org/licenses/by/4.0/"> Creative Commons Attribution 4.0 International License</a> and code samples are licensed under the <a style="color: darkgrey;" href="https://opensource.org/licenses/BSD-3-Clause" class="no-automatic-external"> 3-Clause BSD License</a> </div> </span> </footer> <script src="../static-assets/highlight.pack.js?v1"></script> <script src="../static-assets/docs.dart.js"></script> <button aria-hidden="true" class="glue-footer__link glue-cookie-notification-bar-control"> Cookies management controls </button> <script src="https://www.gstatic.com/glue/cookienotificationbar/cookienotificationbar.min.js" data-glue-cookie-notification-bar-category="2B"> </script> </body> </html>

Pages: 1 2 3 4 5 6 7 8 9 10