### Running Dart Shelf Server Locally Bash Source: https://github.com/dart-lang/samples/blob/main/server/simple/README.md This bash command executes the `bin/server.dart` script using the Dart runtime, starting the HTTP server. It requires the Dart SDK to be installed and project dependencies fetched. ```bash $ dart run bin/server.dart ``` -------------------------------- ### Running Dart FFI Application (Bash) Source: https://github.com/dart-lang/samples/blob/main/ffi/README.md Shows the Bash commands required to fetch dependencies for the Dart project using `dart pub get` and then execute the main Dart application file using `dart run`. This assumes the native library used by the application has already been built. ```bash dart pub get dart run .dart ``` -------------------------------- ### Running Dart Lix Calculator CLI App Cmd Source: https://github.com/dart-lang/samples/blob/main/null_safety/calculate_lix/README.md Provides the necessary command-line steps to execute the Dart Lix readability calculator application from the terminal. It involves changing the directory to the project root, fetching project dependencies using `dart pub get`, and running the main script located in `bin/main.dart` with an example text file as input to calculate its Lix score. ```cmd cd /null_safety/calculate_lix/ $ dart pub get $ dart run bin/main.dart text/lorem-ipsum.txt ``` -------------------------------- ### Required File Header for Dart Files Source: https://github.com/dart-lang/samples/blob/main/CONTRIBUTING.md This code snippet shows the mandatory header that must be included at the top of every new file added to the Dart samples project. It specifies the copyright details, authors file reference, and the governing BSD-style license for the source code. ```Dart // Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. ``` -------------------------------- ### Building Dart FFI Native Library using CMake and Make (Bash) Source: https://github.com/dart-lang/samples/blob/main/ffi/README.md Provides the necessary Bash commands to navigate to a sample project directory, configure the build using CMake, and compile the native shared library using Make. This process generates the platform-specific library file required by the Dart FFI application (e.g., .dylib, .dll, .so). ```bash cd hello_world/hello_library cmake . make ``` -------------------------------- ### Running Dart CLI App with Help Flag (Bash) Source: https://github.com/dart-lang/samples/blob/main/command_line/README.md Command to execute the compiled `github_activity` command-line application. The `--help` flag is used to display the application's usage instructions, including available options and arguments, as defined by `build_cli_annotations`. ```bash ./github_activity --help ``` -------------------------------- ### Configuring C Library and Executable Build with CMake Source: https://github.com/dart-lang/samples/blob/main/ffi/hello_world/hello_library/CMakeLists.txt This CMake snippet sets the minimum required CMake version, defines a shared library target ('hello_library') from specified source files, creates an executable target ('hello_test') from 'hello.c', and assigns properties to the shared library including public header, version, output name, and Xcode code signing identity. ```CMake cmake_minimum_required(VERSION 3.7 FATAL_ERROR) project(hello_library VERSION 1.0.0 LANGUAGES C) add_library(hello_library SHARED hello.c hello.def) add_executable(hello_test hello.c) set_target_properties(hello_library PROPERTIES PUBLIC_HEADER hello.h VERSION ${PROJECT_VERSION} SOVERSION 1 OUTPUT_NAME "hello" XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY "Hex_Identity_ID_Goes_Here" ) ``` -------------------------------- ### Configuring CMake Build for C Library Source: https://github.com/dart-lang/samples/blob/main/ffi/structs/structs_library/CMakeLists.txt This snippet defines the build process for a C project using CMake. It specifies the required CMake version, names the project "structs_library", adds a shared library and an executable from the source files `structs.c` and `structs.def`, links them against the math library (`m`), and sets various properties for the library including public header, version, SO version, output name, and Xcode code signing identity. ```CMake cmake_minimum_required(VERSION 3.7 FATAL_ERROR) project(structs_library VERSION 1.0.0 LANGUAGES C) add_library(structs_library SHARED structs.c structs.def) target_link_libraries(structs_library PUBLIC m) add_executable(structs_test structs.c) target_link_libraries(structs_test PUBLIC m) set_target_properties(structs_library PROPERTIES PUBLIC_HEADER structs.h VERSION ${PROJECT_VERSION} SOVERSION 1 OUTPUT_NAME "structs" XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY "Hex_Identity_ID_Goes_Here" ) ``` -------------------------------- ### Build AOT Snapshot (Dart/Bash) Source: https://github.com/dart-lang/samples/blob/main/native_app/README.md This command uses the `dart compile aot-snapshot` tool to create an Ahead-of-Time (AOT) snapshot of a Dart application. The `-o` flag specifies the output filename `hello_world.aot`. This snapshot can be run using the `dartaotruntime` command. ```Bash dart compile aot-snapshot bin/main.dart -o hello_world.aot ``` -------------------------------- ### Run Native Executable (Linux/macOS) - Dart/Bash Source: https://github.com/dart-lang/samples/blob/main/native_app/README.md This command executes the native binary `hello_world` generated by the `dart compile exe` tool. The `./` prefix indicates that the executable is located in the current directory. This command is intended for Linux and macOS environments. ```Bash ./hello_world ``` -------------------------------- ### Run Native Executable (Windows) - Dart/Bash Source: https://github.com/dart-lang/samples/blob/main/native_app/README.md This command executes the native binary `hello_world.exe` generated by the `dart compile exe` tool. The executable can be run directly by name if it's in the current directory or the system's PATH. This command is intended for Windows environments. ```Bash hello_world.exe ``` -------------------------------- ### Setting Minimum CMake Version and Project CMake Source: https://github.com/dart-lang/samples/blob/main/ffi/primitives/primitives_library/CMakeLists.txt Specifies the minimum required version of CMake (3.7) for this project, ensuring compatibility. It then defines the project name ('primitives_library'), its version (1.0.0), and the programming language used (C). `FATAL_ERROR` halts the configuration if the minimum version is not met. ```CMake cmake_minimum_required(VERSION 3.7 FATAL_ERROR) project(primitives_library VERSION 1.0.0 LANGUAGES C) ``` -------------------------------- ### Build Native Executable (Windows) - Dart/Bash Source: https://github.com/dart-lang/samples/blob/main/native_app/README.md This command uses the `dart compile exe` tool to build a native executable from a Dart source file (`bin\main.dart`). The `-o` flag specifies the output filename `hello_world.exe`. Note the use of backslashes for the path. This command is intended for Windows environments. ```Bash dart compile exe bin\main.dart -o hello_world.exe ``` -------------------------------- ### Build Native Executable (Linux/macOS) - Dart/Bash Source: https://github.com/dart-lang/samples/blob/main/native_app/README.md This command uses the `dart compile exe` tool to build a native executable from a Dart source file (`bin/main.dart`). The `-o` flag specifies the output filename `hello_world`. This command is intended for Linux and macOS environments. ```Bash dart compile exe bin/main.dart -o hello_world ``` -------------------------------- ### Run AOT Snapshot (Dart/Bash) Source: https://github.com/dart-lang/samples/blob/main/native_app/README.md This command uses the `dartaotruntime` tool to execute a previously generated AOT snapshot (`hello_world.aot`). This provides a way to run compiled Dart code without bundling the Dart VM. ```Bash dartaotruntime hello_world.aot ``` -------------------------------- ### Building Dart CLI App with Build Runner (Bash) Source: https://github.com/dart-lang/samples/blob/main/command_line/README.md Command to run the `build_runner` tool for a Dart project. This is typically required to generate code based on annotations, such as those used by `package:build_cli_annotations` to process CLI options defined in the `Options` class. ```bash dart run build_runner build ``` -------------------------------- ### Setting GitHub Token Environment Variable (Bash) Source: https://github.com/dart-lang/samples/blob/main/command_line/README.md Bash command to set the `GITHUB_TOKEN` environment variable. This token is used by the `package:github` library to authenticate with the GitHub API, helping to avoid rate limiting issues when fetching user activity data. Replace `` with your actual token. ```bash export GITHUB_TOKEN= ``` -------------------------------- ### Setting Library Target Properties CMake Source: https://github.com/dart-lang/samples/blob/main/ffi/primitives/primitives_library/CMakeLists.txt Configures various properties for the 'primitives_library' target. This includes specifying 'primitives.h' as the public header, setting the library's version and SOVERSION, defining the output filename as 'primitives', and adding an Xcode-specific code signing identity. ```CMake set_target_properties(primitives_library PROPERTIES PUBLIC_HEADER primitives.h VERSION ${PROJECT_VERSION} SOVERSION 1 OUTPUT_NAME "primitives" XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY "Hex_Identity_ID_Goes_Here" ) ``` -------------------------------- ### Solving a CSP using Backtracking in Dart Source: https://github.com/dart-lang/samples/blob/main/package_constraint_solver/README.md This code demonstrates how to initialize the `CSP` solver with the defined variables and domains, add the custom constraint, and execute the `backtrackingSearch` method to find a solution. The result, if found, is then printed. ```Dart var csp = CSP(variables, domains); csp.addConstraint(AvoidDislikes(variables)); var result = csp.backtrackingSearch(); print(result); ``` -------------------------------- ### Adding Executable Target CMake Source: https://github.com/dart-lang/samples/blob/main/ffi/primitives/primitives_library/CMakeLists.txt Defines an executable target named 'primitives_test'. It uses 'primitives.c' as its source file, implying that 'primitives.c' contains the main function or test entry point for this executable. ```CMake add_executable(primitives_test primitives.c) ``` -------------------------------- ### Adding Shared Library Target CMake Source: https://github.com/dart-lang/samples/blob/main/ffi/primitives/primitives_library/CMakeLists.txt Defines a shared library target named 'primitives_library'. It includes 'primitives.c' as the source file and 'primitives.def' as a definition file, typically used on Windows for exporting symbols, although common on other platforms too. ```CMake add_library(primitives_library SHARED primitives.c primitives.def) ``` -------------------------------- ### Defining CSP Variable Domains in Dart Source: https://github.com/dart-lang/samples/blob/main/package_constraint_solver/README.md This code defines the domain for each CSP variable, representing the set of possible values (meals) that can be assigned to each person. The `domains` map associates each person variable with the list of available meal options. ```Dart var meals = ['artichoke', 'bananas', 'broccoli']; var domains = { doug: meals, patrick: meals, susan: meals, }; ``` -------------------------------- ### Defining CSP Variables in Dart Source: https://github.com/dart-lang/samples/blob/main/package_constraint_solver/README.md This snippet demonstrates how to define the variables for a Constraint Satisfaction Problem (CSP) using a list of `Person` objects. Each variable represents a guest who needs to be assigned a meal, potentially with defined dislikes. ```Dart var doug = Person('Doug', dislikes: ['artichoke']); var patrick = Person('Patrick', dislikes: ['bananas']); var susan = Person('Susan', dislikes: ['broccoli']); var variables = [doug, patrick, susan]; ``` -------------------------------- ### Implementing a Custom CSP Constraint in Dart Source: https://github.com/dart-lang/samples/blob/main/package_constraint_solver/README.md This snippet illustrates how to create a custom constraint by extending the `Constraint` class from the `constraint_solver` package. The `isSatisfied` method needs to be implemented to define the specific rule that checks if a given assignment of values to variables is valid according to this constraint. ```Dart class AvoidDislikes extends Constraint { AvoidDislikes(super.variables); @override bool isSatisfied(Map assignment) { // ... } } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.