dart: URI scheme to reference built-in libraries provided directly by the Dart SDK. These libraries are distinct from package imports (package:) and relative file imports, as they are resolved by the Dart compiler or runtime environment without requiring external dependencies in pubspec.yaml.
Syntax and Placement
Import directives must appear at the top of the Dart file. They must follow anylibrary directives but strictly precede part directives and all top-level code declarations.
Implicit Imports
Thedart:core library is implicitly imported into every Dart program. This library exposes fundamental types (e.g., int, String, List, Map) and basic utilities (e.g., print). Explicitly importing dart:core is redundant.
Namespace Management
Core library imports support standard namespace modifiers to handle naming conflicts or limit scope. Prefixing Assigns an alias to the library to avoid identifier collisions.show (inclusion) or hide (exclusion).
Platform Specificity
While many core libraries are multi-platform, specific libraries are restricted to certain compilation targets or have varying support depending on the backend (Native, JavaScript, or Wasm).- Universal: Libraries such as
dart:async,dart:collection,dart:convert, anddart:mathare available on all supported Dart targets. - Native (VM/AOT): The
dart:iolibrary provides I/O APIs (files, sockets, HTTP servers) and is strictly available only when running on the Dart VM or compiled to native machine code. It is not supported on the web. - Web:
- Legacy: Libraries such as
dart:htmlanddart:indexed_dbare available only when compiling to JavaScript. - Modern Interop:
dart:js_interopis available for both JavaScript and WebAssembly (Wasm) targets.
- Legacy: Libraries such as
- Cross-Platform with Constraints:
dart:isolate: Supported on Native and Web (both JS and Wasm), though implementation details (such as concurrency models) differ between the VM and the Web.dart:ffi: Supported on Native and Web (Wasm only). It is not supported when compiling to JavaScript.
Conditional Imports
The import directive supports configuration-specific logic to import different libraries based on the compilation target. This is achieved using theif keyword followed by a library condition (e.g., dart.library.io or dart.library.js_interop).
Requirement for Shared Interfaces
When using conditional imports, all potential import targets must expose the exact same API (classes, methods, and properties) used by the consuming code. If the APIs differ, the code will fail static analysis.
Master Dart with Deep Grasping Methodology!Learn More





