跳到主內容

實驗標誌

Dart SDK 通常包含實驗性功能,您可以透過向 Dart 工具傳遞標誌來試用這些功能。

在命令列工具中使用實驗標誌

#

要在 Dart SDK 命令列工具中使用實驗性功能,請將相應的標誌傳遞給該工具。

例如,要啟用 super-mixinsno-slow-checks 實驗,請將這些標誌新增到 dart 命令中

dart run --enable-experiment=super-mixins,no-slow-checks bin/main.dart

或新增到 flutter 命令中

flutter run --enable-experiment=super-mixins,no-slow-checks

在 Dart 分析器(命令列和 IDE)中使用實驗標誌

#

要啟用影響分析的實驗,請在分析選項檔案中使用 enable-experiment 鍵。以下是在 analysis_options.yaml 中啟用 super-mixinsno-slow-checks 實驗的示例:

analysis_options.yaml
yaml
analyzer:
  enable-experiment:
    - super-mixins
    - no-slow-checks

在 IDE 中使用實驗標誌

#

要在 IDE 中啟用與執行或除錯應用相關的實驗,請編輯啟動配置。

Visual Studio Code

#

launch.jsonconfigurations 下,新增一個新的 toolArgs 鍵,其中包含所需的標誌。示例:

launch.json
json
 "configurations": [
        {
            "name": "Dart",
            "program": "bin/main.dart",
            "request": "launch",
            "type": "dart",
            "toolArgs": [
                "--enable-experiment=super-mixins,no-slow-checks",
            ],
        }
    ]

有關更多資訊,請查閱 VS Code 啟動配置的文件。

Android Studio

#

VMOptions 下新增所需的標誌。示例:

xml
<component name="ProjectRunConfigurationManager">
  <configuration default="false" name="Run main" type="DartCommandLineRunConfigurationType" factoryName="Dart Command Line Application">
    <option name="VMOptions" value="--enable-experiment=non-nullable" />
    <option name="filePath" value="$PROJECT_DIR$/bin/main.dart" />
    <method v="2" />
  </configuration>
</component>

有關更多資訊,請查閱 Android Studio 執行/除錯配置的說明。

更多資訊

#