Dart 解决 Prefer using null-aware Operators 错误

Dol*_*rma 2 dart flutter

我该如何解决这个问题:

更喜欢使用 null 感知运算符

在这段代码上?

AnimationControllerValue halfBoundValue;
double get halfBound => halfBoundValue != null ? halfBoundValue.percentage : null;
Run Code Online (Sandbox Code Playgroud)

文档: https: //dart-lang.github.io/linter/lints/prefer_null_aware_operators.html

Ric*_*eap 5

它建议:

AnimationControllerValue halfBoundValue;
double get halfBound => halfBoundValue?.percentage;
Run Code Online (Sandbox Code Playgroud)

会更具可读性和简洁性。