### Setup and run the example Source: https://github.com/dart-lang/site-www/blob/main/src/content/interop/java-interop.md Build the dynamic library and compile Java sources before running the application. ```console $ dart run jni:setup $ javac java/dev/dart/Example.java ``` ```console $ dart run jnigen_example:sum 17 25 ``` -------------------------------- ### Get help for dart install Source: https://github.com/dart-lang/site-www/blob/main/src/content/tools/dart-install.md Displays help information and available arguments for the dart install command. ```bash $ dart install --help ``` ```bash $ dart install -h ``` -------------------------------- ### Install Dart SDK using apt-get Source: https://github.com/dart-lang/site-www/blob/main/src/_includes/install/linux.md After setting up the repository and key, use this command to install the Dart SDK. This command also serves to upgrade the SDK if it's already installed. ```bash $ sudo apt-get update && sudo apt-get install dart ``` -------------------------------- ### Checkout Repository and Setup Dart SDK in GitHub Actions Source: https://github.com/dart-lang/site-www/blob/main/src/content/blog/announcing-dart-support-for-github-actions/index.md Checks out the repository code and uses the setup-dart action to download and install the Dart SDK, adding it to the PATH. ```yaml - uses: actions/checkout@v2 - uses: dart-lang/setup-dart@v1 ``` -------------------------------- ### Run example tests Source: https://github.com/dart-lang/site-www/blob/main/examples/README.md Commands to run VM and browser tests for a specific example directory. ```terminal $ cd examples/misc $ dart pub get $ dart test # Run VM tests $ dart test -p chrome # Run browser tests ``` -------------------------------- ### Install a pub.dev package Source: https://github.com/dart-lang/site-www/blob/main/src/content/tools/dart-install.md Installs a package directly from the pub.dev site. Simply provide the package name. ```bash $ dart install ``` ```bash $ dart install markdown ``` -------------------------------- ### Run analyzer on an example Source: https://github.com/dart-lang/site-www/blob/main/examples/README.md Commands to initialize dependencies and execute the Dart analyzer within a specific example directory. ```terminal $ cd examples/misc $ dart pub get $ dart analyze . ``` -------------------------------- ### Example of dart pub get execution Source: https://github.com/dart-lang/site-www/blob/main/src/content/tools/pub/cmd/pub-get.md This shows the typical output when running `dart pub get` successfully, indicating that dependencies are being resolved and fetched. ```console $ dart pub get Resolving dependencies... Got dependencies! ``` -------------------------------- ### Make HTTP GET Request Source: https://github.com/dart-lang/site-www/blob/main/src/content/blog/dart-2-18-objective-c-swift-interop/index.md Example of making an HTTP GET request using the configured client. This call is made after the client has been initialized. ```dart final response = await get( Uri.https( 'www.googleapis.com', '/books/v1/volumes', {'q': 'HTTP', 'maxResults': '40', 'printType': 'books'}, ), ); ``` -------------------------------- ### Install and Run Dart REPL Source: https://github.com/dart-lang/site-www/blob/main/src/content/blog/a-dart-repl-poc/index.md Use these commands to globally activate and run the dart_repl tool. Ensure you have Dart SDK installed. ```bash pub global activate dart_repl ``` ```bash pub global run dart_repl ``` -------------------------------- ### Install a general package Source: https://github.com/dart-lang/site-www/blob/main/src/content/tools/dart-install.md Installs all executables from a package's pubspec.yaml. Specify the package name and optionally a version constraint. ```bash $ dart install [arguments] [version-constraint] ``` ```bash $ dart install markdown ``` -------------------------------- ### Install Realm SDK Binaries Source: https://github.com/dart-lang/site-www/blob/main/src/content/blog/introducing-realm-for-dart-flutter/index.md Run the Realm SDK installer using `dart run realm_dart install`. This command detects your operating system and downloads the necessary Realm SDK binaries, which are compiled versions of the core C++ library. ```shell dart run realm_dart install ``` -------------------------------- ### Install a Git package Source: https://github.com/dart-lang/site-www/blob/main/src/content/tools/dart-install.md Installs a package from a Git repository URL. Pub expects the package in the repository root by default. ```bash $ dart install ``` ```bash $ dart install https://github.com/dart-lang/async_await.git ``` -------------------------------- ### Install Dart SDK via Homebrew Source: https://github.com/dart-lang/site-www/blob/main/src/_includes/install/macos.md Add the official tap and install the Dart SDK package. ```console $ brew tap dart-lang/dart ``` ```console $ brew install dart ``` -------------------------------- ### Check All Site Components Source: https://github.com/dart-lang/site-www/blob/main/README.md Run a comprehensive check on the documentation and example code to ensure it meets site standards. This command is particularly useful after making changes to code examples or documentation files. ```bash dart run dash_site check-all ``` -------------------------------- ### Install Dart SDK via Chocolatey Source: https://github.com/dart-lang/site-www/blob/main/src/_includes/install/windows.md Requires an elevated PowerShell prompt to execute the installation command. ```ps PS C:\> choco install dart-sdk ``` -------------------------------- ### Run analyzer and tests for all examples Source: https://github.com/dart-lang/site-www/blob/main/examples/README.md Execute the shell script to perform analysis and testing across all project examples. ```bash ./tool/analyze-and-test-examples.sh ``` -------------------------------- ### Dart install command reference Source: https://github.com/dart-lang/site-www/blob/main/src/content/tools/dart-install.md The base command for installing Dart packages. Supports various arguments for specifying packages and constraints. ```bash $ dart install [arguments] [version-constraint] ``` -------------------------------- ### Specify custom hosted URL Source: https://github.com/dart-lang/site-www/blob/main/src/content/tools/dart-install.md Installs a package from a custom pub server URL using the --hosted-url option. This is applicable when installing by package name. ```bash $ dart install --hosted-url ``` ```bash $ dart install --hosted-url https://dart-packages.example.com/ ``` -------------------------------- ### Runnable example: Summing a stream Source: https://github.com/dart-lang/site-www/blob/main/src/content/libraries/async/using-streams.md This DartPad example demonstrates summing a stream of integers. It includes a stream generator function 'countStream' and the 'sumStream' function. ```dart Future sumStream(Stream stream) async { var sum = 0; await for (final value in stream) { sum += value; } return sum; } Stream countStream(int to) async* { for (int i = 1; i <= to; i++) { yield i; } } void main() async { var stream = countStream(10); var sum = await sumStream(stream); print(sum); // 55 } ``` -------------------------------- ### Example Search Results on Pub Site Source: https://github.com/dart-lang/site-www/blob/main/src/content/blog/getting-ready-for-dart-2-and-making-your-packages-look-great-on-the-pub-site/index.md Demonstrates how search results on the Pub site now include API documentation, providing more comprehensive results beyond package descriptions and README files. This example shows results for a search query related to ISO 4217 currency formatting. ```text 10 results for 4217 intl Contains code to deal with internationalized/localized messages, date and number formatting and parsing, bi-directional text, and other internationalization issues. v 0.15.2 • Updated: Oct 19, 2017 FLUTTER WEB OTHER API results: intl/NumberFormat-class.html flutter_billing A flutter plugin to communicate with billing on iOS and Android. v 0.1.2 • Updated: Feb 10, 2018 FLUTTER API results: flutter_billing/BillingProduct-class.html ``` -------------------------------- ### Declarative UI Construction Example (Java) Source: https://github.com/dart-lang/site-www/blob/main/src/content/blog/making-dart-a-better-language-for-ui/index.md Shows a more declarative, function-call-based way to construct UI elements, which is closer to modern UI frameworks than the purely imperative example. ```java p("I am an ", strong("exciting"), " paragraph!") ``` -------------------------------- ### Install Dart SDK as a Debian package Source: https://github.com/dart-lang/site-www/blob/main/src/_includes/install/linux.md Use this command to install the Dart SDK by directly providing the path to the downloaded .deb package file. Replace the filename with the current version. ```bash $ sudo dpkg -i dart_3.4.0-1_amd64.deb ``` -------------------------------- ### Example Dart Package Layout Source: https://github.com/dart-lang/site-www/blob/main/src/content/tools/pub/package-layout.md This illustrates a comprehensive package structure including directories for benchmarks, binaries, documentation, examples, tests, and source code. It also highlights key files like pubspec.yaml, LICENSE, README.md, and CHANGELOG.md. ```plaintext - enchilada/ - .dart_tool/ * - benchmark/ - make_lunch.dart - bin/ - enchilada - doc/ - api/ **** - getting_started.md - example/ - main.dart - hook/ - build.dart - integration_test/ - app_test.dart - lib/ - enchilada.dart - tortilla.dart - guacamole.css - src/ - beans.dart - queso.dart - test/ - enchilada_test.dart - tortilla_test.dart - tool/ - generate_docs.dart - web/ - index.html - main.dart - style.css - CHANGELOG.md - LICENSE - pubspec.yaml - pubspec_overrides.yaml ** - pubspec.lock *** - README.md ``` -------------------------------- ### Check all site code and links Source: https://github.com/dart-lang/site-www/wiki/Home Use this command to verify that code in the /examples and /tool directories is up to date and meets site standards. Address any reported errors or warnings. ```bash dart run dash_site check-all ``` -------------------------------- ### Basic HTTP Server Setup with Static Templating Source: https://github.com/dart-lang/site-www/blob/main/src/content/blog/building-data-binding-in-the-browser/index.md Demonstrates setting up a basic HTTP server in Dart that utilizes a static templating approach to serve content. ```dart import 'dart:io'; import 'package:static_templating/static_templating.dart'; main() async { final sundays = const [ 'sleep in', 'eat brunch', 'wash car', ]; ``` -------------------------------- ### Install Package with Specific Version Constraint Source: https://github.com/dart-lang/site-www/blob/main/src/content/tools/dart-install.md Use the `version-constraint` option to specify a particular version of a package. For example, to install version 0.6.0 of the `markdown` package. ```console dart install [version-constraint] ``` ```console dart install markdown 0.6.0 ``` -------------------------------- ### Get webdev Help Source: https://github.com/dart-lang/site-www/blob/main/src/content/tools/webdev.md Run this command to see all available webdev options. ```bash webdev --help ``` -------------------------------- ### Install Dependencies for Dart Project in GitHub Actions Source: https://github.com/dart-lang/site-www/blob/main/src/content/blog/announcing-dart-support-for-github-actions/index.md Installs project dependencies using 'dart pub get'. Ensure the Dart SDK is set up before running this step. ```yaml - name: Install dependencies run: dart pub get ``` -------------------------------- ### Avoid 'get' Prefix for Functions and Methods Source: https://github.com/dart-lang/site-www/blob/main/src/content/effective-dart/design.md Do not start function or method names with 'get'. If the member is a getter, remove 'get'. If it must be a method (e.g., due to arguments), use a noun phrase or a more specific verb like 'fetch' or 'calculate'. ```dart var breakfastOrder = getBreakfastOrder(); ``` -------------------------------- ### Run dash_site tool help Source: https://github.com/dart-lang/site-www/wiki/Home Execute this command to see available commands and options for the dash_site tool. ```bash dart run dash_site --help ``` -------------------------------- ### Get dependencies after adding a new one Source: https://github.com/dart-lang/site-www/blob/main/src/content/tools/pub/packages.md This example demonstrates the output of `dart pub get` after adding a new dependency (`retry: ^3.0.0`) to the `pubspec.yaml` file, showing the resolution and download process. ```bash $ dart pub get Resolving dependencies... (1.0s) Downloading packages... + retry 3.1.2 ``` -------------------------------- ### Use Generated Bindings for TimeZone Example Source: https://github.com/dart-lang/site-www/blob/main/src/content/blog/dart-2-18-objective-c-swift-interop/index.md Utilize the generated Dart bindings to interact with Objective-C APIs. This example shows how to get the local time zone and print its name and offset from GMT. ```dart void main(List args) async { const dylibPath = '/System/Library/Frameworks/Foundation.framework/Versions/Current/Foundation'; final lib = TimeZoneLibrary(DynamicLibrary.open(dylibPath)); final timeZone = NSTimeZone.getLocalTimeZone(lib); if (timeZone != null) { print('Timezone name: ${timeZone.name}'); print('Offset from GMT: ${timeZone.secondsFromGMT / 60 / 60} hours'); } } ``` -------------------------------- ### Run dash_site Tool Help Source: https://github.com/dart-lang/site-www/blob/main/README.md Execute the `dash_site` tool with the `--help` flag to view available commands and options. This is useful for understanding the site's build and development tooling. ```bash dart run dash_site --help ``` -------------------------------- ### Invoke Interop Instance Members Source: https://github.com/dart-lang/site-www/blob/main/src/content/interop/js-interop/usage.md Example usage of instance members to get and set properties on an interop object. ```dart final time = Time(0, 0); print(time.isDinnerTime()); // false final dinnerTime = Time.dinnerTime; time.hours = dinnerTime.hours; time.minutes = dinnerTime.minutes; print(time.isDinnerTime()); // true ``` -------------------------------- ### View help documentation Source: https://github.com/dart-lang/site-www/blob/main/src/content/tools/dart-test.md Displays available command-line options and flags for the test tool. ```console $ dart test --help ``` -------------------------------- ### Create collection with the right type Source: https://github.com/dart-lang/site-www/blob/main/src/content/effective-dart/usage.md Prefer creating collections with their intended type from the start to avoid the need for casting later. This example shows a correctly typed list being created. ```dart List singletonList(int value) { var list = []; list.add(value); return list; } ``` -------------------------------- ### Pubspec environment SDK constraint Source: https://github.com/dart-lang/site-www/blob/main/src/content/tools/pub/dependencies.md Define the required Dart SDK version using caret syntax in the pubspec.yaml file. This example requires a 3.x version starting with 3.2.0. ```yaml environment: # This package must use a 3.x version of the Dart SDK starting with 3.2. sdk: ^3.2.0 ``` -------------------------------- ### Serve Documentation Locally Source: https://github.com/dart-lang/site-www/wiki/Documentation-guide Execute this command in the terminal to serve the documentation project on your personal computer. Access it via http://localhost:4000/ in Chrome. ```bash ./dash_site serve ``` -------------------------------- ### Contraindicated Lint Example: always_specify_types Source: https://github.com/dart-lang/site-www/blob/main/src/content/blog/pedantic-dart/index.md This lint is not recommended for public use as it contradicts the Dart style guide by over-specifying types and negating type inference benefits. Do not use this lint. ```dart // always_specify_types; do not use; breaks with recommended style! var foo = 10; // LINT final bar = new Bar(); // LINT const quux = 20; // LINT ``` -------------------------------- ### Switch Expression Usage Examples Source: https://github.com/dart-lang/site-www/blob/main/src/content/language/branches.md Demonstrates how switch expressions can be used in various contexts where Dart allows expressions, such as variable assignments, print statements, and return statements. Note that switch expressions cannot start an expression statement. ```dart var x = switch (y) { ... }; print(switch (x) { ... }); return switch (x) { ... }; ``` -------------------------------- ### View dartaotruntime Help Source: https://github.com/dart-lang/site-www/blob/main/src/content/tools/dartaotruntime.md Use the `--help` flag with `dartaotruntime` to see all available command-line options. ```bash $ dartaotruntime --help ``` -------------------------------- ### dart installed Source: https://github.com/dart-lang/site-www/blob/main/src/content/tools/dart-install.md Lists all currently installed Dart CLI tool packages. ```APIDOC ## dart installed ### Description Checks which Dart CLI tool packages are currently installed. ### Method N/A (CLI Command) ### Endpoint N/A (CLI Command) ### Parameters None ### Request Example ```console $ dart installed ``` ### Response #### Success Response (200) A list of installed packages is displayed. #### Response Example (Output will vary based on installed packages. Example: `markdown`) ``` -------------------------------- ### List Installed Dart Versions Source: https://github.com/dart-lang/site-www/blob/main/src/_includes/install/macos.md Display information about installed Dart versions. ```console $ brew info dart ``` -------------------------------- ### Add multiple packages with different configurations Source: https://github.com/dart-lang/site-www/blob/main/src/content/tools/pub/cmd/pub-add.md Demonstrates adding multiple packages simultaneously, each with its own type (regular or dev) and version constraint. ```bash $ dart pub add foo dev:bar ``` -------------------------------- ### Redirect Example: Topic Renamed Source: https://github.com/dart-lang/site-www/wiki/Documentation-guide Example of how to define a redirect when a topic has been renamed. ```text # topic is renamed lang/if-elements.md => lang/if-and-for-elements.md ``` -------------------------------- ### Example Pubspec File Source: https://github.com/dart-lang/site-www/blob/main/src/content/tools/pub/pubspec.md A basic but complete pubspec.yaml file demonstrating essential fields like name, description, version, homepage, environment, dependencies, and dev_dependencies. ```yaml name: newtify description: >- Have you been turned into a newt? Would you like to be? This package can help. It has all of the newt-transmogrification functionality you have been looking for. version: 1.2.3 homepage: https://example-pet-store.com/newtify documentation: https://example-pet-store.com/newtify/docs environment: sdk: '^3.2.0' dependencies: efts: ^2.0.4 transmogrify: ^0.4.0 dev_dependencies: test: '>=1.15.0 <2.0.0' ``` -------------------------------- ### dart install Source: https://github.com/dart-lang/site-www/blob/main/src/content/tools/dart-install.md Installs a package for Dart CLI tools, making its executables available globally. ```APIDOC ## dart install ### Description Installs a package for Dart. This command installs all executables specified in a package's `pubspec.yaml` [executables][] section on the PATH. It is a newer alternative to `dart pub global activate`. ### Method N/A (CLI Command) ### Endpoint N/A (CLI Command) ### Parameters #### Path Parameters - **``** (string) - Required - The name of the package to install, a pub.dev package identifier, or a Git URL. - **`[version-constraint]`** (string) - Optional - Specifies the version of the package to install. #### Query Parameters None #### Request Body None ### Request Example ```console $ dart install markdown $ dart install https://github.com/dart-lang/async_await.git $ dart install ``` ### Response #### Success Response (200) Executables from the specified package are installed globally. #### Response Example (No specific response body is defined for CLI success, typically indicates completion without errors.) ### Options for `dart install` #### `--git-path` - **`--git-path`** (string) - Optional - Path of the git package within the repository. This only applies when using a git URL for ``. Example: `$ dart install https://github.com/dart-lang/http.git --git-path pkgs/http/` #### `--git-ref` - **`--git-ref`** (string) - Optional - The specific git branch or commit to retrieve. This only applies when using a git URL for ``. Example: `$ dart install https://github.com/dart-lang/http.git --git-ref 36f98e900347335af2338a0e087538009b7de2f9` #### `--overwrite` - **`--overwrite`** (boolean) - Optional - Allows overwriting executables from other packages that have the same name. Example: `$ dart install markdown --overwrite` #### `-u, --hosted-url` - **`-u, --hosted-url`** (string) - Optional - A custom pub server URL for the package. This only applies when using a package name for ``. Example: `$ dart install --hosted-url https://dart-packages.example.com/` #### `-h, --help` - **`-h, --help`** (boolean) - Optional - Displays help information for the `dart install` command. Example: `$ dart install --help` ``` -------------------------------- ### List installed Dart packages Source: https://github.com/dart-lang/site-www/blob/main/src/content/tools/dart-install.md Displays a list of all currently installed Dart CLI packages. ```bash $ dart installed ``` -------------------------------- ### View help documentation Source: https://github.com/dart-lang/site-www/blob/main/src/content/tools/dart-analyze.md Displays available command-line options for the analyzer. ```console $ dart analyze --help ``` -------------------------------- ### Switch Dart Versions Source: https://github.com/dart-lang/site-www/blob/main/src/_includes/install/macos.md Install a specific version and manage symlinks to switch between installed releases. ```console $ brew install dart@3.1 ``` ```console $ brew unlink dart@ \ && brew unlink dart@ \ && brew link dart@ ``` -------------------------------- ### Generate API documentation Source: https://github.com/dart-lang/site-www/blob/main/src/content/tools/dart-doc.md Run these commands from the package root to generate documentation after ensuring dependencies are fetched and analysis passes. ```console $ cd my_package $ dart pub get $ dart doc . Documenting my_package... ... Success! Docs generated into /Users/me/projects/my_package/doc/api ``` -------------------------------- ### Redirect Example: Section Renamed Source: https://github.com/dart-lang/site-www/wiki/Documentation-guide Example of how to define a redirect when a section within a topic has been renamed. ```text # section in topic is renamed lang/elements#for => lang/elements#if-and-for ``` -------------------------------- ### Redirect Example: Topic Moved Source: https://github.com/dart-lang/site-www/wiki/Documentation-guide Example of how to define a redirect when a topic has moved to a new location. ```text # topic is moved lang/if-elements.md => lang/collections/if-elements.md ``` -------------------------------- ### Implement async-await solution Source: https://github.com/dart-lang/site-www/blob/main/src/content/libraries/async/async-await.md Example solution for an async-await exercise involving fetching roles and login amounts. ```dart Future reportUserRole() async { final username = await fetchRole(); return 'User role: $username'; } Future reportLogins() async { final logins = await fetchLoginAmount(); return 'Total number of logins: $logins'; } ``` -------------------------------- ### Serve documentation locally Source: https://github.com/dart-lang/site-www/blob/main/src/content/tools/dart-doc.md Use the dhttpd package to serve generated documentation files locally for browser viewing. ```console $ dart pub global activate dhttpd $ dart pub global run dhttpd --path doc/api ``` -------------------------------- ### View help documentation Source: https://github.com/dart-lang/site-www/blob/main/src/content/tools/dart-compile.md Displays usage information and available options for a specific subcommand. ```console $ dart compile exe --help ``` -------------------------------- ### Run Dart Example Source: https://github.com/dart-lang/site-www/blob/main/src/content/interop/objective-c-interop.md Execute the Dart script that utilizes the generated Swift bindings. ```console $ dart run example.dart ``` -------------------------------- ### Create a basic Dart project Source: https://github.com/dart-lang/site-www/blob/main/src/content/tools/dart-create.md Initializes a new project directory using the default console template. ```console $ dart create my_cli ``` -------------------------------- ### Boolean Property Names: Good Examples Source: https://github.com/dart-lang/site-www/blob/main/src/content/effective-dart/design.md Examples of well-named boolean properties that use verb phrases. ```dart isEmpty hasElements canClose closesWindow canShowPopup hasShownPopup ``` -------------------------------- ### Dart Main Application Entry Point Source: https://github.com/dart-lang/site-www/blob/main/src/content/blog/building-data-binding-in-the-browser/index.md Sets up the main Dart application logic, initializing a ListController with sample data and rendering its view into a specified HTML element. It also starts the change detection process. ```dart import 'dart:html'; import 'package:mvc_data_binding/list.dart'; main() { final sundays = [ 'sleep in', 'eat brunch', 'wash car', ]; final container = document.querySelector('#todo-list'); final component = new ListController(sundays); container.append(component.view.build()); // Start change detection. This should be automatic in most frameworks. component.view.detectChanges(component); } ``` -------------------------------- ### Create and run a JIT snapshot Source: https://github.com/dart-lang/site-www/blob/main/src/content/tools/dart-compile.md Generates a JIT module from a Dart file and executes it using the Dart VM. ```console $ dart compile jit-snapshot bin/myapp.dart Compiling bin/myapp.dart to jit-snapshot file bin/myapp.jit. Hello world! $ dart run bin/myapp.jit Hello world! ``` -------------------------------- ### Run dart info Source: https://github.com/dart-lang/site-www/blob/main/src/content/tools/dart-info.md Execute the command from any directory to retrieve general system and Dart installation diagnostics. ```console $ dart info ``` -------------------------------- ### Get help for dart create Source: https://github.com/dart-lang/site-www/blob/main/src/content/tools/dart-create.md Displays available command-line options and usage information. ```console $ dart create --help ``` -------------------------------- ### Record Syntax Example Source: https://github.com/dart-lang/site-www/blob/main/src/content/language/records.md Demonstrates the basic syntax for creating a record with mixed positional and named fields. ```dart var record = ('first', a: 2, b: true, 'last'); ``` -------------------------------- ### Dart FFI Struct Allocation Example Source: https://github.com/dart-lang/site-www/blob/main/src/content/blog/implementing-structs-by-value-in-dart-ffi/index.md Example of allocating and initializing a struct using the initial Dart FFI design. ```dart final c = Coordinate.allocate() ..x = 10.0 ..y = 10.0; ``` -------------------------------- ### Use initializer lists for field setup Source: https://github.com/dart-lang/site-www/blob/main/src/content/resources/dart-cheatsheet.md Perform setup before the constructor body executes, useful for initializing final fields. ```dart Point.fromJson(Map json) : x = json['x']!, y = json['y']! { print('In Point.fromJson(): ($x, $y)'); } ``` -------------------------------- ### Available Package Versions Example Source: https://github.com/dart-lang/site-www/blob/main/src/content/tools/pub/versioning.md Shows the released versions of a package (`collection`) that Pub considers when resolving constraints. ```plaintext 1.7.0 1.7.1 1.8.0 1.8.1 1.8.2 1.9.0 ``` -------------------------------- ### Run FFIgen script to generate bindings Source: https://github.com/dart-lang/site-www/blob/main/src/content/interop/objective-c-interop.md Navigate to the example directory and execute this command to generate Objective-C bindings. This script generates a Dart file with bindings for Objective-C APIs, including stubs for transitive dependencies. ```console dart run tool/generate_code.dart ``` -------------------------------- ### Load a system library with DynamicLibrary Source: https://github.com/dart-lang/site-www/blob/main/src/content/interop/objective-c-interop.md Initializes the native library by opening the dylib path. ```dart import 'dart:ffi'; import 'package:objective_c/objective_c.dart'; import 'avf_audio_bindings.dart'; const _dylibPath = '/System/Library/Frameworks/AVFAudio.framework/Versions/Current/AVFAudio'; void main(List args) async { DynamicLibrary.open(_dylibPath); } ``` -------------------------------- ### Verify Dart SDK Installation Source: https://github.com/dart-lang/site-www/blob/main/src/_includes/install/windows.md Checks the currently installed version of the Dart SDK to ensure it is correctly configured in the system PATH. ```ps PS C:\> dart --version Dart SDK version: 3.2.4 (stable) (Thu Dec 21 19:13:53 2023 +0000) on "win_x64" ``` -------------------------------- ### Get build_runner Help Source: https://github.com/dart-lang/site-www/blob/main/src/content/tools/webdev.md View available build_runner options by using the help flag. ```bash dart run build_runner test -h ``` -------------------------------- ### Preferred Future Creation without Completer Source: https://github.com/dart-lang/site-www/blob/main/src/content/effective-dart/usage.md This example demonstrates a cleaner way to achieve the same result as the Completer example by using Future.then(). ```dart Future fileContainsBear(String path) { return File(path).readAsString().then((contents) { return contents.contains('bear'); }); } ``` -------------------------------- ### Preferred async/await for Future Creation Source: https://github.com/dart-lang/site-www/blob/main/src/content/effective-dart/usage.md This alternative example shows how to achieve the same result using the async/await syntax, which is often more readable. ```dart Future fileContainsBear(String path) async { var contents = await File(path).readAsString(); return contents.contains('bear'); } ``` -------------------------------- ### Get app dependencies with dart pub get Source: https://github.com/dart-lang/site-www/blob/main/src/content/web/debugging.md Run this command in your app's top directory to fetch project dependencies. ```bash cd example dart pub get ``` -------------------------------- ### Run dart pub get Source: https://github.com/dart-lang/site-www/blob/main/src/content/tools/build_runner.md After modifying pubspec.yaml, run dart pub get or dart pub upgrade to fetch dependencies. ```bash $ dart pub get ``` -------------------------------- ### Dart main() function with arguments Source: https://github.com/dart-lang/site-www/blob/main/src/content/language/functions.md This example shows how to define and use the `main()` function when it needs to accept command-line arguments. The arguments are provided as a `List`. ```dart // Run the app like this: dart run args.dart 1 test void main(List arguments) { print(arguments); assert(arguments.length == 2); assert(int.parse(arguments[0]) == 1); assert(arguments[1] == 'test'); } ``` -------------------------------- ### Example of using a library with conditional exports Source: https://github.com/dart-lang/site-www/blob/main/src/content/tools/pub/create-packages.md This example demonstrates how to import and use a library that has conditional exports. It prints the message provided by the library. ```dart import 'package:hw_mp/hw_mp.dart'; void main() { print(message); } ``` -------------------------------- ### Initialize Genkit and Call LLM Providers Source: https://github.com/dart-lang/site-www/blob/main/src/content/blog/announcing-genkit-dart-build-full-stack-ai-apps-with-dart-and-flutter/index.md Initialize Genkit with plugins for different AI providers and make calls to specific models like Google Gemini and Anthropic Claude. Ensure necessary plugins are imported. ```dart import 'package:genkit/genkit.dart'; import 'package:genkit_google_genai/genkit_google_genai.dart'; import 'package:genkit_anthropic/genkit_anthropic.dart'; void main() async { // Initialize Genkit with plugins final ai = Genkit(plugins: [ googleAI(), anthropic(), ]); // Call Google Gemini final geminiResponse = await ai.generate( model: googleAI.gemini('gemini-3.1-pro-preview'), prompt: 'Hello from Gemini', ); // Call Anthropic Claude final claudeResponse = await ai.generate( model: anthropic.model('claude-opus-4.6'), prompt: 'Hello from Claude', ); } ``` -------------------------------- ### Install a Git package from a specific ref Source: https://github.com/dart-lang/site-www/blob/main/src/content/tools/dart-install.md Installs a package from a Git repository, specifying a particular branch or commit using the --git-ref option. ```bash $ dart install \ https://github.com/dart-lang/http.git \ --git-ref 36f98e900347335af2338a0e087538009b7de2f9 ``` -------------------------------- ### Start Shelf Server Source: https://github.com/dart-lang/site-www/blob/main/src/content/blog/building-a-chat-app-in-dart/index.md Initializes a Shelf server to handle incoming requests using the defined cascade handler. This sets up the server to listen on localhost port 26199. ```dart await io.serve(cascade.handler, 'localhost', 26199); ``` -------------------------------- ### Install a Git package from a specific path Source: https://github.com/dart-lang/site-www/blob/main/src/content/tools/dart-install.md Installs a package from a Git repository, specifying a subdirectory using the --git-path option when the package is not in the root. ```bash $ dart install \ https://github.com/dart-lang/http.git \ --git-path pkgs/http/ ``` -------------------------------- ### Create and run a new app Source: https://github.com/dart-lang/site-www/blob/main/src/content/tools/dart-run.md This sequence demonstrates creating a new Dart application and then running it using the `dart run` command. ```console $ dart create myapp $ cd myapp $ dart run ```