Dart Documentation Site Source

repository·main·Indexed 21 days ago

https://github.com/dart-lang/site-www

Source code and content for the official Dart programming language documentation site (dart.dev). Built with the Jaspr framework and hosted on Firebase, the repository includes the dash_site CLI tool for local development, site validation, and code excerpt synchronization. It also contains the Effective Dart style, documentation, usage, and design guidelines.

Tokens
245.5K
Snippets
837
Records
1.2K
Agent score
75%

What's inside dart-lang-site-www

  1. Overview of JavaScript interoperability in Dart

    main

    Dart provides tools to call JavaScript from Dart and vice-versa, allowing you to leverage the JavaScript ecosystem within your Dart web applications.

    Key resources for JS interop include:

    • Getting Started: Guides for initial setup and mocking JS interop objects.
    • Reference Guides: Detailed documentation on usage patterns and JS types.
    • Browser Interaction: Using package:web to interact with browser APIs.
    • Modern API: The dart:js_interop library is the current standard for interoperability.
  2. Introduction to dart:async

    main

    The dart:async library provides core primitives for asynchronous programming in Dart, specifically Future and Stream objects.

    • Future: Represents a single value that will be available at some point in the future (similar to a Promise).
    • Stream: Represents a sequence of asynchronous events or values.

    While you can import dart:async to access these APIs, you do not strictly need to import it to use Future or Stream because they are exported by dart:core.

    import 'dart:async';
  3. Use dart:ffi for C interop

    main

    Dart mobile, command-line, and server apps running on the Dart Native platform can use the dart:ffi library to call native C APIs and manage native memory (read, write, allocate, and deallocate). FFI stands for Foreign Function Interface.

    Key capabilities:

    • Call native C functions.
    • Read, write, allocate, and deallocate native memory.
    • Interface with native types.
  4. Use package:jnigen for Java and Kotlin interop

    main

    Dart mobile, command-line, and server apps running on the Dart Native platform (Android, Windows, macOS, and Linux) can call Java and Kotlin APIs using package:jni and package:jnigen.

    • package:jni: Allows Dart code to interact with Java via JNI.
    • package:jnigen: Automatically generates Dart bindings for a given Java/Kotlin API to reduce boilerplate.

    Note: This feature is currently experimental.

  5. Explore Dart usage in Google products

    main

    Dart is used extensively across Google's product groups. Key examples include:

    • Google Play Console: Written completely in Dart.
    • Google Ads: Large-scale development primarily using Dart.
    • Google Assistant: Uses Flutter and Dart for Smart Display system UI.
    • Google Nest Hub & Hub Max: Both UI and much of the back-end code are written in Dart.
    • Other services: Google Pay, Google One, Google Fibre, Google Elections, Google Shopping, Cloud Search, and Family Link.
  6. Secure Dart packages using GitHub security features

    main

    GitHub now provides comprehensive supply chain security for Dart and Flutter applications through integration with the Dart ecosystem. This includes support in the GitHub Advisory Database, the dependency graph, and Dependabot.

    Key Features:

    • Dependabot: Automatically monitors your pubspec.yaml dependencies. If a vulnerability is found or an update is available, Dependabot can submit a pull request to update your pubspec.yaml to the latest secure version.
    • Dependency Graph: Visualizes the set of dependencies used by your Dart package.
    • GitHub Advisory Database: A central database of known vulnerabilities. When creating a new advisory, you can now select the Pub ecosystem to ensure it is correctly categorized for Dart packages.
  7. Summary of Dart extension method capabilities

    main

    Extension methods allow you to add functionality to existing types without modifying them.

    What you can define:

    • Instance methods
    • Operators
    • Setters
    • Getters

    What you CANNOT define:

    • Fields

    Invocation methods:

    • Implicit: list.bubbleSort() (Works when there is no conflict with interface members or other extensions).
    • Explicit: Ext1(list).bubbleSort() (Always works; behaves like a wrapper class).
  8. Manage and edit website diagrams

    main

    The diagrams/ directory contains the source files for images used throughout the dart.dev website. These files are provided in formats that allow for future editing, such as .graffle files (for OmniGraffle) and PNGs/SVGs (generated via diagrams.net).

    Important: Do NOT optimize images or vectors in this directory. These files contain specific metadata required by editors to enable subsequent edits. Optimizing them may strip this metadata and make the source files uneditable.

  9. Dart 3 release roadmap and milestones

    main

    The transition to Dart 3 follows a series of milestones designed to allow for compatibility testing and feature experimentation:

    • Dart 3 Alpha (approx. Jan/Feb 2023): Focuses on enabling early compatibility testing. Developers should use this phase to run static analysis (dart analyze or flutter analyze) to ensure their code is ready for the stable release.
    • Dart 3 Beta (approx. March/April 2023): Previews new features and allows for experimentation and community feedback.
    • Dart 3 Stable (approx. mid 2023): The official stable release where sound null safety becomes the only supported mode.
  10. Summary of the logging tutorial

    main

    This tutorial covers how to implement structured logging in a Dart CLI application using the logging package. Key concepts include:

    • The logging package: Provides Logger, Level, and LogRecord classes for structured logging with configurable severity levels.
    • Hierarchical Logging: Setting up loggers to output to specific destinations, such as timestamped files in a logs/ directory via a custom initFileLogger() function.
    • Dependency Injection: Passing a Logger instance to CLI commands to ensure consistent logging across the application.
    • Severity Levels: Using methods like logger.warning(), logger.severe(), and logger.info() to record events with appropriate context for easier debugging and filtering.
  11. Interop with Objective-C and Swift using package:ffigen

    main

    On Dart Native platforms (macOS or iOS), you can call Objective-C and Swift APIs from Dart using dart:ffi and package:ffigen.

    Objective-C Interop

    While dart:ffi allows direct interaction with C APIs (and thus Objective-C due to its C compatibility), doing so manually requires significant boilerplate. package:ffigen automates this by generating Dart FFI bindings directly from Objective-C headers.

    Swift Interop

    To interact with Swift APIs, you must first generate Objective-C wrapper headers for the Swift code. Once these headers are available, you can use dart:ffi and package:ffigen to generate the necessary Dart bindings.

  12. Effective Dart: Design guidelines for libraries

    main
    The Effective Dart: Design guidelines provide principles for writing consistent, usable, and intuitive APIs for Dart libraries. These guidelines focus on naming conventions and semantic clarity to ensure that developers can easily understand and interact with your library's surface area.