默认情况下不可为空:如何启用实验?

时间:2019-08-21 20:32:22

标签: dart

我刚刚在DartPad中尝试了以下操作:

Option Explicit

Public Sub AlterTable()
    Dim ie As Object, html As HTMLDocument, clipboard As Object, hTable As HTMLTable

    Set ie = CreateObject("InternetExplorer.Application")
    Set clipboard = GetObject("New:{1C3B4210-F441-11CE-B9EA-00AA006B1A69}")

    With ie
        .Visible = True
        .Navigate2 "https://www.w3schools.com/html/html_tables.asp"

        While .Busy Or .readyState <> 4: DoEvents: Wend

        With .document
            .querySelector("#customers tr:nth-of-type(1)").ParentNode.RemoveChild .querySelector("#customers tr:nth-of-type(1)")  'in your case use  querySelector(".reports-area table tr:nth-of-type(1)").ParentNode.RemoveChild .querySelector(".reports-area table tr:nth-of-type(1)")
            Set hTable = .querySelector("#customers")  ' in your case use:  .querySelector(".reports-area table")
        End With

        clipboard.SetText hTable.outerHTML
        clipboard.PutInClipboard
        ActiveSheet.Range("A1").PasteSpecial
        .Quit
    End With
End Sub

并出现以下错误:

void main() {
  int? x;
}
  1. 如何启用该实验?我正在使用Flutter SDK。

  2. 实验是否已经支持空安全静态分析?

5 个答案:

答案 0 :(得分:6)

通过三个步骤启用不可为空的实验:

  1. 将dart-sdk版本添加到pubspec.yaml

    environment:
      sdk: '>=2.8.0-dev.0 <2.8.0'
    
  2. 将启用的非空实验添加到analysis_options.yaml

    analyzer:
      enable-experiment:
        - non-nullable
    
  3. 运行Dart代码:

    dart --enable-experiment=non-nullable ./bin/hello_dart.dart
    

答案 1 :(得分:3)

将以下行添加到analysis_options.yaml

analyzer:
  enable-experiment:
    - non-nullable

答案 2 :(得分:3)

对我来说,删除pubspec.lock并重新运行即可解决此问题。我正在将项目从Windows导入到Mac。

答案 3 :(得分:2)

您可以通过将标志--enable-experiment=nnbd传递给编译器或分析器来启用实验。

它还不是一个完整的功能,因此无法保证它会做什么。随时尝试,但不要将标志用于任何严重的事情。

答案 4 :(得分:0)

手动删除pubspec.lock并运行flutter pub get解决了该问题。就我而言,这是由于回归。